Esempio n. 1
0
        public void GivenLargeOfAmountOfSynonymLists_ShouldReturnExpectedResult()
        {
            var          subject = new Private.Thesaurus();
            const int    numberOfSynonymLists    = 10000;
            const int    numberOfSynonymsPerList = 5;
            const string controlWord             = "x";

            for (int i = 0; i < numberOfSynonymLists; i++)
            {
                var input = CreateRandomUniqueWords(numberOfSynonymsPerList).ToList();

                // Add a control word
                input.Add(controlWord);

                subject.AddSynonyms(input);
            }

            // Test that the control word given to all the random inputs are present
            // Since the control word is synonymous with all the random words,
            // the number of synonymous given should be equal to the total number of generated random word.
            var synonyms = subject.GetSynonyms(controlWord);
            int expectedNumberOfSynonyms = numberOfSynonymLists * numberOfSynonymsPerList;

            Assert.AreEqual(expectedNumberOfSynonyms, synonyms.Count());
        }
Esempio n. 2
0
        public void InputValidation()
        {
            var subject = new Private.Thesaurus();

            var inputWithNullValues      = new[] { "a", "b", null };
            var inputWithLessThan2Values = new[] { "a" };

            Assert.Throws <ArgumentNullException>(() => subject.AddSynonyms(null));
            Assert.Throws <ArgumentException>(() => subject.AddSynonyms(inputWithNullValues));
            Assert.Throws <ArgumentException>(() => subject.AddSynonyms(inputWithLessThan2Values));
            Assert.Throws <ArgumentNullException>(() => subject.GetSynonyms(null));
        }
Esempio n. 3
0
        public void GivenLargeListOfSynonyms_ShouldReturnExpectedResult()
        {
            var subject = new Private.Thesaurus();

            var input = CreateRandomUniqueWords(5000);

            subject.AddSynonyms(input);

            string first    = input.First();
            var    synonyms = subject.GetSynonyms(first);

            Assert.IsTrue(synonyms.All(s => input.Contains(s)));
        }
Esempio n. 4
0
        public void GivenSingleListOfSynonyms_ShouldReturnExpectedSynonyms()
        {
            var subject = new Private.Thesaurus();
            var input   = new[] { "a", "b", "c", "d" };

            subject.AddSynonyms(input);

            foreach (string word in input)
            {
                var otherWords = input.Except(new[] { word });
                var synonyms   = subject.GetSynonyms(word);
                Assert.IsTrue(
                    otherWords.All(synonyms.Contains),
                    "The list of synonyms should contain all the other given words");
            }
        }
Esempio n. 5
0
        public void MultipleOccurrences_ShouldReturnAllOccurrences()
        {
            var subject = new Private.Thesaurus();

            const string recurringWord = "a";

            var input1 = new[] { recurringWord, "b" };
            var input2 = new[] { recurringWord, "c" };
            var input3 = new[] { recurringWord, "d" };

            subject.AddSynonyms(input1);
            subject.AddSynonyms(input2);
            subject.AddSynonyms(input3);

            var recurringWordSynonyms = subject.GetSynonyms(recurringWord);

            Assert.IsTrue(recurringWordSynonyms.Contains("b"));
            Assert.IsTrue(recurringWordSynonyms.Contains("c"));
            Assert.IsTrue(recurringWordSynonyms.Contains("d"));
        }