public void Subtract_AllowNegative_UpperBound1000_CorrectOutput()
        {
            List <int> list = input.ToList();

            _calService.AllowNegative = true;
            _calService.UpperBound    = 1000;
            float  expectedValue = 0;
            string expected      = "";

            for (int i = 0; i < list.Count; i++)
            {
                int item = list[i];
                if (i == 0)
                {
                    expectedValue = item;
                    expected      = $"{item}-";
                    continue;
                }
                if (item > 1000)
                {
                    expected += "0-";
                }
                else
                {
                    expectedValue -= item;
                    expected      += $"{item}-";
                }
            }
            expected = $"subtract: {expected.Remove(expected.Length-1, 1)} = {expectedValue}";
            Assert.IsTrue(_calService.Subtract(list).Equals(expected));
        }
Пример #2
0
        public void Calculate_Subtract_CorrectOutput()
        {
            ICalculateService calService = new CalculateService()
            {
                AllowNegative = true,
                UpperBound    = 2000
            };
            Calculator cal = new Calculator(
                new DelimiterService(),
                new ParseService(),
                calService
                );

            cal.SetStringSequence("//[*][!!][rrr]\\n11rrr22*-33!!44");
            int[] numbers = { 11, 22, -33, 44 };

            string expectedValue = (11 - 22 - (-33) - 44).ToString();
            string value         = cal.Calculate(Calculator.CalculateOperation.SUBSTRACT);

            Assert.IsTrue(value.Contains(expectedValue));
            Assert.IsTrue(value.Equals(calService.Subtract(numbers.ToList())));
        }