Exemple #1
0
        private IPatriciaNode <T> CreateLeaf <T>(int key, T item)
            where T : class
        {
            var operation = new OperationStub <T>(i => null, () => new[] { item });

            return(EmptyPatriciaTrie <T> .Instance.Modify(key, operation));
        }
Exemple #2
0
        public void Modify_OnExistingKey_WithOperationReturningNull_ReturnsNull()
        {
            var node      = CreateLeaf(Key, Item);
            var operation = new OperationStub <string>(i => null, () => null);

            var result = node.Modify(Key, operation);

            Assert.IsNull(result);
        }
Exemple #3
0
        public void Modify_OnExistingKey_WithOperationReturningSameValue_ReturnsSameLeaf()
        {
            var node      = CreateLeaf(Key, Item);
            var operation = new OperationStub <string>(i => new[] { Item }, () => null);

            var result = node.Modify(Key, operation);

            Assert.AreSame(node, result);
        }
Exemple #4
0
        public void Modify_OnExistingKey_WithOperationReturningNewValue_CreatesModifiedLeaf()
        {
            var node      = CreateLeaf(Key, Item);
            var operation = new OperationStub <string>(i => new[] { SecondItem }, () => null);

            var result = node.Modify(Key, operation);

            Assert.IsInstanceOf <PatriciaLeaf <string> >(result);
            Assert.AreEqual(SecondItem, result.GetItems().First());
        }
Exemple #5
0
        public void Modify_OnNewKey_WithOperationReturningNewElement_CreatesBranch()
        {
            var node      = CreateLeaf(Key, Item);
            var operation = new OperationStub <string>(i => null, () => new[] { SecondItem });

            var result = node.Modify(SecondKey, operation);

            Assert.IsInstanceOf <PatriciaBranch <string> >(result);
            CollectionAssert.AreEquivalent(new[] { Item, SecondItem }, result.GetItems());
        }
Exemple #6
0
        public void RemovingFromTwoElementBranch_ReturnsOtherLeaf()
        {
            const string item = "foo", otherItem = "bar";

            var node      = CreateNode(new[] { item, otherItem });
            var operation = new OperationStub <string>(i => null, () => null);

            var result = node.Modify(item.GetHashCode(), operation);

            Assert.IsInstanceOf <PatriciaLeaf <string> >(result);
            CollectionAssert.AreEquivalent(new[] { otherItem }, result.GetItems());
        }
Exemple #7
0
        public void Modify_WithOperationReturningValue_ReturnsLeaf()
        {
            const int    key  = 10;
            const string item = "foo";

            var node      = EmptyPatriciaTrie <string> .Instance;
            var operation = new OperationStub <string>(i => null, () => new[] { item });

            var result = node.Modify(key, operation);

            Assert.AreEqual(1, result.GetItems().Count());
            Assert.IsInstanceOf <PatriciaLeaf <string> >(result);
            Assert.AreEqual(item, result.Find(key)[0]);
        }