public void InputReaderTest_InvalidInt()
        {
            MockInputReader reader = new MockInputReader();

            reader.AddInput("Not a number");
            int value = 0;

            Assert.False(reader.ReadInput(ref value));
        }
        public void InputReaderTest_ValidString()
        {
            const string    USER_INPUT = "This is my input string";
            MockInputReader reader     = new MockInputReader();

            reader.AddInput(USER_INPUT);
            string value = null;

            Assert.True(reader.ReadInput(ref value));
            Assert.Equal(USER_INPUT, value);
        }
        public void InputReaderTest_ValidInt()
        {
            const int       NUMBER_VALUE = -998976;
            MockInputReader reader       = new MockInputReader();

            reader.AddInput(NUMBER_VALUE.ToString());
            int value = 0;

            Assert.True(reader.ReadInput(ref value));
            Assert.Equal(NUMBER_VALUE, value);
        }
Ejemplo n.º 4
0
        public void ProgramTests_GetFilePathWithRetry()
        {
            const string    VALID_PATH  = @"C:\My\Fake\Filepath.ext";
            MockInputReader inputReader = new MockInputReader();

            inputReader.AddInput("fat-fingered input");
            inputReader.AddInput(@"Z:\Non\Existent\Path");
            inputReader.AddInput(VALID_PATH);

            string filepath = Program.GetFilePath(inputReader, filepath => filepath == VALID_PATH);

            Assert.Equal(VALID_PATH, filepath);
        }
Ejemplo n.º 5
0
        public void ProgramTests_GetFieldCountWithRetry()
        {
            const int       VALID_FIELD_COUNT = 4;
            MockInputReader inputReader       = new MockInputReader();

            inputReader.AddInput("fat-fingered input");
            inputReader.AddInput("9-");
            inputReader.AddInput("`1");
            inputReader.AddInput(VALID_FIELD_COUNT.ToString());

            int fieldCount = Program.GetFieldCount(inputReader);

            Assert.Equal(VALID_FIELD_COUNT, fieldCount);
        }
        public void MarkowCoderEncodeInput()
        {
            //given
            byte[]                input        = new byte[] { (byte)'A', (byte)'A', (byte)'B', (byte)'C', (byte)'A', (byte)'C', (byte)'D', (byte)'B', (byte)'A', (byte)'A' };
            MockInputReader       inputReader  = new MockInputReader(input);
            MockCoderOutputWriter outputWriter = new MockCoderOutputWriter();

            //when
            MarkowHuffmanCoderInterface markowHuffmanCoderInterface = new MarkowHuffmanCoderInterface(inputReader, outputWriter);

            markowHuffmanCoderInterface.Encode();

            //then
            outputWriter.AssertSize(12);
        }
Ejemplo n.º 7
0
        public void ProgramTests_GetExtensionWithRetry()
        {
            const string    VALID_EXTENSION = "csv";
            MockInputReader inputReader     = new MockInputReader();

            inputReader.AddInput("fat-fingered input");
            inputReader.AddInput("txt");
            inputReader.AddInput("doc");
            inputReader.AddInput("comma separated value");
            inputReader.AddInput(VALID_EXTENSION);

            string extension = Program.GetExtension(inputReader);

            Assert.Equal(VALID_EXTENSION, extension);
        }
        public void PairCoderEncodeInput()
        {
            //given
            byte[]                input        = new byte[] { (byte)'A', (byte)'B', (byte)'C', (byte)'A', (byte)'B', (byte)'D', (byte)'A', (byte)'B', (byte)'C', (byte)'A' };
            MockInputReader       inputReader  = new MockInputReader(input);
            MockCoderOutputWriter outputWriter = new MockCoderOutputWriter();

            //when
            PairHuffmanCoderInterface pairHuffmanCoderInterface = new PairHuffmanCoderInterface(inputReader, outputWriter);

            pairHuffmanCoderInterface.Encode();

            //then
            outputWriter.AssertEquals(new List <int>()
            {
                1, 1, 0, 1, 0, 1, 1, 0
            });
        }