public void OperatorPlus_SameDenominator_ReturnsValidResult() { var a = new Fraction(3, 5); var b = new Fraction(1, 5); var actual = a + b; actual.Numerator.ShouldBeEquivalentTo(4); actual.Denominator.ShouldBeEquivalentTo(5); }
public void OperatorPlus_DifferentDenominator_ReturnsValidResult(int aNum, int aDenom, int bNum, int bDenom, int expectedNum, int expectedDenom) { var a = new Fraction(aNum, aDenom); var b = new Fraction(bNum, bDenom); var expected = new Fraction(expectedNum, expectedDenom); var actual = a + b; actual.ShouldBeEquivalentTo(expected); }
public static Fraction operator -(Fraction a, Fraction b) { var bChangedSign = new Fraction(-1 * b.Sign * b.Numerator, b.Denominator); return a + bChangedSign; }