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());
        }
Esempio n. 2
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);
            }
Esempio n. 3
0
            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 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);;
        }
Esempio n. 5
0
        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]);
Esempio n. 6
0
        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 TestDontCountTwice()
        {
            var dictionary = new BinaryTreeDictionary <int, string>();

            dictionary.Add(8, "eight");
            dictionary.Add(8, "eight");

            Assert.AreEqual(1, dictionary.Count);
        }
Esempio n. 8
0
        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 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 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);
        }
Esempio n. 11
0
        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 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"));;
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        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")));
        }
Esempio n. 15
0
        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());
        }
Esempio n. 16
0
        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"));
        }
Esempio n. 17
0
        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 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 TestGetValue()
        {
            var dictionary = new BinaryTreeDictionary <int, string>();

            dictionary.Add(8, "eight");

            Assert.AreEqual("eight", dictionary[8]);;
        }
Esempio n. 20
0
        public void TestRemoves()
        {
            var dict = new BinaryTreeDictionary <int, string>();

            dict.Add(1, "first value");

            Assert.IsTrue(dict.Remove(1));
            Assert.AreEqual(0, dict.Count);
        }
Esempio n. 21
0
        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 TestRemoves()
        {
            var dictionary = new BinaryTreeDictionary <int, string>();

            dictionary.Add(8, "eight");

            Assert.IsTrue(dictionary.Remove(8));;
            Assert.AreEqual(0, dictionary.Count);;
        }
Esempio n. 23
0
        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 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 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"));;
        }