Ejemplo n.º 1
0
        public void Copy_To_Returns_Correct_Result()
        {
            TernaryTree <int> subject = TernaryTree <int> .Create(_keyValueCollection);

            KeyValuePair <string, int>[] actualResult = new KeyValuePair <string, int> [subject.Count];
            subject.CopyTo(actualResult, 0);
            Assert.That(actualResult, Is.EqualTo(_sortedKVPairs));
        }
Ejemplo n.º 2
0
        public void Keys_Returns_A_Sorted_Collection_Of_All_Keys()
        {
            TernaryTree <int> subject = TernaryTree <int> .Create(_keyValueDictionary);

            ICollection <string> actualResult = subject.Keys();

            Assert.That(actualResult, Is.EqualTo(_sortedKeys));
        }
Ejemplo n.º 3
0
        public void This_Int_Throws_IndexOutOfRangeException(int index)
        {
            TernaryTree <int> subject = TernaryTree <int> .Create(_keyValueCollection);

            Assert.Throws <IndexOutOfRangeException>(() =>
            {
                string actualResult = subject[index];
            });
        }
Ejemplo n.º 4
0
        public void Count_After_Consecutive_Calls_To_Remove()
        {
            TernaryTree <string> subject = TernaryTree <string> .Create(_keys);

            foreach (string key in _keys)
            {
                subject.Remove(key);
            }
            Assert.That(subject.Count, Is.EqualTo(0));
        }
Ejemplo n.º 5
0
        public void This_Int_Returns_Correct_Key()
        {
            TernaryTree <int> subject = TernaryTree <int> .Create(_keyValueDictionary);

            Assert.Multiple(() => {
                for (int i = 0; i < _sortedKeys.Length; i++)
                {
                    Assert.That(subject[i], Is.EqualTo(_sortedKeys[i]));
                }
            });
        }
Ejemplo n.º 6
0
        public void Enumerator_Returns_All_Elements_In_Order()
        {
            TernaryTree <int> subject = TernaryTree <int> .Create(_keyValueCollection);

            List <KeyValuePair <string, int> > actualResult = new List <KeyValuePair <string, int> >();

            foreach (KeyValuePair <string, int> kvPair in subject)
            {
                actualResult.Add(kvPair);
            }
            Assert.That(actualResult, Is.EqualTo(_sortedKeyValueCollection));
        }
Ejemplo n.º 7
0
        public void Tree_ContainsKey_All_Added_Keys()
        {
            TernaryTree <string> subject = TernaryTree <string> .Create(_keys);

            Assert.Multiple(() =>
            {
                foreach (string key in _keys)
                {
                    Assert.That(subject.ContainsKey(key));
                }
            });
        }
Ejemplo n.º 8
0
        public void Regex_Match_Test(string pattern, string[] matchingKeys, string[] nonMatchingKeys)
        {
            TernaryTree <int> subject = TernaryTree <int> .Create(matchingKeys);

            foreach (string nonMatchingKey in nonMatchingKeys)
            {
                subject.Add(nonMatchingKey);
            }
            HashSet <string> actualResult = new HashSet <string>(subject.Match(pattern));

            Assert.Multiple(() =>
            {
                Assert.That(subject.Count, Is.EqualTo(matchingKeys.Length + nonMatchingKeys.Length));
                Assert.That(actualResult.Count, Is.EqualTo(matchingKeys.Length));
                foreach (string key in matchingKeys)
                {
                    Assert.That(actualResult.Contains(key));
                }
            });
        }
Ejemplo n.º 9
0
        public void Setup(int numKeys)
        {
            foreach (string tenant in tenants)
            {
                Console.Write($"Generating {numKeys / 5} keys for tenant {tenant}.  ");
                Random random = new Random();
                startTime = DateTime.Now.Ticks;
                for (int i = 0; i < numKeys / 5; i++)
                {
                    int    docType = random.Next(0, docTypes.Length);
                    string key     = $"{tenant}-{docTypes[docType]}-{Guid.NewGuid()}";
                    keys.Add(key);
                }
                endTime = DateTime.Now.Ticks;
                Console.Write($"Took {(endTime - startTime) / 10000} ms." + Environment.NewLine);
            }

            Console.Write(Environment.NewLine + $"Adding {numKeys} keys to TernaryTree.  ");
            startTime = DateTime.Now.Ticks;
            subject   = TernaryTree <int> .Create(keys);

            endTime = DateTime.Now.Ticks;
            Console.WriteLine($"Took {(endTime - startTime) / 10000} ms." + Environment.NewLine + Environment.NewLine);
        }
Ejemplo n.º 10
0
        public void Create_From_IDictionary_String_Int()
        {
            TernaryTree <int> subject = TernaryTree <int> .Create(_keyValueDictionary);

            Assert.That(subject.Count, Is.EqualTo(_keyValueDictionary.Count));
        }
Ejemplo n.º 11
0
        public void Create_From_ICollection_KVPair()
        {
            TernaryTree <int> subject = TernaryTree <int> .Create(_keyValueCollection);

            Assert.That(subject.Count, Is.EqualTo(_keyValueCollection.Count));
        }
Ejemplo n.º 12
0
        public void Create_From_ICollection_String()
        {
            TernaryTree <int> subject = TernaryTree <int> .Create(_keys);

            Assert.That(subject.Count, Is.EqualTo(_keys.Length));
        }
Ejemplo n.º 13
0
        public void Contains_Returns_False_For_Invalid_Key()
        {
            TernaryTree <string> subject = TernaryTree <string> .Create(_keys);

            Assert.IsFalse(subject.Contains("invalid key"));
        }