public void SecondTermNegativeResolution_PerformedCorrectly() { var equation = "1+1"; var input = new List <string>() { "1", "+", "-", "1" }; A.CallTo(() => _mathsRuleResolver.Operator).Returns("+"); A.CallTo(() => _mathsRuleResolver.SecondTermNegativeResolution(input, 1)).Returns("2"); A.CallTo(() => _equationPartsIdentifier.FindParts(equation)).Returns(input); var response = _mathsResolver.ResolveSection(equation); response.Should().Be("+2"); A.CallTo(() => _equationPartsIdentifier.FindParts(equation)).MustHaveHappened(); A.CallTo(() => _mathsRuleResolver.SecondTermNegativeResolution(input, 1)).MustHaveHappened(); }
private List <string> ResolveGeneric(List <string> equationList, IMathsRuleResolver mathsRuleResolver) { while (equationList.Contains(mathsRuleResolver.Operator)) { var i = 0; while (i < equationList.Count) { if (equationList[i] == mathsRuleResolver.Operator) { if (FirstTermIsNegative(equationList, i) && SecondTermIsNegative(equationList, i)) { equationList[i - 2] = PrependPosSign(mathsRuleResolver.BothNegativeResolution(equationList, i)); equationList.RemoveRange(i - 1, 4); } else if (FirstTermIsNegative(equationList, i)) { equationList[i - 2] = PrependPosSign(mathsRuleResolver.FirstTermNegativeResolution(equationList, i)); equationList.RemoveRange(i - 1, 3); } else if (SecondTermIsNegative(equationList, i)) { equationList[i - 1] = PrependPosSign(mathsRuleResolver.SecondTermNegativeResolution(equationList, i)); equationList.RemoveRange(i, 3); } else if (i == 0) { equationList[i] = PrependPosSign(mathsRuleResolver.BothPositiveResolution(equationList, i)); equationList.RemoveRange(i + 1, 1); } else { equationList[i - 1] = PrependPosSign(mathsRuleResolver.BothPositiveResolution(equationList, i)); equationList.RemoveRange(i, 2); } i = equationList.Count; } i++; } } return(equationList); }