Exemple #1
0
        public void Adding10000RandomKeysAndRemovingHalfWorks()
        {
            var randomKeys = Keygenerator.GenerateKeys(49, 20, '0', 'z', 100000);

            var searchDictionary = new SearchDictionary <int>();

            foreach (var randomKey in randomKeys)
            {
                searchDictionary.Add(randomKey, 0);
            }

            var i = 0;

            foreach (var randomKey in randomKeys)
            {
                if (i % 2 == 0)
                {
                    Assert.IsTrue(searchDictionary.Remove(randomKey), $"RemoveKey(\"{randomKey}\"");
                }

                i++;
            }

            i = 0;
            foreach (var randomKey in randomKeys)
            {
                Assert.AreEqual(i % 2 != 0, searchDictionary.ContainsKey(randomKey), $"ContainsKey(\"{randomKey}\"");
                i++;
            }

            Assert.AreEqual(randomKeys.Count / 2, searchDictionary.Count);
        }
Exemple #2
0
        public void OptimizeDoesNotDestroyTheTree()
        {
            var randomKeys = Keygenerator.GenerateKeys(57, 20, '0', 'z', 10000);

            var searchDictionary = new SearchDictionary <int>();

            foreach (var ranomKey in randomKeys)
            {
                searchDictionary.Add(ranomKey, 0);
            }

            foreach (var randomKey in randomKeys)
            {
                Assert.IsTrue(searchDictionary.ContainsKey(randomKey), $"ContainsKey(\"{randomKey}\"");
            }
        }
Exemple #3
0
        public void Adding10000RandomKeysWork()
        {
            var randomKeys = Keygenerator.GenerateKeys(42, 20, '0', 'z', 10000);

            var searchDictionary = new SearchDictionary <int>();

            foreach (var randomKey in randomKeys)
            {
                searchDictionary.Add(randomKey, 0);
            }

            Assert.AreEqual(randomKeys.Count, searchDictionary.Count);
            foreach (var randomKey in randomKeys)
            {
                Assert.IsTrue(searchDictionary.ContainsKey(randomKey));
            }
        }
Exemple #4
0
        public void Adding10000RandomKeysAndStartsWithFindsRandomKeysWork()
        {
            var randomKeys = Keygenerator.GenerateKeys(57, 20, '0', 'z', 10000);
            var random     = new Random(57);

            var searchDictionary = new SearchDictionary <string>();

            foreach (var randomKey in randomKeys)
            {
                searchDictionary.Add(randomKey, randomKey);
            }

            foreach (var randomKey in randomKeys)
            {
                var length     = random.Next(1, randomKey.Length + 1);
                var startOfKey = randomKey.Substring(0, length);

                var foundValues  = searchDictionary.StartsWith(startOfKey).OrderBy(value => value).ToArray();
                var actualValues = randomKeys.Where(key => key.StartsWith(startOfKey)).OrderBy(value => value).ToArray();

                CollectionAssert.AreEqual(foundValues, actualValues);
            }
        }