public void Test_SortedTextFile()
        {
            string        dir      = Directory.GetCurrentDirectory();
            var           fullpath = Path.Combine(dir, @"ExampleFiles\ValidTxtFile.txt"); //Hi my name is Baloo and i live in the djungle. Yesterday I met a new friend, his name is Mowgli.
            List <string> expected = new List <string>
            {
                "a",
                "and",
                "baloo",
                "djungle",
                "friend",
                "hi",
                "his",
                "i",
                "i",
                "in",
                "is",
                "is",
                "live",
                "met",
                "mowgli",
                "my",
                "name",
                "name",
                "new",
                "the",
                "yesterday"
            };

            var actual = new TxtFile(fullpath);

            actual.SortWords();
            Assert.AreEqual(expected, actual.WordsSorted);
        }
        public void TestSaveASSorted()
        {
            string dir      = Directory.GetCurrentDirectory();
            var    fullpath = Path.Combine(dir, @"ExampleFiles\ValidTxtFile.txt");
            var    result   = new TxtFile(fullpath);

            result.SortWords();
            result.SaveSortedFile();
        }
예제 #3
0
        public void SaveSortedFile_DoesSaveFile()
        {
            var fullpath = Path.Combine(Directory.GetCurrentDirectory(), @"ExampleFiles\ValidTxtFile.txt");
            var result   = new TxtFile(fullpath);

            result.SortWords();
            result.SaveSortedFile();
            bool fileExist = File.Exists(Path.Combine(Directory.GetCurrentDirectory(), @"ExampleFiles\ValidTxtFile_SortedWords.txt"));

            Assert.IsTrue(fileExist);
        }
예제 #4
0
        public void SortWords__SameNumberOfWordsInSortedWordsAndUnsortedWords()
        {
            //Arrange
            var fullpath = Path.Combine(Directory.GetCurrentDirectory(), @"ExampleFiles\ValidTxtFile.txt");
            var sut      = new TxtFile(fullpath);

            //Act
            sut.SortWords();

            //Assert
            Assert.AreEqual(sut.WordsSorted.Count, sut.WordsUnsorted.Count);
        }
예제 #5
0
        public void SearchAndSort_SearchSortThenSearchAgain_SearchResultIsTheSame()
        {
            // Arrange
            var file      = new TxtFile(Path.Combine(Directory.GetCurrentDirectory(), @"ExampleFiles\ValidTxtFile.txt"));
            int searchOne = file.Search("baloo");

            file.SortWords();
            int searchTwo = file.Search("baloo");

            // Assert
            Assert.AreEqual(searchOne, searchTwo);
        }
예제 #6
0
        public void SortWords_SortedWordsAndUnsortedWordsContainTheSameWords()
        {
            //Arrange
            var fullpath = Path.Combine(Directory.GetCurrentDirectory(), @"ExampleFiles\ValidTxtFile.txt");
            var sut      = new TxtFile(fullpath);

            //Act
            sut.SortWords();

            //Assert
            foreach (var word in sut.WordsSorted)
            {
                Assert.IsTrue(sut.WordsUnsorted.Contains(word));
            }
        }