Skip to content

Commit

Permalink
Added SCG.ISet<T> to TreeSet<T> (fixes sestoft#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
NightOwl888 committed Dec 31, 2019
1 parent 039b04c commit 890929a
Show file tree
Hide file tree
Showing 2 changed files with 788 additions and 1 deletion.
324 changes: 324 additions & 0 deletions C5.Tests/Trees/RedBlackTreeSetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3039,4 +3039,328 @@ public void Dispose()
}

}

[TestFixture]
public class SCGISet
{
private SCG.ISet<string> tree;

[SetUp]
public void Init()
{
tree = new TreeSet<string>(new SC())
{
"A", "C", "E"
};
}

[TearDown]
public void Dispose()
{
tree = null;
}

[Test]
public void Add()
{
Assert.IsTrue(tree.Add("Z"));
Assert.AreEqual(4, tree.Count);
Assert.IsTrue(tree.Contains("Z"));
Assert.IsFalse(tree.Add("A"));
}

[Test]
public void ExceptWith()
{
tree.ExceptWith(new SCG.List<string> { "C", "E", "Z" });
Assert.AreEqual(1, tree.Count);
Assert.IsTrue(tree.Contains("A"));
}

[Test]
public void ExceptWith_SameComparer()
{
tree.ExceptWith(new TreeSet<string>(new SC()) { "C", "E", "Z" });
Assert.AreEqual(1, tree.Count);
Assert.IsTrue(tree.Contains("A"));
}

[Test]
public void IntersectWith()
{
tree.IntersectWith(new SCG.List<string> { "C", "E", "Z" });
Assert.AreEqual(2, tree.Count);
Assert.IsTrue(tree.Contains("C"));
Assert.IsTrue(tree.Contains("E"));
}

[Test]
public void IntersectWith_SameComparer()
{
tree.IntersectWith(new TreeSet<string>(new SC()) { "C", "E", "Z" });
Assert.AreEqual(2, tree.Count);
Assert.IsTrue(tree.Contains("C"));
Assert.IsTrue(tree.Contains("E"));
}

[Test]
public void IsProperSubsetOf()
{
Assert.IsFalse(tree.IsProperSubsetOf(new SCG.List<string>()));
Assert.IsFalse(tree.IsProperSubsetOf(new SCG.List<string> { "C", "E", "A" }));
Assert.IsTrue(tree.IsProperSubsetOf(new SCG.List<string> { "C", "E", "A", "X" }));
Assert.IsFalse(tree.IsProperSubsetOf(new SCG.List<string> { "C", "Z" }));
tree.Clear();
Assert.IsTrue(tree.IsProperSubsetOf(new SCG.List<string> { "C", "A" }));
}

[Test]
public void IsProperSubsetOf_SameComparer()
{
Assert.IsFalse(tree.IsProperSubsetOf(new TreeSet<string>(new SC())));
Assert.IsFalse(tree.IsProperSubsetOf(new TreeSet<string>(new SC()) { "C", "E", "A" }));
Assert.IsTrue(tree.IsProperSubsetOf(new TreeSet<string>(new SC()) { "C", "E", "A", "X" }));
Assert.IsFalse(tree.IsProperSubsetOf(new TreeSet<string>(new SC()) { "C", "Z" }));
tree.Clear();
Assert.IsTrue(tree.IsProperSubsetOf(new TreeSet<string>(new SC()) { "C", "A" }));
}

[Test]
public void IsProperSupersetOf()
{
Assert.IsTrue(tree.IsProperSupersetOf(new SCG.List<string>()));
Assert.IsFalse(tree.IsProperSupersetOf(new SCG.List<string> { "C", "E", "A" }));
Assert.IsTrue(tree.IsProperSupersetOf(new SCG.List<string> { "C", "A" }));
Assert.IsFalse(tree.IsProperSupersetOf(new SCG.List<string> { "C", "Z" }));
tree.Clear();
Assert.IsFalse(tree.IsProperSupersetOf(new SCG.List<string> { "C", "A" }));
}

[Test]
public void IsProperSupersetOf_SameComparer()
{
Assert.IsTrue(tree.IsProperSupersetOf(new TreeSet<string>(new SC())));
Assert.IsFalse(tree.IsProperSupersetOf(new TreeSet<string>(new SC()) { "C", "E", "A" }));
Assert.IsTrue(tree.IsProperSupersetOf(new TreeSet<string>(new SC()) { "C", "A" }));
Assert.IsFalse(tree.IsProperSupersetOf(new TreeSet<string>(new SC()) { "C", "Z" }));
tree.Clear();
Assert.IsFalse(tree.IsProperSupersetOf(new TreeSet<string>(new SC()) { "C", "A" }));
}

[Test]
public void IsSubsetOf()
{
Assert.IsFalse(tree.IsSubsetOf(new SCG.List<string>()));
Assert.IsTrue(tree.IsSubsetOf(new SCG.List<string> { "C", "E", "A" }));
Assert.IsTrue(tree.IsSubsetOf(new SCG.List<string> { "C", "E", "A", "X" }));
Assert.IsFalse(tree.IsSubsetOf(new SCG.List<string> { "C", "Z" }));
Assert.IsFalse(tree.IsSubsetOf(new SCG.List<string> { "C", "A", "Z" }));
tree.Clear();
Assert.IsTrue(tree.IsSubsetOf(new SCG.List<string> { "C", "A" }));
}

[Test]
public void IsSubsetOf_SameComparer()
{
Assert.IsFalse(tree.IsSubsetOf(new TreeSet<string>(new SC())));
Assert.IsTrue(tree.IsSubsetOf(new TreeSet<string>(new SC()) { "C", "E", "A" }));
Assert.IsTrue(tree.IsSubsetOf(new TreeSet<string>(new SC()) { "C", "E", "A", "X" }));
Assert.IsFalse(tree.IsSubsetOf(new TreeSet<string>(new SC()) { "C", "Z" }));
Assert.IsFalse(tree.IsSubsetOf(new TreeSet<string>(new SC()) { "C", "A", "Z" }));
tree.Clear();
Assert.IsTrue(tree.IsSubsetOf(new TreeSet<string>(new SC()) { "C", "A" }));
}

[Test]
public void IsSupersetOf()
{
Assert.IsTrue(tree.IsSupersetOf(new SCG.List<string>()));
Assert.IsTrue(tree.IsSupersetOf(new SCG.List<string> { "C", "E", "A" }));
Assert.IsFalse(tree.IsSupersetOf(new SCG.List<string> { "C", "E", "A", "X" }));
Assert.IsFalse(tree.IsSupersetOf(new SCG.List<string> { "C", "Z" }));
Assert.IsTrue(tree.IsSupersetOf(new SCG.List<string> { "C", "A" }));
tree.Clear();
Assert.IsFalse(tree.IsSupersetOf(new SCG.List<string> { "C", "A" }));
}

[Test]
public void IsSupersetOf_SameComparer()
{
Assert.IsTrue(tree.IsSupersetOf(new TreeSet<string>(new SC())));
Assert.IsTrue(tree.IsSupersetOf(new TreeSet<string>(new SC()) { "C", "E", "A" }));
Assert.IsFalse(tree.IsSupersetOf(new TreeSet<string>(new SC()) { "C", "E", "A", "X" }));
Assert.IsFalse(tree.IsSupersetOf(new TreeSet<string>(new SC()) { "C", "Z" }));
Assert.IsTrue(tree.IsSupersetOf(new TreeSet<string>(new SC()) { "C", "A" }));
tree.Clear();
Assert.IsFalse(tree.IsSupersetOf(new TreeSet<string>(new SC()) { "C", "A" }));
}

[Test]
public void Overlaps()
{
Assert.IsFalse(tree.Overlaps(new SCG.List<string>()));
Assert.IsTrue(tree.Overlaps(new SCG.List<string> { "C", "E", "A" }));
Assert.IsTrue(tree.Overlaps(new SCG.List<string> { "C", "E", "A", "X" }));
Assert.IsFalse(tree.Overlaps(new SCG.List<string> { "X", "Z" }));
Assert.IsTrue(tree.Overlaps(new SCG.List<string> { "C", "A" }));
tree.Clear();
Assert.IsFalse(tree.Overlaps(new SCG.List<string> { "C", "A" }));
}

[Test]
public void Overlaps_SameComparer()
{
Assert.IsFalse(tree.Overlaps(new TreeSet<string>(new SC())));
Assert.IsTrue(tree.Overlaps(new TreeSet<string>(new SC()) { "C", "E", "A" }));
Assert.IsTrue(tree.Overlaps(new TreeSet<string>(new SC()) { "C", "E", "A", "X" }));
Assert.IsFalse(tree.Overlaps(new TreeSet<string>(new SC()) { "X", "Z" }));
Assert.IsTrue(tree.Overlaps(new TreeSet<string>(new SC()) { "C", "A" }));
tree.Clear();
Assert.IsFalse(tree.Overlaps(new TreeSet<string>(new SC()) { "C", "A" }));
}

[Test]
public void SetEquals()
{
Assert.IsFalse(tree.SetEquals(new SCG.List<string>()));
Assert.IsTrue(tree.SetEquals(new SCG.List<string> { "C", "E", "A" }));
Assert.IsFalse(tree.SetEquals(new SCG.List<string> { "C", "E", "A", "X" }));
Assert.IsFalse(tree.SetEquals(new SCG.List<string> { "X", "Z" }));
Assert.IsFalse(tree.SetEquals(new SCG.List<string> { "C", "A" }));
tree.Clear();
Assert.IsFalse(tree.SetEquals(new SCG.List<string> { "C", "A" }));
Assert.IsTrue(tree.SetEquals(new SCG.List<string>()));
}

[Test]
public void SetEquals_SameComparer()
{
Assert.IsFalse(tree.SetEquals(new TreeSet<string>(new SC())));
Assert.IsTrue(tree.SetEquals(new TreeSet<string>(new SC()) { "C", "E", "A" }));
Assert.IsFalse(tree.SetEquals(new TreeSet<string>(new SC()) { "C", "E", "A", "X" }));
Assert.IsFalse(tree.SetEquals(new TreeSet<string>(new SC()) { "X", "Z" }));
Assert.IsFalse(tree.SetEquals(new TreeSet<string>(new SC()) { "C", "A" }));
tree.Clear();
Assert.IsFalse(tree.SetEquals(new TreeSet<string>(new SC()) { "C", "A" }));
Assert.IsTrue(tree.SetEquals(new TreeSet<string>(new SC())));
}

[Test]
public void SymmetricExceptWith()
{
tree.SymmetricExceptWith(new SCG.List<string>());
Assert.AreEqual(3, tree.Count);
tree.SymmetricExceptWith(new SCG.List<string> { "C", "E", "R", "X" });
Assert.AreEqual(3, tree.Count);
Assert.IsTrue(tree.SetEquals(new SCG.List<string> { "A", "R", "X" }));
tree.SymmetricExceptWith(new SCG.List<string> { "A", "R", "X" });
Assert.AreEqual(0, tree.Count);

tree.Clear();
tree.SymmetricExceptWith(new SCG.List<string> { "C", "E", "A" });
Assert.IsTrue(tree.SetEquals(new SCG.List<string> { "C", "E", "A" }));
}

[Test]
public void SymmetricExceptWith_SameComparer()
{
tree.SymmetricExceptWith(new TreeSet<string>(new SC()));
Assert.AreEqual(3, tree.Count);
tree.SymmetricExceptWith(new TreeSet<string>(new SC()) { "C", "E", "R", "X" });
Assert.AreEqual(3, tree.Count);
Assert.IsTrue(tree.SetEquals(new SCG.List<string> { "A", "R", "X" }));
tree.SymmetricExceptWith(new TreeSet<string>(new SC()) { "A", "R", "X" });
Assert.AreEqual(0, tree.Count);

tree.Clear();
tree.SymmetricExceptWith(new TreeSet<string>(new SC()) { "C", "E", "A" });
Assert.IsTrue(tree.SetEquals(new SCG.List<string> { "C", "E", "A" }));
}

[Test]
public void UnionWith()
{
tree.UnionWith(new SCG.List<string>());
Assert.AreEqual(3, tree.Count);
tree.UnionWith(new SCG.List<string> { "C", "E", "R", "X" });
Assert.AreEqual(5, tree.Count);
Assert.IsTrue(tree.SetEquals(new SCG.List<string> { "A", "C", "E", "R", "X" }));
tree.UnionWith(new SCG.List<string> { "A", "R", "X" });
Assert.AreEqual(5, tree.Count);
Assert.IsTrue(tree.SetEquals(new SCG.List<string> { "A", "C", "E", "R", "X" }));

tree.Clear();
tree.UnionWith(new SCG.List<string> { "C", "E", "A" });
Assert.IsTrue(tree.SetEquals(new SCG.List<string> { "C", "E", "A" }));
}

[Test]
public void UnionWith_SameComparer()
{
tree.UnionWith(new TreeSet<string>(new SC()));
Assert.AreEqual(3, tree.Count);
tree.UnionWith(new TreeSet<string>(new SC()) { "C", "E", "R", "X" });
Assert.AreEqual(5, tree.Count);
Assert.IsTrue(tree.SetEquals(new SCG.List<string> { "A", "C", "E", "R", "X" }));
tree.UnionWith(new TreeSet<string>(new SC()) { "A", "R", "X" });
Assert.AreEqual(5, tree.Count);
Assert.IsTrue(tree.SetEquals(new SCG.List<string> { "A", "C", "E", "R", "X" }));

tree.Clear();
tree.UnionWith(new TreeSet<string>(new SC()) { "C", "E", "A" });
Assert.IsTrue(tree.SetEquals(new SCG.List<string> { "C", "E", "A" }));
}

// ICollection<T> members
[Test]
public void Clear()
{
Assert.AreEqual(3, tree.Count);
tree.Clear();
Assert.AreEqual(0, tree.Count);
}

[Test]
public void Contains()
{
Assert.IsTrue(tree.Contains("A"));
Assert.IsFalse(tree.Contains("Z"));
}

[Test]
public void CopyTo()
{
var values = new string[tree.Count + 2];
tree.CopyTo(values, 1);
Assert.AreEqual(null, values[0]);
Assert.AreEqual("A", values[1]);
Assert.AreEqual("C", values[2]);
Assert.AreEqual("E", values[3]);
Assert.AreEqual(null, values[4]);
}

[Test]
public void Remove()
{
Assert.AreEqual(3, tree.Count);
Assert.IsTrue(tree.Remove("A"));
Assert.AreEqual(2, tree.Count);
Assert.IsFalse(tree.Remove("A"));
Assert.AreEqual(2, tree.Count);
}

[Test]
public void Count()
{
Assert.AreEqual(3, tree.Count);
tree.Add("Foo");
Assert.AreEqual(4, tree.Count);
}

[Test]
public void IsReadOnly()
{
Assert.AreEqual(false, tree.IsReadOnly);
}
}
}
Loading

0 comments on commit 890929a

Please sign in to comment.