public void TestIndexing_1() { var coll = new AscendingIntegerRangeCollection(); coll.AddRangeByFirstAndLastInclusive(10, 19); Assert.AreEqual(10, coll[0]); Assert.AreEqual(19, coll[9]); coll.AddRangeByFirstAndLastInclusive(30, 39); Assert.AreEqual(10, coll[0]); Assert.AreEqual(19, coll[9]); Assert.AreEqual(30, coll[10]); Assert.AreEqual(39, coll[19]); coll.RemoveRangeByFirstAndLastInclusive(30, 35); Assert.AreEqual(10, coll[0]); Assert.AreEqual(19, coll[9]); Assert.AreEqual(36, coll[10]); Assert.AreEqual(39, coll[13]); coll.RemoveRangeByFirstAndLastInclusive(10, 14); Assert.AreEqual(15, coll[0]); Assert.AreEqual(19, coll[4]); Assert.AreEqual(36, coll[5]); Assert.AreEqual(39, coll[8]); }
private AscendingIntegerRangeCollection PrepareCollection_10_50_60_100() { var result = new AscendingIntegerRangeCollection(); result.AddRangeByFirstAndLastInclusive(10, 50); result.AddRangeByFirstAndLastInclusive(60, 100); return result; }
private AscendingIntegerRangeCollection PrepareCollection_10_20_30_40() { var result = new AscendingIntegerRangeCollection(); result.AddRangeByFirstAndLastInclusive(10, 20); result.AddRangeByFirstAndLastInclusive(30, 40); return result; }
private AscendingIntegerRangeCollection PrepareCollection_10_20_30_40() { var result = new AscendingIntegerRangeCollection(); result.AddRangeByFirstAndLastInclusive(10, 20); result.AddRangeByFirstAndLastInclusive(30, 40); return(result); }
private AscendingIntegerRangeCollection PrepareCollection_10_50_60_100() { var result = new AscendingIntegerRangeCollection(); result.AddRangeByFirstAndLastInclusive(10, 50); result.AddRangeByFirstAndLastInclusive(60, 100); return(result); }
public void TestAddToMaxValue_5() { var coll = new AscendingIntegerRangeCollection(); coll.AddRangeByFirstAndLastInclusive(int.MaxValue, int.MaxValue); coll.AddRangeByFirstAndLastInclusive(int.MaxValue - 2, int.MaxValue - 1); Assert.AreEqual(1, coll.RangeCount); var ranges = coll.Ranges.ToArray(); Assert.AreEqual(1, ranges.Length); Assert.AreEqual(int.MaxValue - 2, ranges[0].First); Assert.AreEqual(int.MaxValue, ranges[0].LastInclusive); }
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()); } }
private AscendingIntegerRangeCollection PrepareCollection_2_3() { var result = new AscendingIntegerRangeCollection(); result.AddRangeByFirstAndLastInclusive(2, 3); return(result); }
private AscendingIntegerRangeCollection PrepareCollection_1000_Max() { var result = new AscendingIntegerRangeCollection(); result.AddRangeByFirstAndLastInclusive(1000, int.MaxValue); return(result); }
private AscendingIntegerRangeCollection PrepareCollection_Min_M1000() { var result = new AscendingIntegerRangeCollection(); result.AddRangeByFirstAndLastInclusive(int.MinValue, -1000); return(result); }
public void TestRemoveCompleteRange_1() { for (int i = -2; i <= 2; ++i) { var coll = new AscendingIntegerRangeCollection(); coll.AddRangeByFirstAndLastInclusive(10, 20); coll.RemoveRangeByFirstAndLastInclusive(i + 10 - 2, i + 20 + 2); Assert.AreEqual(0, coll.RangeCount, "i=" + i.ToString()); } }
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)); } }
public void TestAddRemoveRandomly_1() { var rnd = new System.Random(); var coll = new AscendingIntegerRangeCollection(); var hashSet = new HashSet<int>(); List<int> addList = new List<int>(); List<int> rmvList = new List<int>(); string error = null; int indexThatWentWrong = -1; for (int i = 0; i < 2000; ++i) { var r = rnd.Next(10, 4000); addList.Add(r); } for (int i = 0; i < 1000; ++i) { var r = rnd.Next(10, 4000); rmvList.Add(r); } for (int i = 0; i < addList.Count; ++i) { var r = addList[i]; coll.AddRangeByFirstAndLastInclusive(r, r); hashSet.Add(r); } for (int i = 0; i < rmvList.Count; ++i) { var r = rmvList[i]; hashSet.Remove(r); coll.RemoveRangeByFirstAndLastInclusive(r, r); error = AssertEqual(coll, hashSet); if (null != error) { indexThatWentWrong = i; break; } } // Replay the error coll = new AscendingIntegerRangeCollection(); hashSet = new HashSet<int>(); for (int i = 0; i < addList.Count; ++i) { var r = addList[i]; coll.AddRangeByFirstAndLastInclusive(r, r); hashSet.Add(r); } for (int i = 0; i < rmvList.Count; ++i) { var r = rmvList[i]; hashSet.Remove(r); if (i == indexThatWentWrong) { System.Diagnostics.Debugger.Break(); } coll.RemoveRangeByFirstAndLastInclusive(r, r); error = AssertEqual(coll, hashSet); Assert.IsNull(error); } }
private AscendingIntegerRangeCollection PrepareCollection_1000_Max() { var result = new AscendingIntegerRangeCollection(); result.AddRangeByFirstAndLastInclusive(1000, int.MaxValue); return result; }
private AscendingIntegerRangeCollection PrepareCollection_Min_M1000() { var result = new AscendingIntegerRangeCollection(); result.AddRangeByFirstAndLastInclusive(int.MinValue, -1000); return result; }
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()); } }
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)); } }
private AscendingIntegerRangeCollection PrepareCollection_2_3() { var result = new AscendingIntegerRangeCollection(); result.AddRangeByFirstAndLastInclusive(2, 3); return result; }
public void TestAddRemoveRandomly_1() { var rnd = new System.Random(); var coll = new AscendingIntegerRangeCollection(); var hashSet = new HashSet <int>(); var addList = new List <int>(); var rmvList = new List <int>(); string error = null; int indexThatWentWrong = -1; for (int i = 0; i < 2000; ++i) { var r = rnd.Next(10, 4000); addList.Add(r); } for (int i = 0; i < 1000; ++i) { var r = rnd.Next(10, 4000); rmvList.Add(r); } for (int i = 0; i < addList.Count; ++i) { var r = addList[i]; coll.AddRangeByFirstAndLastInclusive(r, r); hashSet.Add(r); } for (int i = 0; i < rmvList.Count; ++i) { var r = rmvList[i]; hashSet.Remove(r); coll.RemoveRangeByFirstAndLastInclusive(r, r); error = AssertEqual(coll, hashSet); if (null != error) { indexThatWentWrong = i; break; } } // Replay the error coll = new AscendingIntegerRangeCollection(); hashSet = new HashSet <int>(); for (int i = 0; i < addList.Count; ++i) { var r = addList[i]; coll.AddRangeByFirstAndLastInclusive(r, r); hashSet.Add(r); } for (int i = 0; i < rmvList.Count; ++i) { var r = rmvList[i]; hashSet.Remove(r); if (i == indexThatWentWrong) { System.Diagnostics.Debugger.Break(); } coll.RemoveRangeByFirstAndLastInclusive(r, r); error = AssertEqual(coll, hashSet); Assert.IsNull(error); } }
public void TestAddToMaxValue_6() { var coll = new AscendingIntegerRangeCollection(); coll.AddRangeByFirstAndLastInclusive(int.MaxValue, int.MaxValue); coll.AddRangeByFirstAndLastInclusive(int.MaxValue - 2, int.MaxValue - 2); Assert.AreEqual(2, coll.RangeCount); var ranges = coll.Ranges.ToArray(); Assert.AreEqual(2, ranges.Length); Assert.AreEqual(int.MaxValue - 2, ranges[0].First); Assert.AreEqual(int.MaxValue - 2, ranges[0].LastInclusive); Assert.AreEqual(int.MaxValue, ranges[1].First); Assert.AreEqual(int.MaxValue, ranges[1].LastInclusive); }