diff --git a/pymath/fraction.py b/pymath/fraction.py index 6917bc5..f19e1a6 100644 --- a/pymath/fraction.py +++ b/pymath/fraction.py @@ -169,7 +169,8 @@ class Fraction(object): return number - self def __neg__(self): - return Fraction(-self._num,self._denom).simplify() + f = Fraction(-self._num, self._denom) + return [f] + f.simplify() def __mul__(self, other): steps = [] diff --git a/test/test_fraction.py b/test/test_fraction.py index 05963a1..78c4cdf 100644 --- a/test/test_fraction.py +++ b/test/test_fraction.py @@ -61,7 +61,19 @@ class TestFraction(unittest.TestCase): self.assertEqual(res, ans[i][j]) def test_neg(self): - pass + ans = [ Fraction(-1,3), \ + Fraction(-2,3), \ + Fraction(-4,5), \ + Fraction(1, 3), \ + Fraction(1,3), \ + -1 + ] + for (j, f) in enumerate(self.listAgainst): + res = -f + if type(res) == list: + self.assertEqual(res[-1], ans[j]) + else: + self.assertEqual(res, ans[j]) def test_mul(self): ans = [[Fraction(1, 9), Fraction(2,9), Fraction(4, 15), Fraction(-1,9), Fraction(-1,9), Fraction(1,3)], \