public void UnitRb_RemoveRange() { var rb = new RankedBag <int> { Capacity = 7 }; for (int ii = 0; ii < 20; ++ii) { rb.Add(ii); } rb.RemoveRange(20, 0); Assert.AreEqual(20, rb.Count); rb.RemoveRange(12, 4); Assert.AreEqual(16, rb.Count); #if DEBUG rb.SanityCheck(); #endif }
public void UnitRbq_ElementAt() { var rb = new RankedBag <int> { Capacity = 5 }; int n = 200; for (int ii = 0; ii <= n; ++ii) { rb.Add(ii / 2); } for (int ii = 0; ii <= n; ++ii) { #if TEST_BCL Assert.AreEqual(ii / 2, Enumerable.ElementAt(rb, ii)); #else Assert.AreEqual(ii / 2, rb.ElementAt(ii)); #endif } }
static void Main() { bag = new RankedBag <int>() { Capacity = 6 }; Console.WriteLine("Using Add (x), create tree of order 6:"); for (int ii = 1; ii <= 6; ++ii) { bag.Add(3); } for (int ii = 1; ii <= 13; ++ii) { bag.Add(5); } for (int ii = 1; ii <= 7; ++ii) { bag.Add(7); } for (int ii = 1; ii <= 5; ++ii) { bag.Add(9); } WriteInfo(); Console.WriteLine("Remove (5, 10):"); bag.Remove(5, 13); WriteInfo(); bag.Clear(); Console.WriteLine("Using Add (x, n), create tree of order 6:"); bag.Add(3, 6); bag.Add(5, 13); bag.Add(7, 7); bag.Add(9, 5); WriteInfo(); }
public void UnitRb_IndexOf() { var rb0 = new RankedBag <int>(); var rb = new RankedBag <int> { Capacity = 4 }; foreach (int x in new int[] { 3, 5, 5, 7, 7 }) { rb.Add(x); } Assert.AreEqual(~0, rb0.IndexOf(9)); Assert.AreEqual(~0, rb.IndexOf(2)); Assert.AreEqual(0, rb.IndexOf(3)); Assert.AreEqual(~1, rb.IndexOf(4)); Assert.AreEqual(1, rb.IndexOf(5)); Assert.AreEqual(~3, rb.IndexOf(6)); Assert.AreEqual(3, rb.IndexOf(7)); Assert.AreEqual(~5, rb.IndexOf(8)); }
public void CrashRbq_DistinctHotUpdate() { var rb = new RankedBag <int> { Capacity = 4 }; foreach (int ii in new int[] { 1, 1, 3, 5, 7, 9 }) { rb.Add(ii); } int n = 0; #if TEST_BCL foreach (var x in Enumerable.Distinct(rb)) #else foreach (var x in rb.Distinct()) #endif { if (++n == 2) { rb.Remove(3); } } }
public void StressRbq_SkipR() { var rb = new RankedBag <int> { Capacity = 5 }; int n = 25; for (int ix = 0; ix < n; ++ix) { rb.Add(n + ix); } for (int s1 = 0; s1 <= n; ++s1) { int e0 = n + n - s1; foreach (var a0 in rb.Reverse().Skip(s1)) { --e0; Assert.AreEqual(e0, a0); } Assert.AreEqual(n, e0); } }
public void StressRbRemove() { #if STRESS int m = 2, n = 50, x1 = 0, x2 = n; #else int m = 2, n = 22, x1 = 15, x2 = x1; #endif for (int x = x1; x <= x2; ++x) { var rb = new RankedBag <int>() { Capacity = 4 }; var ex = new System.Collections.Generic.List <int>(); for (int i = n; i >= 0; --i) { rb.Add(i, m); if (i != x) { ex.Insert(0, i); ex.Insert(0, i); } } rb.Remove(x); var isOk = System.Linq.Enumerable.SequenceEqual(ex, rb); if (!isOk) { } Assert.IsTrue(System.Linq.Enumerable.SequenceEqual(ex, rb)); #if DEBUG rb.SanityCheck(); #endif } }
public void UnitRb_ElementsBetween() { var rb0 = new RankedBag <int>(); var rb1 = new RankedBag <int> { Capacity = 4 }; var rb2 = new RankedBag <int> (new int[] { 5, 5, 5, 5, 5 }); foreach (var k1 in new int[] { 3, 4, 5, 5, 6, 6, 7, 7, 8 }) { rb1.Add(k1); } var d0 = new System.Collections.Generic.List <int> (rb0.ElementsBetween(2, 4)); Assert.AreEqual(0, d0.Count); var d1 = new System.Collections.Generic.List <int> (rb1.ElementsBetween(5, 6)); Assert.AreEqual(4, d1.Count); var d2 = new System.Collections.Generic.List <int> (rb1.ElementsBetween(5, 5)); Assert.AreEqual(2, d2.Count); var d3 = new System.Collections.Generic.List <int> (rb2.ElementsBetween(5, 5)); Assert.AreEqual(5, d3.Count); var d4 = new System.Collections.Generic.List <int> (rb2.ElementsBetween(1, 2)); Assert.AreEqual(0, d4.Count); var d5 = new System.Collections.Generic.List <int> (rb2.ElementsBetween(9, 11)); Assert.AreEqual(0, d5.Count); }
public void CrashRbq_ReverseHotUpdate() { var rb = new RankedBag <int> { Capacity = 4 }; for (int ii = 9; ii >= 0; --ii) { rb.Add(ii); } int a = 0; #if TEST_BCL foreach (var key in Enumerable.Reverse(rb)) #else foreach (var x in rb.Reverse()) #endif { if (++a == 2) { rb.Clear(); } } }
public void UnitRbq_Distinct() { var rb0 = new RankedBag <int>(); var rb1 = new RankedBag <int> { Capacity = 4 }; int a0 = 0, a1 = 0; foreach (var ii in new int[] { 3, 5, 5, 7, 7 }) { rb1.Add(ii); } #if TEST_BCL foreach (var k0 in Enumerable.Distinct(rb0)) { ++a0; } foreach (var k1 in Enumerable.Distinct(rb1)) { ++a1; } #else foreach (var k0 in rb0.Distinct()) { ++a0; } foreach (var k1 in rb1.Distinct()) { ++a1; } #endif Assert.AreEqual(0, a0); Assert.AreEqual(3, a1); }
public void UnitRb_Remove2() { var rb0 = new RankedBag <int>(); var rb1 = new RankedBag <int> { Capacity = 4 }; var rb2 = new RankedBag <int> { Capacity = 4 }; var rb3 = new RankedBag <int> { Capacity = 5 }; foreach (int ii in new int[] { 3, 5, 5, 7, 7, 7, 9 }) { rb1.Add(ii); } foreach (int ii in new int[] { 3, 3, 3, 5, 5, 5, 7, 7, 7, 9 }) { rb2.Add(ii); } for (int ii = 0; ii < 41; ++ii) { rb3.Add(ii / 5); } var rem0 = rb0.Remove(0, 1); Assert.AreEqual(0, rem0); var rem2 = rb1.Remove(2, 2); Assert.AreEqual(0, rem2); var rem70 = rb1.Remove(7, 0); Assert.AreEqual(0, rem70); var rem7 = rb1.Remove(7, 1); Assert.AreEqual(1, rem7); Assert.AreEqual(6, rb1.Count); var rem5 = rb1.Remove(5, 3); Assert.AreEqual(2, rem5); Assert.AreEqual(4, rb1.Count); var rem9 = rb1.Remove(10); Assert.IsFalse(rem9); var rem53 = rb2.Remove(5, 3); Assert.AreEqual(3, rem53); var rem33 = rb2.Remove(3, 3); Assert.AreEqual(3, rem33); var rem99 = rb2.Remove(9, 9); Assert.AreEqual(1, rem99); Assert.AreEqual(3, rb2.Count); var rem35 = rb3.Remove(3, 9); Assert.AreEqual(5, rem35); Assert.AreEqual(36, rb3.Count); Assert.IsFalse(rb3.Contains(3)); var rem65 = rb3.Remove(6, Int32.MaxValue); Assert.AreEqual(5, rem65); Assert.AreEqual(31, rb3.Count); Assert.IsFalse(rb3.Contains(6)); }
public void CrashRb_Add2_ArgumentNull() { var rb = new RankedBag <int>(); var zz = rb.Add(1, -1); }