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.
Guarded dictionaries return proper Keys and Values (sestoft#92)
- Loading branch information
Showing
6 changed files
with
221 additions
and
132 deletions.
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
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,68 @@ | ||
using NUnit.Framework; | ||
|
||
namespace C5.Tests.Wrappers | ||
{ | ||
[TestFixture] | ||
public class GuardedDictionaryTests | ||
{ | ||
[Test] | ||
public void Keys_returns_GuardedCollectionValue() | ||
{ | ||
var source = new HashDictionary<int, string> | ||
{ | ||
[1] = "one", | ||
[2] = "two", | ||
[3] = "three" | ||
}; | ||
|
||
var guarded = new GuardedDictionary<int, string>(source); | ||
|
||
Assert.IsAssignableFrom<GuardedCollectionValue<int>>(guarded.Keys); | ||
} | ||
|
||
[Test] | ||
public void Keys_returns_Keys() | ||
{ | ||
var source = new HashDictionary<int, string> | ||
{ | ||
[1] = "one", | ||
[2] = "two", | ||
[3] = "three" | ||
}; | ||
|
||
var guarded = new GuardedDictionary<int, string>(source); | ||
|
||
CollectionAssert.AreEquivalent(new[] { 1, 2, 3 }, guarded.Keys); | ||
} | ||
|
||
[Test] | ||
public void Values_returns_GuardedCollectionValue() | ||
{ | ||
var source = new HashDictionary<int, string> | ||
{ | ||
[1] = "one", | ||
[2] = "two", | ||
[3] = "three" | ||
}; | ||
|
||
var guarded = new GuardedDictionary<int, string>(source); | ||
|
||
Assert.IsAssignableFrom<GuardedCollectionValue<string>>(guarded.Values); | ||
} | ||
|
||
[Test] | ||
public void Values_returns_Values() | ||
{ | ||
var source = new HashDictionary<int, string> | ||
{ | ||
[1] = "one", | ||
[2] = "two", | ||
[3] = "three" | ||
}; | ||
|
||
var guarded = new GuardedDictionary<int, string>(source); | ||
|
||
CollectionAssert.AreEquivalent(new[] { "one", "two", "three" }, guarded.Values); | ||
} | ||
} | ||
} |
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,76 @@ | ||
using NUnit.Framework; | ||
|
||
namespace C5.Tests.Wrappers | ||
{ | ||
[TestFixture] | ||
public class GuardedSortedDictionaryTests | ||
{ | ||
[Test] | ||
public void Keys_returns_GuardedSorted() | ||
{ | ||
var reverse = ComparerFactory<int>.CreateComparer((a, b) => a > b ? -1 : 1); | ||
|
||
var source = new SortedArrayDictionary<int, string>(reverse) | ||
{ | ||
[1] = "one", | ||
[2] = "two", | ||
[3] = "three" | ||
}; | ||
|
||
var guarded = new GuardedSortedDictionary<int, string>(source); | ||
|
||
Assert.IsAssignableFrom<GuardedSorted<int>>(guarded.Keys); | ||
} | ||
|
||
[Test] | ||
public void Keys_returns_Keys() | ||
{ | ||
var reverse = ComparerFactory<int>.CreateComparer((a, b) => a > b ? -1 : 1); | ||
|
||
var source = new SortedArrayDictionary<int, string>(reverse) | ||
{ | ||
[1] = "one", | ||
[2] = "two", | ||
[3] = "three" | ||
}; | ||
|
||
var guarded = new GuardedSortedDictionary<int, string>(source); | ||
|
||
CollectionAssert.AreEquivalent(new[] { 3, 2, 1 }, guarded.Keys); | ||
} | ||
|
||
[Test] | ||
public void Values_returns_GuardedCollectionValue() | ||
{ | ||
var reverse = ComparerFactory<int>.CreateComparer((a, b) => a > b ? -1 : 1); | ||
|
||
var source = new SortedArrayDictionary<int, string>(reverse) | ||
{ | ||
[1] = "one", | ||
[2] = "two", | ||
[3] = "three" | ||
}; | ||
|
||
var guarded = new GuardedSortedDictionary<int, string>(source); | ||
|
||
Assert.IsAssignableFrom<GuardedCollectionValue<string>>(guarded.Values); | ||
} | ||
|
||
[Test] | ||
public void Values_returns_Values() | ||
{ | ||
var reverse = ComparerFactory<int>.CreateComparer((a, b) => a > b ? -1 : 1); | ||
|
||
var source = new SortedArrayDictionary<int, string>(reverse) | ||
{ | ||
[1] = "one", | ||
[2] = "two", | ||
[3] = "three" | ||
}; | ||
|
||
var guarded = new GuardedSortedDictionary<int, string>(source); | ||
|
||
CollectionAssert.AreEquivalent(new[] { "one", "two", "three" }, guarded.Values); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.