示例#1
0
        public void When_adding_value_with_hash_conflicted_key_Then_I_should_be_able_to_get_it_back()
        {
            var key1 = new HashConflictingKey <string>("a", 1);
            var key2 = new HashConflictingKey <string>("b", 1);
            var key3 = new HashConflictingKey <string>("c", 1);
            var tree = ImHashMap <HashConflictingKey <string>, int> .Empty
                       .AddOrUpdate(key1, 1)
                       .AddOrUpdate(key2, 2)
                       .AddOrUpdate(key3, 3);

            var value = tree.GetValueOrDefault(key3);

            Assert.That(value, Is.EqualTo(3));
        }
示例#2
0
        public void When_adding_value_with_hash_conflicted_key_Then_I_should_be_able_to_get_it_back_TryFind()
        {
            var key1 = new HashConflictingKey <string>("a", 1);
            var key2 = new HashConflictingKey <string>("b", 1);
            var key3 = new HashConflictingKey <string>("c", 1);
            var tree = ImHashMap <HashConflictingKey <string>, int> .Empty
                       .AddOrUpdate(key1, 1)
                       .AddOrUpdate(key2, 2)
                       .AddOrUpdate(key3, 3);

            int value;

            Assert.IsTrue(tree.TryFind(key3, out value));
            Assert.That(value, Is.EqualTo(3));
        }
示例#3
0
        public void When_adding_couple_of_values_with_hash_conflicted_key_Then_I_should_be_able_to_get_them_back()
        {
            var key1 = new HashConflictingKey <string>("a", 1);
            var key2 = new HashConflictingKey <string>("b", 1);
            var key3 = new HashConflictingKey <string>("c", 1);
            var tree = ImHashMap <HashConflictingKey <string>, int> .Empty
                       .AddOrUpdate(key1, 1)
                       .AddOrUpdate(key2, 2)
                       .AddOrUpdate(key3, 3);

            var values = tree.Enumerate().ToDictionary(kv => kv.Key.Key, kv => kv.Value);

            Assert.That(values, Is.EqualTo(new Dictionary <string, int>
            {
                { "a", 1 },
                { "b", 2 },
                { "c", 3 },
            }));
        }
示例#4
0
        public void Can_fold_values_with_hash_conflicted_key()
        {
            var key1 = new HashConflictingKey <string>("a", 1);
            var key2 = new HashConflictingKey <string>("b", 1);
            var key3 = new HashConflictingKey <string>("c", 1);
            var tree = ImHashMap <HashConflictingKey <string>, int> .Empty
                       .AddOrUpdate(key1, 1)
                       .AddOrUpdate(key2, 2)
                       .AddOrUpdate(key3, 3);

            var values = tree.Fold(new Dictionary <string, int>(), (data, dict) => dict.Do(data, (x, d) => x.Add(d.Key.Key, d.Value)));

            Assert.That(values, Is.EqualTo(new Dictionary <string, int>
            {
                { "a", 1 },
                { "b", 2 },
                { "c", 3 },
            }));
        }