Ejemplo n.º 1
0
        public void CanAddAndGet()
        {
            // ARRANGE
            var pair1 = new KeyValuePair <string, string>("tag1", "value1");
            var pair2 = new KeyValuePair <string, string>("tag2", "value2");

            // ACT
            var offset1 = _elementStore.Insert(new Node()
            {
                Id   = 1,
                Tags = new Dictionary <string, string> {
                    { pair1.Key, pair1.Value }
                }.ToTags()
            });
            var offset2 = _elementStore.Insert(new Node()
            {
                Id   = 2,
                Tags = new Dictionary <string, string> {
                    { pair1.Key, pair1.Value }, { pair2.Key, pair2.Value }
                }.ToTags()
            });

            var usageOffset1 = _kvStore.GetUsage(_index.GetOffset(pair1));
            var usageOffset2 = _kvStore.GetUsage(_index.GetOffset(pair2));

            var results1 = _kvUsage.Get(usageOffset1).ToArray();
            var results2 = _kvUsage.Get(usageOffset2).ToArray();

            // ASSERT
            Assert.IsNotNull(results1);
            Assert.AreEqual(2, results1.Length);
            Assert.AreEqual(offset1, results1[1]);
            Assert.AreEqual(offset2, results1[0]);

            Assert.IsNotNull(results2);
            Assert.AreEqual(1, results2.Length);
            Assert.AreEqual(offset2, results2[0]);
        }
Ejemplo n.º 2
0
        public void CanCreateAddGetOne()
        {
            // ARRANGE
            var  index  = new KeyValueIndex(Capacity, PrefixLength);
            var  pair   = new KeyValuePair <string, string>("addr", "eic");
            uint offset = 2;

            // ACT
            index.Add(pair, offset);
            var result = index.GetOffset(pair);

            // ASSERT
            Assert.AreEqual(offset, result);
        }
Ejemplo n.º 3
0
        public void CanCreateAddGetMultiply()
        {
            // ARRANGE
            var index = new KeyValueIndex(Capacity, PrefixLength);

            // ACT & ASSERT
            for (int i = 0; i < 3; i++)
            {
                index.Add(new KeyValuePair <string, string>(i.ToString(), (i + 1).ToString()), (uint)i * 10);
            }

            for (int i = 0; i < 3; i++)
            {
                var offset = index.GetOffset(new KeyValuePair <string, string>(i.ToString(), (i + 1).ToString()));
                Assert.AreEqual((uint)i * 10, offset);
            }
        }