using System; using System.Collections.Generic; using System.Linq; using System.Text; using NUnit.Framework; using Developpez.Dotnet.Collections; namespace Developpez.Dotnet.Tests.Collections { [TestFixture] public class DefaultDictionaryTests { [Test] public void Test_WithGenerator() { Func generator = key => key.Length; var dic = new DefaultDictionary(generator); string s = "Hello world !"; int expected = s.Length; int actual = dic[s]; Assert.AreEqual(expected, actual); s = "foo"; expected = s.Length; Assert.IsTrue(dic.TryGetValue(s, out actual)); Assert.AreEqual(expected, actual); } [Test] public void Test_WithDefaultValue() { int defaultValue = 42; var dic = new DefaultDictionary(defaultValue); string s = "Hello world !"; int expected = defaultValue; int actual = dic[s]; Assert.AreEqual(expected, actual); s = "foo"; expected = defaultValue; Assert.IsTrue(dic.TryGetValue(s, out actual)); Assert.AreEqual(expected, actual); } [Test] public void Test_WithoutDefault() { var dic = new DefaultDictionary(); string s = "Hello world !"; int expected = default(int); int actual = dic[s]; Assert.AreEqual(expected, actual); s = "foo"; expected = default(int); Assert.IsTrue(dic.TryGetValue(s, out actual)); Assert.AreEqual(expected, actual); } } }