Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SwapperTest
- {
- public class Test_
- {
- public int X { get; set; }
- public int Y { get; set; }
- }
- [TestMethod]
- public void ExampleWithObject()
- {
- var t = new Test_() { X = 0, Y = 1 };
- Swapper.Swap(() => t.X, () => t.Y);
- Assert.AreEqual(0, t.Y);
- Assert.AreEqual(1, t.X);
- }
- [TestMethod]
- public void ExampleWithArray()
- {
- int[] array = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- Swapper.Swap(() => array[0], () => array[1]);
- Assert.AreEqual(2, array[0]);
- Assert.AreEqual(1, array[1]);
- }
- [TestMethod]
- public void ExampleWithList()
- {
- List<int>array = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- Swapper.Swap(() => array[0], () => array[1]);
- Assert.AreEqual(2, array[0]);
- Assert.AreEqual(1, array[1]);
- }
- [TestMethod]
- public void ExampleWithTwoDimensionArray()
- {
- int[,] array = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 }, { 9, 10 } };
- Swapper.Swap(() => array[0, 0], () => array[4, 1]);
- Assert.AreEqual(10, array[0, 0]);
- Assert.AreEqual(1, array[4, 1]);
- }
- [TestMethod]
- public void ExampleWithTwoDimensionSlaggedArray()
- {
- int[][] array = new int[][] { new[] { 1, 2 }, new[] { 3, 4 }, new[] { 5, 6 }, new[] { 7, 8 }, new[] { 9, 10 } };
- Swapper.Swap(() => array[0][0], () => array[4][1]);
- Assert.AreEqual(10, array[0][0]);
- Assert.AreEqual(1, array[4][1]);
- }
- [TestMethod]
- public void ExampleWithLocals()
- {
- int a = 5;
- int b=6;
- Swapper.Swap(() => a, () => b);
- Assert.AreEqual(6, a);
- Assert.AreEqual(5, b);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment