-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix InternMap and add test cases (#26)
- Loading branch information
1 parent
22aa1d8
commit 3c05d1f
Showing
3 changed files
with
110 additions
and
15 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,49 @@ | ||
namespace Maroontress.Util.Test | ||
{ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
[TestClass] | ||
public sealed class InternMapTest | ||
{ | ||
[TestMethod] | ||
public void Intern_Func_1() | ||
{ | ||
var map = new InternMap<int, string>(); | ||
var key = 12; | ||
var v1 = "12"; | ||
var v2 = string.Join("", new[] { "1", "2" }); | ||
Assert.AreNotSame(v1, v2); | ||
var c1 = map.Intern(key, () => v1); | ||
Assert.AreSame(v1, c1); | ||
var c2 = map.Intern(key, () => v2); | ||
Assert.AreSame(c1, c2); | ||
} | ||
|
||
[TestMethod] | ||
public void Intern_Func_2() | ||
{ | ||
var map = new InternMap<int, string>(); | ||
var key = 12; | ||
var c1 = map.Intern(key, k => k.ToString()); | ||
var c2 = map.Intern(key, k => k.ToString()); | ||
Assert.AreSame(c1, c2); | ||
} | ||
|
||
[TestMethod] | ||
public void Intern_Func_1_Null() | ||
{ | ||
var map = new InternMap<int, string>(); | ||
Assert.ThrowsException<ArgumentNullException>( | ||
() => _ = map.Intern(12, (Func<string>)null!)); | ||
} | ||
|
||
[TestMethod] | ||
public void Intern_Func_2_Null() | ||
{ | ||
var map = new InternMap<int, string>(); | ||
Assert.ThrowsException<ArgumentNullException>( | ||
() => _ = map.Intern(12, (Func<int, string>)null!)); | ||
} | ||
} | ||
} |
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