public void TestSerializeAndDeserialize() { var dictionary = new BinaryTreeDictionary <int, string>(); dictionary.Add(8, "eight"); dictionary.Add(3, "three"); dictionary.Add(6, "six"); dictionary.Add(4, "four"); var name = "some-name"; var stream = new MemoryStream(); var storageMock = new Mock <IStorage>(); storageMock.Setup(s => s.GetWriteStream(name)) .Returns(stream); storageMock.Setup(s => s.GetReadStream(name)) .Returns(stream); var serializer = new BinaryTreeDictionarySerializer(storageMock.Object); serializer.Save(name, dictionary, closeStream: false); stream.Position = 0; var newDictionary = serializer.Load <int, string>(name); CollectionAssert.AreEquivalent(dictionary.ToList(), newDictionary.ToList()); }
public void TestSerialize() { var dictionary = new BinaryTreeDictionary <int, string>(); dictionary.Add(8, "eight"); dictionary.Add(3, "three"); dictionary.Add(6, "six"); dictionary.Add(4, "four"); var name = "some-name"; var stream = new MemoryStream(); var storageMock = new Mock <IStorage>(); storageMock.Setup(s => s.GetWriteStream(name)) .Returns(stream); var serializer = new BinaryTreeDictionarySerializer(storageMock.Object); serializer.Save(name, dictionary, closeStream: false); stream.Position = 0; var serialized = Encoding.ASCII.GetString(stream.ToArray()); Assert.AreEqual(@"[{""Key"":3,""Value"":""three""},{""Key"":4,""Value"":""four""},{""Key"":6,""Value"":""six""},{""Key"":8,""Value"":""eight""}]", serialized);; }
public void TestSerializeAndDeserialize() { var dict = new BinaryTreeDictionary <int, string>(); dict.Add(1, "first value"); dict.Add(3, "third value"); dict.Add(7, "seventh value"); var name = "testFile"; var stream = new MemoryStream(); var storageMock = new Mock <IStorage>(); storageMock.Setup(s => s.GetWriteStream(name)) .Returns(stream); storageMock.Setup(s => s.GetReadStream(name)) .Returns(stream); var serializer = new BinarySearchTreeSerializer(storageMock.Object); serializer.Save(name, dict, closeStream: false); stream.Position = 0; var newDict = serializer.Load <int, string>(name); CollectionAssert.AreEquivalent(dict.ToList(), newDict.ToList()); }
public void GetAndSetValue() { var BTD = new BinaryTreeDictionary <int, int>(); BTD[0] = 1; Assert.AreEqual(1, BTD[0]); }
public void TestSerialize() { var dict = new BinaryTreeDictionary <int, string>(); dict.Add(1, "first value"); dict.Add(3, "third value"); dict.Add(7, "seventh value"); var name = "testFile"; var stream = new MemoryStream(); var storageMock = new Mock <IStorage>(); storageMock.Setup(s => s.GetWriteStream(name)) .Returns(stream); var serializer = new BinarySearchTreeSerializer(storageMock.Object); serializer.Save(name, dict, closeStream: false); stream.Position = 0; var serialized = Encoding.ASCII.GetString(stream.ToArray()); Assert.AreEqual(@"[{""Key"":1,""Value"":""first value""},{""Key"":3,""Value"":""third value""},{""Key"":7,""Value"":""seventh value""}]", serialized); }
public void TestSetValue() { var dictionary = new BinaryTreeDictionary <int, string>(); dictionary[8] = "eight"; Assert.AreEqual("eight", dictionary[8]);; }
public void TestAddKeyValueAndContains() { var dictionary = new BinaryTreeDictionary <int, string>(); dictionary.Add(new KeyValuePair <int, string>(1, "one")); Assert.IsTrue(dictionary.Contains(new KeyValuePair <int, string>(1, "one"))); }
public void TestAddAndGet() { var dict = new BinaryTreeDictionary <int, string>(); dict.Add(1, "first value"); Assert.IsTrue(dict.Contains(new KeyValuePair <int, string>(1, "first value"))); }
public void TestDontCountTwice() { var dict = new BinaryTreeDictionary <int, string>(); dict.Add(1, "first value"); dict.Add(1, "first value"); Assert.AreEqual(1, dict.Count); }
public void TestTryGetValue() { var dict = new BinaryTreeDictionary <int, string>(); dict.Add(1, "first value"); var value = "default value"; Assert.IsTrue(dict.TryGetValue(1, out value)); }
public void ClearDict() { var BTD = new BinaryTreeDictionary <int, int>(); BTD[0] = 1; BTD.Add(3, 2); BTD.Add(new KeyValuePair <int, int>(5, 11)); BTD.Clear(); Assert.AreEqual(default, BTD[default]);
public void TestDontCountTwice() { var dictionary = new BinaryTreeDictionary <int, string>(); dictionary.Add(8, "eight"); dictionary.Add(8, "eight"); Assert.AreEqual(1, dictionary.Count); }
public void TestRemoves() { var dict = new BinaryTreeDictionary <int, string>(); dict.Add(1, "first value"); Assert.IsTrue(dict.Remove(1)); Assert.AreEqual(0, dict.Count); }
public void TestRemoves() { var dictionary = new BinaryTreeDictionary <int, string>(); dictionary.Add(8, "eight"); Assert.IsTrue(dictionary.Remove(8));; Assert.AreEqual(0, dictionary.Count);; }
public void TestAddAndResetValue() { var dict = new BinaryTreeDictionary <int, string>(); dict.Add(1, "first value"); dict[1] = "default value"; Assert.IsFalse(dict.Contains(new KeyValuePair <int, string>(1, "first value"))); Assert.IsTrue(dict.Contains(new KeyValuePair <int, string>(1, "default value"))); }
public void TestCount() { var dict = new BinaryTreeDictionary <int, string>(); dict.Add(1, "first value"); dict.Add(3, "third value"); dict.Add(7, "seventh value"); Assert.AreEqual(3, dict.Count); }
public void GetCount() { var BTD = new BinaryTreeDictionary <int, int>(); BTD[0] = 1; BTD[10] = 11; BTD[-1] = 0; Assert.AreEqual(3, BTD.Count); }
public void TestCount() { var dictionary = new BinaryTreeDictionary <int, string>(); dictionary.Add(8, "eight"); dictionary.Add(3, "three"); dictionary.Add(6, "six"); dictionary.Add(4, "four"); Assert.AreEqual(4, dictionary.Count); }
public void AddToDict() { var BTD = new BinaryTreeDictionary <int, int>(); BTD[0] = 1; BTD.Add(3, 2); BTD.Add(new KeyValuePair <int, int>(5, 11)); Assert.AreEqual(2, BTD[3]); Assert.AreEqual(11, BTD[5]); }
public void TestAddMultipleAndGet() { var dictionary = new BinaryTreeDictionary <int, string>(); dictionary.Add(8, "eight"); dictionary.Add(3, "three"); dictionary.Add(6, "six"); dictionary.Add(4, "four"); Assert.IsTrue(dictionary.ContainsKey(6)); }
public void TestGetValues() { var dictionary = new BinaryTreeDictionary <int, string>(); dictionary.Add(8, "eight"); dictionary.Add(3, "three"); var testList = dictionary.Values; Assert.AreEqual(testList.Count, 2); Assert.IsTrue(testList.Contains("three"));; }
public void Save <Tkey, Tvalue>(string name, BinaryTreeDictionary <Tkey, Tvalue> dict, bool closeStream = true) where Tkey : IComparable { var ser = new DataContractJsonSerializer(typeof(BinaryTreeDictionary <Tkey, Tvalue>)); Stream stream = storage.GetWriteStream(name); ser.WriteObject(stream, dict); if (closeStream) { stream.Close(); } }
public void TestAddMultipleAndGet() { var dict = new BinaryTreeDictionary <int, string>(); dict.Add(1, "first value"); dict.Add(3, "third value"); dict.Add(7, "seventh value"); Assert.IsTrue(dict.Contains(new KeyValuePair <int, string>(7, "seventh value"))); Assert.IsTrue(dict.Contains(new KeyValuePair <int, string>(1, "first value"))); Assert.IsTrue(dict.Contains(new KeyValuePair <int, string>(3, "third value"))); }
public void TestRemovesWihDeepTree() { var dict = new BinaryTreeDictionary <int, string>(); dict.Add(1, "first value"); dict.Add(3, "third value"); dict.Add(7, "seventh value"); dict.Add(11, "eleventh value"); Assert.IsTrue(dict.Remove(3)); Assert.IsTrue(dict.Remove(11)); Assert.AreEqual(2, dict.Count); }
public void TestReturnCollection() { var dict = new BinaryTreeDictionary <int, string>(); dict.Add(1, "first value"); dict.Add(3, "third value"); var defaultDict = new Dictionary <int, string>() { { 1, "first value" }, { 3, "third value" } }; CollectionAssert.AreEqual(defaultDict, dict.ToList()); }
public void TestRemovesKeyValueWihDeepTree() { var dictionary = new BinaryTreeDictionary <int, string>(); dictionary.Add(8, "eight"); dictionary.Add(3, "three"); dictionary.Add(10, "ten"); dictionary.Add(6, "six"); dictionary.Add(1, "one"); dictionary.Add(14, "fourteen"); dictionary.Add(4, "four"); dictionary.Add(7, "seven"); Assert.IsTrue(dictionary.Remove(new KeyValuePair <int, string>(1, "one")));; Assert.AreEqual(7, dictionary.Count);; }
public void TestCopyTo() { var dict = new BinaryTreeDictionary <int, string>(); dict.Add(1, "first value"); dict.Add(3, "third value"); dict.Add(7, "seventh value"); dict.Add(11, "eleventh value"); KeyValuePair <int, string>[] array = new KeyValuePair <int, string> [4]; dict.CopyTo(array, 0); Assert.IsNotNull(array); Assert.AreEqual(array[0], new KeyValuePair <int, string>(1, "first value")); }
public void GetValues() { var BTD = new BinaryTreeDictionary <int, int>(); BTD[0] = 1; BTD[10] = 11; BTD[-1] = 0; var key = new List <int>(); foreach (var k in BTD.Values) { key.Add(k); } var assertList = new List <int>() { 1, 11, 0 }; Assert.AreEqual(assertList.ToString(), key.ToString()); }
public void TestCopyTo() { var dictionary = new BinaryTreeDictionary <int, string>(); dictionary.Add(8, "eight"); dictionary.Add(3, "three"); dictionary.Add(10, "ten"); dictionary.Add(6, "six"); dictionary.Add(1, "one"); dictionary.Add(14, "fourteen"); dictionary.Add(4, "four"); dictionary.Add(7, "seven"); KeyValuePair <int, string>[] array = new KeyValuePair <int, string> [8]; dictionary.CopyTo(array, 0); Assert.IsNotNull(array);; Assert.AreEqual(array[0], new KeyValuePair <int, string>(1, "one"));; }
public void GetKeys() { var BTD = new BinaryTreeDictionary <int, int>(); BTD[0] = 1; BTD[10] = 11; BTD[-1] = 0; var key = new List <int>(); foreach (var k in BTD.Keys) { Console.WriteLine(k); key.Add(k); } var assertList = new List <int>() { 0, 10, -1 }; CollectionAssert.AreEqual(assertList, key); }