public void AddFailDuplicate() { var dictionary = new DictionaryNoAlloc <string, int>(10); dictionary.Add("MyValue", 10); Assert.Throws <ArgumentException>(() => dictionary.Add("MyValue", 10)); }
public void AddOverRange() { var dictionary = new DictionaryNoAlloc <string, int>(2); dictionary.Add("A", 1); dictionary.Add("B", 1); Assert.Throws <OverflowException>(() => dictionary.Add("C", 1)); }
public void HashClashSevereDuplicated() { var dictionary = new DictionaryNoAlloc <HashableKey, int>(3); dictionary.Add(new HashableKey("A", 1), 10); dictionary.Add(new HashableKey("B", 1), 12); dictionary.Remove(new HashableKey("A", 1)); Assert.AreEqual(12, dictionary[new HashableKey("B", 1)]); }
public void Remove() { var dictionary = new DictionaryNoAlloc <string, int>(10); dictionary.Add("MyValue", 10); Assert.False(dictionary.Remove("NotUsedValue")); Assert.True(dictionary.Remove("MyValue")); }
public void Get() { var dictionary = new DictionaryNoAlloc <string, int>(10); dictionary.Add("MyValue", 10); Assert.AreEqual(10, dictionary["MyValue"]); }
public void Clear() { var dictionary = new DictionaryNoAlloc <int, int>(100); for (int i = 0; i < 100; ++i) { dictionary.Add(i * i, i); } dictionary.Clear(); Assert.AreEqual(0, dictionary.Count); Assert.Throws <KeyNotFoundException>(() => { int x = dictionary[4]; }); }
public void AddMany() { var dictionary = new DictionaryNoAlloc <int, int>(100); for (int i = 0; i < 100; ++i) { dictionary.Add(i * i, i); } for (int i = 0; i < 100; ++i) { Assert.AreEqual(i, dictionary[i * i]); } }
public void HashClashSevere() { var dictionary = new DictionaryNoAlloc <HashableKey, int>(100); for (int i = 0; i < 100; ++i) { dictionary.Add(new HashableKey(i.ToString()), i); } for (int i = 0; i < 100; ++i) { var key = new HashableKey(i.ToString()); Assert.AreEqual(i, dictionary[key]); } }
public void Add() { var dictionary = new DictionaryNoAlloc <string, int>(10); dictionary.Add("MyValue", 10); }