コード例 #1
0
        private string AssertEqual(AscendingIntegerRangeCollection coll, HashSet <int> hashSet)
        {
            var stb        = new System.Text.StringBuilder();
            var hashSorted = hashSet.OrderBy(x => x).ToArray();
            var collSorted = coll.ToArray();

            // Evaluation
            if (hashSorted.Length != collSorted.Length)
            {
                stb.AppendFormat("Length different. Expected {0} but was {1}", hashSorted.Length, collSorted.Length);
                stb.AppendLine();
            }

            var len = Math.Min(hashSorted.Length, collSorted.Length);

            for (int i = 0; i < len; ++i)
            {
                if (hashSorted[i] != collSorted[i])
                {
                    stb.AppendFormat("Different elements at index[{0}]. Expected {1} but was {2}", i, hashSorted[i], collSorted[i]);
                    break;
                }
            }

            return(stb.Length == 0 ? null : stb.ToString());
        }
コード例 #2
0
        public void TestIndexing_2()
        {
            var rnd     = new System.Random();
            var coll    = new AscendingIntegerRangeCollection();
            var hashSet = new HashSet <int>();

            for (int i = 0; i < 2000; ++i)
            {
                var r = rnd.Next(10, 4000);
                coll.AddRangeByFirstAndLastInclusive(r, r);
                hashSet.Add(r);
            }

            var hashSorted = hashSet.OrderBy(x => x).ToArray();
            var collSorted = coll.ToArray();

            // Auswertung
            Assert.AreEqual(hashSorted.Length, collSorted.Length);
            for (int i = 0; i < hashSorted.Length; ++i)
            {
                Assert.AreEqual(hashSorted[i], collSorted[i], "i=" + i.ToString());
            }

            Assert.AreEqual(hashSorted.Length, coll.Count);
            for (int i = 0; i < hashSorted.Length; ++i)
            {
                Assert.AreEqual(hashSorted[i], coll[i], "i=" + i.ToString());
            }
        }
コード例 #3
0
        public void TestIndexing_3()
        {
            var rnd     = new System.Random();
            var coll    = new AscendingIntegerRangeCollection();
            var hashSet = new HashSet <int>();

            for (int i = 0; i < 3000; ++i)
            {
                var r = rnd.Next(10, 4000);
                coll.AddRangeByFirstAndLastInclusive(r, r);
                hashSet.Add(r);
            }

            for (int i = 0; i < 3000; ++i)
            {
                var r = rnd.Next(10, 4000);
                coll.RemoveRangeByFirstAndLastInclusive(r, r);
                hashSet.Remove(r);
            }

            var hashSorted = hashSet.OrderBy(x => x).ToArray();
            var collSorted = coll.ToArray();

            // Evaluation of the sorted arrays
            Assert.AreEqual(hashSorted.Length, collSorted.Length);
            for (int i = 0; i < hashSorted.Length; ++i)
            {
                Assert.AreEqual(hashSorted[i], collSorted[i], "i=" + i.ToString());
            }

            // Test of indexing
            Assert.AreEqual(hashSorted.Length, coll.Count);
            for (int i = 0; i < hashSorted.Length; ++i)
            {
                Assert.AreEqual(hashSorted[i], coll[i], "i=" + i.ToString());
            }

            // Test of Contains
            int minElement = hashSorted[0];
            int maxElement = hashSorted[hashSorted.Length - 1];

            for (int ele = minElement - 5; ele < maxElement + 5; ++ele)
            {
                Assert.AreEqual(hashSet.Contains(ele), coll.Contains(ele));
            }
        }
コード例 #4
0
		private string AssertEqual(AscendingIntegerRangeCollection coll, HashSet<int> hashSet)
		{
			var stb = new System.Text.StringBuilder();
			var hashSorted = hashSet.OrderBy(x => x).ToArray();
			var collSorted = coll.ToArray();

			// Evaluation
			if (hashSorted.Length != collSorted.Length)
			{
				stb.AppendFormat("Length different. Expected {0} but was {1}", hashSorted.Length, collSorted.Length);
				stb.AppendLine();
			}

			var len = Math.Min(hashSorted.Length, collSorted.Length);
			for (int i = 0; i < len; ++i)
			{
				if (hashSorted[i] != collSorted[i])
				{
					stb.AppendFormat("Different elements at index[{0}]. Expected {1} but was {2}", i, hashSorted[i], collSorted[i]);
					break;
				}
			}

			return stb.Length == 0 ? null : stb.ToString();
		}
コード例 #5
0
		public void TestIndexing_3()
		{
			var rnd = new System.Random();
			var coll = new AscendingIntegerRangeCollection();
			var hashSet = new HashSet<int>();

			for (int i = 0; i < 3000; ++i)
			{
				var r = rnd.Next(10, 4000);
				coll.AddRangeByFirstAndLastInclusive(r, r);
				hashSet.Add(r);
			}

			for (int i = 0; i < 3000; ++i)
			{
				var r = rnd.Next(10, 4000);
				coll.RemoveRangeByFirstAndLastInclusive(r, r);
				hashSet.Remove(r);
			}

			var hashSorted = hashSet.OrderBy(x => x).ToArray();
			var collSorted = coll.ToArray();

			// Evaluation of the sorted arrays
			Assert.AreEqual(hashSorted.Length, collSorted.Length);
			for (int i = 0; i < hashSorted.Length; ++i)
			{
				Assert.AreEqual(hashSorted[i], collSorted[i], "i=" + i.ToString());
			}

			// Test of indexing
			Assert.AreEqual(hashSorted.Length, coll.Count);
			for (int i = 0; i < hashSorted.Length; ++i)
			{
				Assert.AreEqual(hashSorted[i], coll[i], "i=" + i.ToString());
			}

			// Test of Contains
			int minElement = hashSorted[0];
			int maxElement = hashSorted[hashSorted.Length - 1];

			for (int ele = minElement - 5; ele < maxElement + 5; ++ele)
			{
				Assert.AreEqual(hashSet.Contains(ele), coll.Contains(ele));
			}
		}
コード例 #6
0
		public void TestIndexing_2()
		{
			var rnd = new System.Random();
			var coll = new AscendingIntegerRangeCollection();
			var hashSet = new HashSet<int>();

			for (int i = 0; i < 2000; ++i)
			{
				var r = rnd.Next(10, 4000);
				coll.AddRangeByFirstAndLastInclusive(r, r);
				hashSet.Add(r);
			}

			var hashSorted = hashSet.OrderBy(x => x).ToArray();
			var collSorted = coll.ToArray();

			// Auswertung
			Assert.AreEqual(hashSorted.Length, collSorted.Length);
			for (int i = 0; i < hashSorted.Length; ++i)
			{
				Assert.AreEqual(hashSorted[i], collSorted[i], "i=" + i.ToString());
			}

			Assert.AreEqual(hashSorted.Length, coll.Count);
			for (int i = 0; i < hashSorted.Length; ++i)
			{
				Assert.AreEqual(hashSorted[i], coll[i], "i=" + i.ToString());
			}
		}