public void UnitRb_GetCount() { var rb0 = new RankedBag <int>(); var rb = new RankedBag <int> (new int[] { 3, 5, 5, 5, 7 }); Assert.AreEqual(0, rb0.GetCount(4)); Assert.AreEqual(0, rb.GetCount(1)); Assert.AreEqual(1, rb.GetCount(3)); Assert.AreEqual(3, rb.GetCount(5)); Assert.AreEqual(1, rb.GetCount(7)); Assert.AreEqual(0, rb.GetCount(9)); }
public void StressRb_Counts() { #if STRESS int n = 136; #else int n = 5; #endif int reps = 100; for (int order = 4; order <= n; order += 8) { var rb = new RankedBag <int> { Capacity = order }; for (int ix = 1; ix <= reps; ++ix) { rb.Add(ix, ix); } for (int ix = 1; ix <= reps; ++ix) { Assert.AreEqual(ix, rb.GetCount(ix)); } Assert.AreEqual((reps + 1) * reps / 2, rb.Count); Assert.AreEqual(reps, rb.GetDistinctCount()); } }
static void Main() { bag = new RankedBag <int>() { Capacity = 4 }; Console.WriteLine("Create tree of order 4:"); for (int i = 2; i <= 12; i += 2) { bag.Add(i); } for (int i = 2; i <= 12; i += 2) { bag.Add(i); } for (int i = 2; i <= 12; i += 2) { bag.Add(i); } for (int i = 2; i <= 12; i += 2) { bag.Add(i); } WriteInfo(); var a1 = new int[] { 4, 6, 6, 6 }; Console.WriteLine("\nRemoveAll " + String.Join(",", a1) + ":"); bag.RemoveAll(a1); WriteInfo(); Console.WriteLine("\nRemoveAll 8:"); bag.RemoveAll(new int[] { 8 }); WriteInfo(); Console.WriteLine("\nRemoveAll 8:"); bag.RemoveAll(new int[] { 8 }); WriteInfo(); Console.WriteLine("GetCount(12) = " + bag.GetCount(12)); var a2 = new int[] { 1, 2, 2, 5, 10, 21 }; Console.WriteLine("\nRetain " + String.Join(",", a2) + ":"); bag.RetainAll(a2); WriteInfo(); }