public void TestCtors() { var empty = new RedBlackSetTester<char>(); Assert.That(empty.Empty, Is.True); Assert.That(empty.Count(), Is.EqualTo(0)); Assert.That(empty.ToList(), Is.Empty); empty.Add('1'); Assert.That(empty.Empty, Is.False); Assert.That(empty.Count(), Is.EqualTo(1)); WithRandomNumbers(list => { var range = Enumerable.Range(42, list.Count); var two = new RedBlackMapTester<int, int>(list, range); var prs = new RedBlackMapTester<int, int>(list.Zip<int, int, KeyValuePair<int, int>>(range, RedBlackMap<int, int>.KeyValuePair.Create)); var tup = new RedBlackMapTester<int, int>(list.Zip<int, int, Tuple<int, int>>(range, Tuple.Create)); Assert.That(two.ToArray(), Is.EqualTo(prs.ToList())); Assert.That(two.ToArray(), Is.EqualTo(tup.ToList())); }); Assert.That(() => { new RedBlackMapTester<int, int>(Enumerable.Range(1, 3), Enumerable.Range(1, 4)); }, Throws.ArgumentException); }
public void TestCacheWorks() { var init = new int[] { 2, 3, 4, 5 }; var t = new RedBlackSetTester<int>(init); Assert.That(t.Cache, Is.EqualTo(init)); Assert.That(t.Remove(4), Is.True); var remove = init.Where(i => i != 4); Assert.That(t.Add(2), Is.False); Assert.That(t.Cache, Is.EquivalentTo(remove)); Assert.That(t.Add(7), Is.True); var add = remove.Concat(Enumerable.Repeat(7, 1)); Assert.That(t.Cache, Is.EquivalentTo(add)); t.Clear(); Assert.That(t.Cache, Is.Empty); }
public void TestBalancedness() { var perfect = new RedBlackSetTester<int>(); perfect.Add(4); perfect.Add(2); perfect.Add(1); perfect.Add(3); perfect.Add(6); perfect.Add(5); perfect.Add(7); Assert.That(perfect.MaxDepth(), Is.EqualTo(3)); }
public void TestDepthOfLinearInsertion() { const int up2 = 9999; var rbt = new RedBlackSetTester<int>(Enumerable.Range(1, 7)); double max = 0.0; for (int i = 8; i <= up2; ++i) { rbt.Add(i); double actual = rbt.MaxDepth(); double perfect = Math.Log(i, 2.0); double ratio = actual / perfect; max = Math.Max(max, ratio); } Assert.That(rbt.Count, Is.EqualTo(up2)); Assert.That(max, Is.LessThanOrEqualTo(2.0)); }
public void TestIsProperSupersetOf() { var a = new RedBlackSetTester<int>(); Assert.That(() => a.IsProperSupersetOf(null), Throws.InstanceOf<ArgumentNullException>()); Assert.That(a.IsProperSupersetOf(Enumerable.Empty<int>()), Is.False); Assert.That(a.IsProperSupersetOf(Enumerable.Range(1, 1)), Is.False); a.Add(2); Assert.That(a.IsProperSupersetOf(Enumerable.Empty<int>())); a.AddRange(_odd); Assert.That(a.IsProperSupersetOf(_primes)); }