예제 #1
0
        protected void RunTest(string testInput, IReadOnlyList <Term> expectedResults)
        {
            var actualResults = _termExtractor.GetTerms(testInput).ToList();

            Assert.AreEqual(expectedResults.Count, actualResults.Count, "Term count mismatch");
            Assert.IsTrue(expectedResults.SequenceEqual(actualResults));
        }
예제 #2
0
        public IStringCalculationResult Calculate(string userInput, CancellationToken token)
        {
            var terms = _termExtractor.GetTerms(userInput)?.ToList() ?? new List <Term>();

            var result = new StringCalculationResult();

            foreach (var term in terms)
            {
                if (token.IsCancellationRequested)
                {
                    break;
                }

                // Enforce the max value, substituting an Emtpy Term in its place if it's too large.
                result.ProcessTerm(term.Value <= _maxValue ? term : Term.Empty);
            }

            if (!_allowNegativeNumbers && result.NegativeNumbers.Any())
            {
                throw new NegativeNumbersException("Negative numbers are not supported", result.NegativeNumbers.ToArray());
            }

            return(result);
        }