Exemple #1
0
        public void ParaNodeMap_AccurateComparison()
        {
            // Artificially create a few ParaNodeMaps
            ParaNodeMap map1 = new DummyParaNodeMap(0, 0, 0, 0, 0);
            ParaNodeMap map2 = new DummyParaNodeMap(0, 0, 0, 1, 2);
            ParaNodeMap map3 = new DummyParaNodeMap(0, 0, 0, 11, 0);
            ParaNodeMap map4 = new DummyParaNodeMap(1, 0, 0, 0, 0);

            // Now run through our checks:
            // We expect map1 to come before map2
            Assert.AreEqual(-1, map1.CompareTo(map2));
            // Likewise, we expect map2 to come after map1
            Assert.AreEqual(1, map2.CompareTo(map1));
            // Map2 should be less than map3
            Assert.AreEqual(-1, map2.CompareTo(map3));

            // If we create a list and add maps 1-4, we should expect
            // (after sorting), to find them in that same order.  We'll
            // insert them out of order just to be sure it works
            List <ParaNodeMap> toSort = new List <ParaNodeMap>();

            toSort.Add(map3);
            toSort.Add(map2);
            toSort.Add(map4);
            toSort.Add(map1);
            toSort.Sort();
            // Now verify the list is in the expected order
            Assert.IsTrue(map1.Equals(toSort[0]));
            Assert.IsTrue(map2.Equals(toSort[1]));
            Assert.IsTrue(map3.Equals(toSort[2]));
            Assert.IsTrue(map4.Equals(toSort[3]));

            // Finally, create another map, identical to map3, and verify
            // that when the two objects are equal, comparison also returns 0
            ParaNodeMap map5 = new DummyParaNodeMap(0, 0, 0, 11, 0);

            Assert.IsTrue(map3.Equals(map5));
            Assert.AreEqual(0, map3.CompareTo(map5));
        }
		public void ParaNodeMap_AccurateComparison()
		{
			// Artificially create a few ParaNodeMaps
			ParaNodeMap map1 = new DummyParaNodeMap(0, 0, 0, 0, 0);
			ParaNodeMap map2 = new DummyParaNodeMap(0, 0, 0, 1, 2);
			ParaNodeMap map3 = new DummyParaNodeMap(0, 0, 0, 11, 0);
			ParaNodeMap map4 = new DummyParaNodeMap(1, 0, 0, 0, 0);

			// Now run through our checks:
			// We expect map1 to come before map2
			Assert.AreEqual(-1, map1.CompareTo(map2));
			// Likewise, we expect map2 to come after map1
			Assert.AreEqual(1, map2.CompareTo(map1));
			// Map2 should be less than map3
			Assert.AreEqual(-1, map2.CompareTo(map3));

			// If we create a list and add maps 1-4, we should expect
			// (after sorting), to find them in that same order.  We'll
			// insert them out of order just to be sure it works
			List<ParaNodeMap> toSort = new List<ParaNodeMap>();
			toSort.Add(map3);
			toSort.Add(map2);
			toSort.Add(map4);
			toSort.Add(map1);
			toSort.Sort();
			// Now verify the list is in the expected order
			Assert.IsTrue(map1.Equals(toSort[0]));
			Assert.IsTrue(map2.Equals(toSort[1]));
			Assert.IsTrue(map3.Equals(toSort[2]));
			Assert.IsTrue(map4.Equals(toSort[3]));

			// Finally, create another map, identical to map3, and verify
			// that when the two objects are equal, comparison also returns 0
			ParaNodeMap map5 = new DummyParaNodeMap(0, 0, 0, 11, 0);
			Assert.IsTrue(map3.Equals(map5));
			Assert.AreEqual(0, map3.CompareTo(map5));
		}