forked from sestoft/C5
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added SCG.ISet<T> to HashSet<T> (sestoft#53)
- Loading branch information
1 parent
e5302c6
commit d7298af
Showing
2 changed files
with
806 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,332 @@ | ||
// This file is part of the C5 Generic Collection Library for C# and CLI | ||
// See https://github.com/sestoft/C5/blob/master/LICENSE.txt for licensing details. | ||
|
||
using NUnit.Framework; | ||
using SCG = System.Collections.Generic; | ||
|
||
namespace C5.Tests.Hashing | ||
{ | ||
[TestFixture] | ||
public class SCGISet | ||
{ | ||
private SCG.ISet<string> tree; | ||
|
||
[SetUp] | ||
public void Init() | ||
{ | ||
tree = new HashSet<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_SameEqualityComparer() | ||
{ | ||
tree.ExceptWith(new TreeSet<string>(new SC(), 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_SameEqualityComparer() | ||
{ | ||
tree.IntersectWith(new TreeSet<string>(new SC(), 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_SameEqualityComparer() | ||
{ | ||
Assert.IsFalse(tree.IsProperSubsetOf(new TreeSet<string>(new SC(), new SC()))); | ||
Assert.IsFalse(tree.IsProperSubsetOf(new TreeSet<string>(new SC(), new SC()) { "C", "E", "A" })); | ||
Assert.IsTrue(tree.IsProperSubsetOf(new TreeSet<string>(new SC(), new SC()) { "C", "E", "A", "X" })); | ||
Assert.IsFalse(tree.IsProperSubsetOf(new TreeSet<string>(new SC(), new SC()) { "C", "Z" })); | ||
tree.Clear(); | ||
Assert.IsTrue(tree.IsProperSubsetOf(new TreeSet<string>(new SC(), 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_SameEqualityComparer() | ||
{ | ||
Assert.IsTrue(tree.IsProperSupersetOf(new TreeSet<string>(new SC(), new SC()))); | ||
Assert.IsFalse(tree.IsProperSupersetOf(new TreeSet<string>(new SC(), new SC()) { "C", "E", "A" })); | ||
Assert.IsTrue(tree.IsProperSupersetOf(new TreeSet<string>(new SC(), new SC()) { "C", "A" })); | ||
Assert.IsFalse(tree.IsProperSupersetOf(new TreeSet<string>(new SC(), new SC()) { "C", "Z" })); | ||
tree.Clear(); | ||
Assert.IsFalse(tree.IsProperSupersetOf(new TreeSet<string>(new SC(), 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_SameEqualityComparer() | ||
{ | ||
Assert.IsFalse(tree.IsSubsetOf(new TreeSet<string>(new SC(), new SC()))); | ||
Assert.IsTrue(tree.IsSubsetOf(new TreeSet<string>(new SC(), new SC()) { "C", "E", "A" })); | ||
Assert.IsTrue(tree.IsSubsetOf(new TreeSet<string>(new SC(), new SC()) { "C", "E", "A", "X" })); | ||
Assert.IsFalse(tree.IsSubsetOf(new TreeSet<string>(new SC(), new SC()) { "C", "Z" })); | ||
Assert.IsFalse(tree.IsSubsetOf(new TreeSet<string>(new SC(), new SC()) { "C", "A", "Z" })); | ||
tree.Clear(); | ||
Assert.IsTrue(tree.IsSubsetOf(new TreeSet<string>(new SC(), 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_SameEqualityComparer() | ||
{ | ||
Assert.IsTrue(tree.IsSupersetOf(new TreeSet<string>(new SC(), new SC()))); | ||
Assert.IsTrue(tree.IsSupersetOf(new TreeSet<string>(new SC(), new SC()) { "C", "E", "A" })); | ||
Assert.IsFalse(tree.IsSupersetOf(new TreeSet<string>(new SC(), new SC()) { "C", "E", "A", "X" })); | ||
Assert.IsFalse(tree.IsSupersetOf(new TreeSet<string>(new SC(), new SC()) { "C", "Z" })); | ||
Assert.IsTrue(tree.IsSupersetOf(new TreeSet<string>(new SC(), new SC()) { "C", "A" })); | ||
tree.Clear(); | ||
Assert.IsFalse(tree.IsSupersetOf(new TreeSet<string>(new SC(), 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_SameEqualityComparer() | ||
{ | ||
Assert.IsFalse(tree.Overlaps(new TreeSet<string>(new SC(), new SC()))); | ||
Assert.IsTrue(tree.Overlaps(new TreeSet<string>(new SC(), new SC()) { "C", "E", "A" })); | ||
Assert.IsTrue(tree.Overlaps(new TreeSet<string>(new SC(), new SC()) { "C", "E", "A", "X" })); | ||
Assert.IsFalse(tree.Overlaps(new TreeSet<string>(new SC(), new SC()) { "X", "Z" })); | ||
Assert.IsTrue(tree.Overlaps(new TreeSet<string>(new SC(), new SC()) { "C", "A" })); | ||
tree.Clear(); | ||
Assert.IsFalse(tree.Overlaps(new TreeSet<string>(new SC(), 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_SameEqualityComparer() | ||
{ | ||
Assert.IsFalse(tree.SetEquals(new TreeSet<string>(new SC(), new SC()))); | ||
Assert.IsTrue(tree.SetEquals(new TreeSet<string>(new SC(), new SC()) { "C", "E", "A" })); | ||
Assert.IsFalse(tree.SetEquals(new TreeSet<string>(new SC(), new SC()) { "C", "E", "A", "X" })); | ||
Assert.IsFalse(tree.SetEquals(new TreeSet<string>(new SC(), new SC()) { "X", "Z" })); | ||
Assert.IsFalse(tree.SetEquals(new TreeSet<string>(new SC(), new SC()) { "C", "A" })); | ||
tree.Clear(); | ||
Assert.IsFalse(tree.SetEquals(new TreeSet<string>(new SC(), new SC()) { "C", "A" })); | ||
Assert.IsTrue(tree.SetEquals(new TreeSet<string>(new SC(), 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_SameEqualityComparer() | ||
{ | ||
tree.SymmetricExceptWith(new TreeSet<string>(new SC(), new SC())); | ||
Assert.AreEqual(3, tree.Count); | ||
tree.SymmetricExceptWith(new TreeSet<string>(new SC(), 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(), new SC()) { "A", "R", "X" }); | ||
Assert.AreEqual(0, tree.Count); | ||
|
||
tree.Clear(); | ||
tree.SymmetricExceptWith(new TreeSet<string>(new SC(), 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_SameEqualityComparer() | ||
{ | ||
tree.UnionWith(new TreeSet<string>(new SC(), new SC())); | ||
Assert.AreEqual(3, tree.Count); | ||
tree.UnionWith(new TreeSet<string>(new SC(), 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(), 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(), 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); | ||
} | ||
} | ||
} |
Oops, something went wrong.