コード例 #1
0
        public void PutTest()
        {
            NativeDictionary <string> programmers = new NativeDictionary <string>(5);

            string key    = "Jimmy";
            string value  = "Nube";
            string key2   = "Li";
            string value2 = "Junior";
            string key3   = "Gordon";
            string value3 = "Middle";
            string key4   = "Fred";
            string value4 = "Senior";
            string key5   = "Jessica";
            string value5 = "Team Lead";

            programmers.Put(key, value);
            programmers.Put(key2, value2);
            programmers.Put(key3, value3);
            programmers.Put(key4, value4);
            programmers.Put(key5, value5);

            int    expectedSize  = 5;
            string expectedKey   = "Gordon";
            string expectedValue = "Middle";
            int    actualSize    = programmers.size;
            string actualKey     = programmers.slots[2];
            string actualValue   = programmers.values[2];

            Assert.IsTrue(programmers.IsKey(key));
            Assert.IsTrue(programmers.IsKey("Jessica"));
            Assert.AreEqual(expectedSize, actualSize);
            Assert.AreEqual(expectedKey, actualKey);
            Assert.AreEqual(expectedValue, actualValue);
        }
コード例 #2
0
        public void TestA_Get_3()
        {
            int    size   = 4;
            string key1   = "one";
            string key2   = "one";
            int    index1 = 10;
            int    index2 = 10;

            NativeDictionary <int> nat = new NativeDictionary <int>(size);

            nat.Put(key1, 1);
            nat.Put(key2, 2);

            for (int i = 0; i < size; i++)
            {
                if (nat.values[i] == 1)
                {
                    index1 = i;
                }
                if (nat.values[i] == 2)
                {
                    index2 = i;
                }
            }


            Assert.AreEqual(true, index1 == 10);
            Assert.AreEqual(true, index2 != 10);
        }
コード例 #3
0
        public void TestC_Put_1()
        {
            int size = 16;
            NativeDictionary <BitBag> nat = new NativeDictionary <BitBag>(size);

            nat.Put("key1", new BitBag(1));
            nat.Put("key2", new BitBag(2));

            Assert.AreEqual(1, nat.Get("key1").value);
            Assert.AreEqual(2, nat.Get("key2").value);
        }
コード例 #4
0
        public void Test_Get()
        {
            var dictionary = new NativeDictionary <int>(2);

            dictionary.Put("a", 1);
            dictionary.Put("k", 2);

            var result = dictionary.Get("k");

            Assert.AreEqual(2, result);
        }
コード例 #5
0
        public void IsKey()
        {
            NativeDictionary <int> dict = new NativeDictionary <int>(5);

            dict.Put("1", 1);
            dict.Put("2", 2);

            Assert.True(dict.IsKey("1"));
            Assert.True(dict.IsKey("2"));
            Assert.True(!dict.IsKey("3"));
        }
コード例 #6
0
        public void TestB_Put_5()
        {
            NativeDictionary <string> nat = new NativeDictionary <string>(16);

            nat.Put("1", "1");
            nat.Put("11", "2");
            nat.Put("111", "3");

            Assert.AreEqual("1", nat.Get("1"));
            Assert.AreEqual("2", nat.Get("11"));
            Assert.AreEqual("3", nat.Get("111"));
        }
コード例 #7
0
        public void Test_Put_WhenNoExtend()
        {
            var dictionary = new NativeDictionary <int>(10);

            dictionary.Put("a", 1);
            dictionary.Put("b", 2);
            dictionary.Put("c", 3);
            dictionary.Put("d", 4);
            var result = dictionary.IsKey("c");

            Assert.AreEqual(true, result);
        }
