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() { var crayons = new RankedBag <string> (StringComparer.InvariantCultureIgnoreCase) { "red", "yellow", "black", "BLACK" }; crayons.Add("blue"); Console.WriteLine($"There are {crayons.Count} total crayons:"); foreach (var crayon in crayons) { Console.WriteLine($" {crayon}"); } Console.WriteLine($"\nThere are {crayons.GetDistinctCount()} distinct colors:"); foreach (var crayon in crayons.Distinct()) { Console.WriteLine($" {crayon}"); } Console.WriteLine($"\nGot 'gold' crayon? {crayons.Contains ("gold")}"); // RetainAll respects cardinality so the oldest 'black' is removed: crayons.RetainAll(new string[] { "white", "grey", "Black", "red" }); Console.WriteLine("\nAfter RetainAll: "); foreach (var crayon in crayons) { Console.WriteLine($" {crayon}"); } }
public void UnitRb_GetDistinctCount() { var rb0 = new RankedBag <int>(); var rb = new RankedBag <int> (new int[] { 3, 5, 5, 5, 7 }); Assert.AreEqual(0, rb0.GetDistinctCount()); Assert.AreEqual(3, rb.GetDistinctCount()); }