示例#1
0
        public void TestConstructorWithValidFile()
        {
            InputFile file = InputFile.GetInputFile(TestFileNameContents.Example2FileName);

            //If no exception is thrown, this test passes
            Assert.IsTrue(true);
        }
示例#2
0
        public void TestGetWordAtIndexWithValidIndex()
        {
            int       testIndex = 3;
            InputFile file      = InputFile.GetInputFile(TestFileNameContents.Example2FileName);

            Assert.AreEqual("plan", file.GetWordAtIndex(testIndex));
        }
示例#3
0
        public void TestGetWordsInRangeWithValidRangeThatExtendsPastEndOfTestFile()
        {
            int       testRange      = 6;
            int       testStartIndex = 19;
            InputFile file           = InputFile.GetInputFile(TestFileNameContents.Example2FileName);

            string[] words = file.GetWordsInRange(testStartIndex, testRange);
            Assert.AreEqual(2, words.Length);
            Assert.AreEqual("canal", words[0]);
            Assert.AreEqual("panama", words[1]);
        }
示例#4
0
        public void TestGetWordsInRangeWithValidRange()
        {
            int       testRange      = 2;
            int       testStartIndex = 0;
            InputFile file           = InputFile.GetInputFile(TestFileNameContents.Example2FileName);

            string[] words = file.GetWordsInRange(testStartIndex, testRange);
            Assert.AreEqual(testRange, words.Length);
            Assert.AreEqual("the", words[0]);
            Assert.AreEqual("man", words[1]);
        }
示例#5
0
 public void TestConstructorWithInvalidFile()
 {
     try
     {
         InputFile file = InputFile.GetInputFile(TestFileNameContents.MissingFileName);
     }
     catch (FileNotFoundException e)
     {
         Assert.AreEqual(ErrorMessageConstants.InvalidFileArgumentErrorMessage, e.Message);
     }
 }
示例#6
0
        public void TestGetWordAtIndexWithInvalidIndex()
        {
            int       testIndex = 3;
            InputFile file      = InputFile.GetInputFile(TestFileNameContents.Example2FileName);

            try
            {
                file.GetWordAtIndex(testIndex);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(ErrorMessageConstants.InvalidInputFileIndexErrorMessage, e.Message);
            }
        }
示例#7
0
        public void TestGetWordsInRangeWithZeroRange()
        {
            int       testRange      = 0;
            int       testStartIndex = 0;
            InputFile file           = InputFile.GetInputFile(TestFileNameContents.Example2FileName);

            try
            {
                file.GetWordsInRange(testStartIndex, testRange);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(ErrorMessageConstants.InvalidInputFileIndexErrorMessage, e.Message);
            }
        }
示例#8
0
        public void TestGetWordsInRangeWithStartIndexGreaterThanNumberOfWordsInInputFile()
        {
            int       testRange             = 2;
            int       testStartIndexInvalid = 5000;
            InputFile file = InputFile.GetInputFile(TestFileNameContents.Example2FileName);

            try
            {
                file.GetWordsInRange(testStartIndexInvalid, testRange);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(ErrorMessageConstants.InvalidInputFileIndexErrorMessage, e.Message);
            }
        }
示例#9
0
        public void TestGetWordCountWithEmptyFile()
        {
            InputFile file = InputFile.GetInputFile(TestFileNameContents.EmptyFileName);

            Assert.AreEqual(0, file.GetWordCount());
        }
示例#10
0
        public void TestGetWordCount()
        {
            InputFile file = InputFile.GetInputFile(TestFileNameContents.Example2FileName);

            Assert.AreEqual(21, file.GetWordCount());
        }