コード例 #8
0
        public void TestA_Get_2()
        {
            int    size = 4;
            string key1 = "one";
            string key2 = "two";
            string key3 = "three";
            string key4 = "four";

            NativeDictionary <int> nat = new NativeDictionary <int>(size);

            nat.Put(key1, 614);
            nat.Put(key2, 921);
            nat.Put(key3, 53);
            nat.Put(key4, 910);

            int index1 = 0;
            int index2 = 0;
            int index3 = 0;
            int index4 = 0;

            for (int i = 0; i < size; i++)
            {
                if (nat.values[i] == 0)
                {
                    continue;
                }
                else if (nat.slots[i] == key1)
                {
                    index1 = i;
                }
                else if (nat.slots[i] == key2)
                {
                    index2 = i;
                }
                else if (nat.slots[i] == key3)
                {
                    index3 = i;
                }
                else if (nat.slots[i] == key4)
                {
                    index4 = i;
                }
                else
                {
                    break;
                }
            }

            Assert.AreEqual(nat.values[index1], nat.Get("one"));
            Assert.AreEqual(nat.values[index2], nat.Get("two"));
            Assert.AreEqual(nat.values[index3], nat.Get("three"));
            Assert.AreEqual(nat.values[index4], nat.Get("four"));
        }
コード例 #9
0
        public void TestA_Put_5()
        {
            NativeDictionary <int> nat = new NativeDictionary <int>(16);

            nat.Put("1", 1);
            nat.Put("11", 2);
            nat.Put("111", 3);

            Assert.AreEqual(1, nat.Get("1"));
            Assert.AreEqual(2, nat.Get("11"));
            Assert.AreEqual(3, nat.Get("111"));
        }
コード例 #10
0
        public void TestC_Put_2()
        {
            int    size = 16;
            BitBag bb1  = new BitBag(1);
            BitBag bb2  = new BitBag(2);
            NativeDictionary <BitBag> nat = new NativeDictionary <BitBag>(size);

            nat.Put("key1", bb1);
            nat.Put("key2", bb2);

            Assert.AreEqual(bb1, nat.Get("key1"));
            Assert.AreEqual(bb2, nat.Get("key2"));
        }
コード例 #11
0
        public static void TestsNativeDictionaryPut()
        {
            var testDict = new NativeDictionary <int>(3);

            Assert.AreEqual(3, testDict.size);
            testDict.Put("one", 1);
            Assert.AreEqual("one", testDict.slots[1]);
            Assert.AreEqual(1, testDict.values[1]);
            testDict.Put("three", 3);
            Assert.AreEqual("three", testDict.slots[2]);
            Assert.AreEqual(3, testDict.values[2]);
            testDict.Put("one", 2);
            Assert.AreEqual("one", testDict.slots[1]);
            Assert.AreEqual(2, testDict.values[1]);
        }
コード例 #12
0
        public void TestB_Put_4()
        {
            NativeDictionary <string> nat = new NativeDictionary <string>(16);

            nat.Put("one", "1");
            nat.Put("two", "5");
            nat.Put("three", "12");
            nat.Put("four", "20");
            nat.Put("five", "34");

            Assert.AreEqual("1", nat.Get("one"));
            Assert.AreEqual("5", nat.Get("two"));
            Assert.AreEqual("12", nat.Get("three"));
            Assert.AreEqual("20", nat.Get("four"));
            Assert.AreEqual("34", nat.Get("five"));
        }
コード例 #13
0
        public void TestA_IsKey_6()
        {
            int size = 4;

            NativeDictionary <int> nat = new NativeDictionary <int>(size);

            nat.Put("one", 1);
            nat.Put("two", 2);
            nat.Put("three", 3);
            nat.Put("four", 4);

            Assert.AreEqual(true, nat.IsKey("one"));
            Assert.AreEqual(true, nat.IsKey("two"));
            Assert.AreEqual(true, nat.IsKey("three"));
            Assert.AreEqual(true, nat.IsKey("four"));
        }
コード例 #14
0
        public void TestA_Put_4()
        {
            NativeDictionary <int> nat = new NativeDictionary <int>(16);

            nat.Put("one", 1);
            nat.Put("two", 5);
            nat.Put("three", 12);
            nat.Put("four", 20);
            nat.Put("five", 34);

            Assert.AreEqual(1, nat.Get("one"));
            Assert.AreEqual(5, nat.Get("two"));
            Assert.AreEqual(12, nat.Get("three"));
            Assert.AreEqual(20, nat.Get("four"));
            Assert.AreEqual(34, nat.Get("five"));
        }
