Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 27th, 2012  |  syntax: None  |  size: 1.95 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  public class SwapperTest
  2.     {
  3.         public class Test_
  4.         {
  5.             public int X { get; set; }
  6.             public int Y { get; set; }
  7.         }
  8.        
  9.        
  10.         [TestMethod]
  11.         public void ExampleWithObject()
  12.         {
  13.            
  14.             var t = new Test_() { X = 0, Y = 1 };
  15.             Swapper.Swap(() => t.X, () => t.Y);
  16.             Assert.AreEqual(0, t.Y);
  17.             Assert.AreEqual(1, t.X);
  18.         }
  19.         [TestMethod]
  20.         public void ExampleWithArray()
  21.         {
  22.             int[] array = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  23.             Swapper.Swap(() => array[0], () => array[1]);
  24.             Assert.AreEqual(2, array[0]);
  25.             Assert.AreEqual(1, array[1]);
  26.          
  27.         }
  28.         [TestMethod]
  29.         public void ExampleWithList()
  30.         {
  31.             List<int>array = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  32.             Swapper.Swap(() => array[0], () => array[1]);
  33.             Assert.AreEqual(2, array[0]);
  34.             Assert.AreEqual(1, array[1]);
  35.  
  36.         }
  37.         [TestMethod]
  38.         public void ExampleWithTwoDimensionArray()
  39.         {
  40.             int[,] array = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 }, { 9, 10 } };
  41.             Swapper.Swap(() => array[0, 0], () => array[4, 1]);
  42.             Assert.AreEqual(10, array[0, 0]);
  43.             Assert.AreEqual(1, array[4, 1]);
  44.  
  45.         }
  46.         [TestMethod]
  47.         public void ExampleWithTwoDimensionSlaggedArray()
  48.         {
  49.             int[][] array = new int[][] { new[] { 1, 2 }, new[] { 3, 4 }, new[] { 5, 6 }, new[] { 7, 8 }, new[] { 9, 10 } };
  50.             Swapper.Swap(() => array[0][0], () => array[4][1]);
  51.             Assert.AreEqual(10, array[0][0]);
  52.             Assert.AreEqual(1, array[4][1]);
  53.  
  54.         }
  55.         [TestMethod]
  56.         public void ExampleWithLocals()
  57.         {
  58.             int a = 5;
  59.             int b=6;
  60.             Swapper.Swap(() => a, () => b);
  61.             Assert.AreEqual(6, a);
  62.             Assert.AreEqual(5, b);
  63.  
  64.         }
  65.     }