예제 #1
0
        public void DelimiterOnlyShouldResultInZero()
        {
            const string testInput      = ",";
            var          expectedResult = new StringCalculationResult(0, "0+0");

            RunTest(testInput, expectedResult);
        }
        public void CalculatorSupportsMultiplication()
        {
            const string testInput       = "5,(*)5";
            var          expectedResults = new StringCalculationResult(5 * 5, "5*5");

            RunTest(testInput, expectedResults);
        }
        public void MultiCharacterDelimitersAreNotSupportedWithoutBrackets()
        {
            var testInput      = $"//abc\n1,abc,1000{Environment.NewLine}1001,60abc10";
            var expectedResult = new StringCalculationResult(1001, "1+0+1000+0+0");

            RunTest(testInput, expectedResult);
        }
        public void EnvironmentNewLineCharacterSupported()
        {
            var testInput      = $"1{Environment.NewLine}5";
            var expectedResult = new StringCalculationResult(6, "1+5");

            RunTest(testInput, expectedResult);
        }
        public void NewLineCharacterSupported()
        {
            const string testInput      = "4\n9";
            var          expectedResult = new StringCalculationResult(13, "4+9");

            RunTest(testInput, expectedResult);
        }
        public void LeadingAdditionIgnoresImplicitZeroToBeginningOfFormula()
        {
            const string testInput       = "(+)5,(/)5";
            var          expectedResults = new StringCalculationResult(5 / 5, "5/5");

            RunTest(testInput, expectedResults);
        }
        public void LeadingDivisionAddsImplicitZeroToBeginningOfFormula()
        {
            const string testInput       = "(/)5,(/)5";
            var          expectedResults = new StringCalculationResult((0 / 5) / 5, "0/5/5");

            RunTest(testInput, expectedResults);
        }
        public void AllowNumericCustomDelimiter()
        {
            var testInput      = $"//5\n1,5,1000{Environment.NewLine}1001,60510";
            var expectedResult = new StringCalculationResult(1071, "1+0+0+1000+0+60+10");

            RunTest(testInput, expectedResult);
        }
예제 #9
0
        public void DelimiterAndNumberShouldReturnTheNumber()
        {
            const string testInput      = ",5";
            var          expectedResult = new StringCalculationResult(5, "0+5");

            RunTest(testInput, expectedResult);
        }
        public void CalculatorSupportsExplicitAddition()
        {
            const string testInput       = "5,(+)5";
            var          expectedResults = new StringCalculationResult(5 + 5, "5+5");

            RunTest(testInput, expectedResults);
        }
예제 #11
0
        public void CalculatorSupportsManyValues()
        {
            var testInput      = "1,2,3,4,5,6,7,8,9,10,11,12";
            var expectedResult = new StringCalculationResult(78, "1+2+3+4+5+6+7+8+9+10+11+12");

            RunTest(testInput, expectedResult);
        }
예제 #12
0
        public void TwoNumericOperandsShouldBeAddedTogether()
        {
            const string testInput      = "3,21";
            var          expectedResult = new StringCalculationResult(24, "3+21");

            RunTest(testInput, expectedResult);
        }
예제 #13
0
        public void EmptyStringShouldResultInZero()
        {
            var testInput      = string.Empty;
            var expectedResult = new StringCalculationResult(0, "0+0");

            RunTest(testInput, expectedResult);
        }
예제 #14
0
        public void StringAndNumberOperandsShouldReturnNumber()
        {
            const string testInput      = "hrtr,21";
            var          expectedResult = new StringCalculationResult(21, "0+21");

            RunTest(testInput, expectedResult);
        }
예제 #15
0
        public void NumberAndStringOperandsShouldReturnNumber()
        {
            const string testInput      = "22,fdhreg";
            var          expectedResult = new StringCalculationResult(22, "22+0");

            RunTest(testInput, expectedResult);
        }
예제 #16
0
        public void StringOperandsShouldBeIgnoredAsZero()
        {
            const string testInput      = "fdhreg";
            var          expectedResult = new StringCalculationResult(0, "0+0");

            RunTest(testInput, expectedResult);
        }
        public void TextNewLineCharacterSupported()
        {
            const string testInput      = "2\\n8";
            var          expectedResult = new StringCalculationResult(10, "2+8");

            RunTest(testInput, expectedResult);
        }
        public void CalculatorSupportsSubtraction()
        {
            const string testInput       = "5,(-)5";
            var          expectedResults = new StringCalculationResult(5 - 5, "5-5");

            RunTest(testInput, expectedResults);
        }
        public void AllowMultiCharCustomDelimiter()
        {
            var testInput      = $"//[abc]\n1abc5,1000{Environment.NewLine}1001abc5000";
            var expectedResult = new StringCalculationResult(1006, "1+5+1000+0+0");

            RunTest(testInput, expectedResult);
        }
        public void IgnoreValuesGreaterThanOneThousand()
        {
            const string testInput      = "1,5,1000,1001,5000,10";
            var          expectedResult = new StringCalculationResult(1016, "1+5+1000+0+0+10");

            RunTest(testInput, expectedResult);
        }
        public void AllowASingleCustomDelimiter()
        {
            var testInput      = $"//;\n1;5,1000{Environment.NewLine}1001,5000";
            var expectedResult = new StringCalculationResult(1006, "1+5+1000+0+0");

            RunTest(testInput, expectedResult);
        }
        public void CalculatorSupportsDivision()
        {
            const string testInput       = "5,(/)5";
            var          expectedResults = new StringCalculationResult(5 / 5, "5/5");

            RunTest(testInput, expectedResults);
        }
        public void AllTermsGreaterThanMaxValueShouldPassAsAllZero()
        {
            const string testInput      = "10000,5000,1001,5000";
            var          expectedResult = new StringCalculationResult(0, "0+0+0+0");

            RunTest(testInput, expectedResult);
        }
예제 #24
0
        public void NumberOnlyShouldReturnTheNumber()
        {
            // It's tempting to select a random value, but you lose control over what is being tested - and if you fail for specific values, your test may pass or fail randomly.
            // Better to implement regression tests for known bad states when identified.
            const string testInput      = "5";
            var          expectedResult = new StringCalculationResult(5, "5+0");

            RunTest(testInput, expectedResult);
        }