コード例 #15
0
        public void TestB_Put_2()
        {
            NativeDictionary <string> nat = new NativeDictionary <string>(16);

            nat.Put("one", "pet");
            nat.Put("two", "fat");
            nat.Put("three", "bat");
            nat.Put("four", "dot");
            nat.Put("five", "bed");

            Assert.AreEqual("pet", nat.Get("one"));
            Assert.AreEqual("fat", nat.Get("two"));
            Assert.AreEqual("bat", nat.Get("three"));
            Assert.AreEqual("dot", nat.Get("four"));
            Assert.AreEqual("bed", nat.Get("five"));
        }
コード例 #16
0
        public void Put()
        {
            NativeDictionary <int> dict = new NativeDictionary <int>(5);

            dict.Put("1", 1);
            Assert.True(dict.Get("1") == 1);

            dict.Put("1", -1);
            Assert.True(dict.Get("1") == -1);

            dict.Put("2", 2);
            Assert.True(dict.Get("1") == -1);
            Assert.True(dict.Get("2") == 2);

            Assert.True(dict.Get("3") == 0);
        }
コード例 #17
0
        public void Get_if_Dict_Has_Key()
        {
            NativeDictionary <string> clients = new NativeDictionary <string>(6);

            string[] names      = { "Laura", "Patrik", "Stuart", "Leonard", "Delcin" };
            string[] categories = { "New", "Regular", "VIP", "Deptor" };

            Console.WriteLine("=== LOG ===");


            Console.WriteLine("{0}\n{1}\n{2}\n{3}\n{4}",
                              clients.HashFun(names[0]),
                              clients.HashFun(names[1]),
                              clients.HashFun(names[2]),
                              clients.HashFun(names[3]),
                              clients.HashFun(names[4]));

            clients.Put(names[0], categories[1]);
            clients.Put(names[1], categories[0]);
            clients.Put(names[2], categories[3]);
            clients.Put(names[3], categories[2]);
            clients.Put(names[4], categories[1]);

            Console.WriteLine("{0}\n{1}\n{2}\n{3}\n{4}",
                              clients.Get(names[0]),
                              clients.Get(names[1]),
                              clients.Get(names[2]),
                              clients.Get(names[3]),
                              clients.Get(names[4]));
            Console.WriteLine("=== LOG END ===");

            string actualValue    = clients.Get(names[0]);
            string actualValue2   = clients.Get(names[1]);
            string actualValue3   = clients.Get(names[2]);
            string expectedValue4 = "VIP";
            string actualValue4   = clients.Get(names[3]);
            string expectedValue5 = "Regular";
            string actualValue5   = clients.Get(names[4]);

            Assert.IsNull(actualValue);
            Assert.IsNull(actualValue2);
            Assert.IsNull(actualValue3);
            Assert.AreEqual(expectedValue4, actualValue4);
            Assert.AreEqual(expectedValue5, actualValue5);
            Assert.IsNull(clients.Get("Hue"));
            Assert.IsTrue(clients.size == 6);
        }
コード例 #18
0
        public void TestB_Put_1()
        {
            NativeDictionary <string> nat = new NativeDictionary <string>(16);

            nat.Put("one", "1");

            Assert.AreEqual("1", nat.Get("one"));
        }
コード例 #19
0
        public void TestA_Put_1()
        {
            NativeDictionary <int> nat = new NativeDictionary <int>(16);

            nat.Put("one", 1);

            Assert.AreEqual(1, nat.Get("one"));
        }
コード例 #20
0
        public void Test_IsKey_WhenNoSuchKey()
        {
            var dictionary = new NativeDictionary <int>(10);

            dictionary.Put("b", 2);

            var result = dictionary.IsKey("a");

            Assert.AreEqual(false, result);
        }
コード例 #21
0
        public void IsKeyTest()
        {
            NativeDictionary <string> profs = new NativeDictionary <string>(5);
            string key   = "Dmitry";
            string value = "engineer";

            profs.Put(key, value);

            Assert.IsTrue(profs.IsKey(key));
            Assert.IsFalse(profs.IsKey("football player"));
        }
コード例 #22
0
        public void TestA_IsKey_4()
        {
            int size = 4;

            NativeDictionary <int> nat = new NativeDictionary <int>(size);

            nat.Put(" ", 1);

            Assert.AreEqual(false, nat.IsKey("one"));
            Assert.AreEqual(false, nat.IsKey("key"));
        }
コード例 #23
0
        public void TestA_IsKey_5()
        {
            int size = 16;

            NativeDictionary <int> nat = new NativeDictionary <int>(size);

            nat.Put("one", 1);

            Assert.AreEqual(false, nat.IsKey(""));
            Assert.AreEqual(false, nat.IsKey(null));
        }
コード例 #24
0
        public static void TestsNativeDictionaryGet()
        {
            var testDict = new NativeDictionary <int>(3);

            Assert.AreEqual(3, testDict.size);
            testDict.Put("one", 1);
            Assert.AreEqual("one", testDict.slots[1]);
            Assert.AreEqual(1, testDict.values[1]);

            Assert.AreEqual(1, testDict.Get("one"));
            Assert.AreEqual(default(int), testDict.Get("two"));
        }
コード例 #25
0
        public static void TestsNativeDictionaryIsKey()
        {
            var testDict = new NativeDictionary <int>(3);

            Assert.AreEqual(3, testDict.size);
            testDict.Put("one", 1);
            Assert.AreEqual("one", testDict.slots[1]);
            Assert.AreEqual(1, testDict.values[1]);

            Assert.IsTrue(testDict.IsKey("one"));
            Assert.IsFalse(testDict.IsKey("two"));
        }
コード例 #26
0
        public void TestB_Put_6()
        {
            int size = 16;
            NativeDictionary <string> nat = new NativeDictionary <string>(size);

            nat.Put(null, "1");

            for (int i = 0; i < size; i++)
            {
                Assert.AreEqual(true, nat.values[i] == null);
            }
        }
コード例 #27
0
        public void TestA_IsKey_8()
        {
            int    size = 16;
            string key1 = "";

            NativeDictionary <int> nat = new NativeDictionary <int>(size);

            Assert.AreEqual(false, nat.IsKey(""));

            nat.Put(key1, 1);

            Assert.AreEqual(true, nat.IsKey(""));
        }
コード例 #28
0
        public void Test1_FirstStartTest()
        {
            int size = 16;

            string key1  = "key1";
            int    item1 = 1;

            string key2  = "key2";
            string item2 = "1";

            string key3  = "key3";
            BitBag item3 = new BitBag(1);

            string  key4  = "key4";
            BitBagE item4 = new BitBagE(1);

            NativeDictionary <int>    nat1 = new NativeDictionary <int>(size);
            NativeDictionary <string> nat2 = new NativeDictionary <string>(size);
            NativeDictionary <BitBag> nat3 = new NativeDictionary <BitBag>(size);

            nat1.Put(key1, item1);
            nat2.Put(key2, item2);
            nat3.Put(key3, item3);
            nat3.Put(key4, item4);

            Assert.AreEqual(true, nat1.IsKey(key1));
            Assert.AreEqual(item1, nat1.Get(key1));

            Assert.AreEqual(true, nat2.IsKey(key2));
            Assert.AreEqual(item2, nat2.Get(key2));

            Assert.AreEqual(true, nat3.IsKey(key3));
            Assert.AreEqual(item3, nat3.Get(key3));
            Assert.AreEqual(true, nat3.IsKey(key4));
            Assert.AreEqual(item4, nat3.Get(key4));
        }
コード例 #29
0
        public void TestA_IsKey_2()
        {
            int size = 16;

            NativeDictionary <int> nat = new NativeDictionary <int>(size);

            for (int i = 0; i < size; i++)
            {
                nat.Put("key" + i, i);
            }

            for (int i = 0; i < size; i++)
            {
                Assert.AreEqual(true, nat.IsKey("key" + 1));
            }
        }
コード例 #30
0
        public void TestA_IsKey_7()
        {
            int size = 1;

            NativeDictionary <int> nat1 = new NativeDictionary <int>(size);
            NativeDictionary <int> nat2 = new NativeDictionary <int>(size);
            NativeDictionary <int> nat3 = new NativeDictionary <int>(size);

            nat1.Put("one", 1);
            nat2.Put("two", 1);
            nat3.Put("four", 1);

            Assert.AreEqual(true, nat1.IsKey("one"));
            Assert.AreEqual(true, nat2.IsKey("two"));
            Assert.AreEqual(true, nat3.IsKey("four"));
        }