OK test need to make r* operations

This commit is contained in:
Lafrite 2014-02-21 18:02:50 +01:00
parent 6509e0164a
commit 88597369ea

View File

@ -15,39 +15,75 @@ class TestFraction(unittest.TestCase):
Fraction(4,5), \ Fraction(4,5), \
Fraction(-1, 3), \ Fraction(-1, 3), \
Fraction(1,-3), \ Fraction(1,-3), \
Fraction(0,2), \
1, 1,
] ]
def test_add(self): def test_add(self):
ans = [[Fraction(2, 3), 1, Fraction(17, 15), 0, 0, Fraction(1,3), Fraction(4,3)], \ ans = [[Fraction(2, 3), 1, Fraction(17, 15), 0, 0, Fraction(4,3)], \
[Fraction(4,3), Fraction(5,3), Fraction(9,3), Fraction(2,3), Fraction(2,3), 1, 0] \ [Fraction(4,3), Fraction(5,3), Fraction(9,3), Fraction(2,3), Fraction(2,3), 0] \
] ]
for (i, f1) in enumerate(self.listFrom): for (i, f1) in enumerate(self.listFrom):
for (j, f2) in enumerate(self.listAgainst): for (j, f2) in enumerate(self.listAgainst):
res = f1 + f2 res = f1 + f2
print(res)
self.assertAlmostEqual(res[-1], ans[i][j])
#print("-----------")
#print("f1 : ", f1)
#print("f2 : ", f2)
#print(res)
def test_radd(self): self.assertEqual(res[-1], ans[i][j])
pass
def test_sub(self): def test_sub(self):
pass ans = [[0, Fraction(-1,3), Fraction(-7, 15), Fraction(2,3), Fraction(2,3), Fraction(-2,3)], \
[Fraction(2,3), Fraction(1,3), Fraction(1,5), Fraction(4,3), Fraction(4,3), 0] \
]
def test_rsub(self): for (i, f1) in enumerate(self.listFrom):
pass for (j, f2) in enumerate(self.listAgainst):
res = f1 - f2
#print("-----------")
#print("f1 : ", f1)
#print("f2 : ", f2)
#print(res)
self.assertEqual(res[-1], ans[i][j])
def test_neg(self): def test_neg(self):
pass pass
def test_mul(self): def test_mul(self):
pass ans = [[Fraction(1, 9), Fraction(2,9), Fraction(4, 15), Fraction(-1,9), Fraction(-1,9), Fraction(1,3)], \
[ Fraction(1,3), Fraction(2,3), Fraction(4,5), Fraction(-1, 3), Fraction(1,-3), 1] \
]
for (i, f1) in enumerate(self.listFrom):
for (j, f2) in enumerate(self.listAgainst):
res = f1 * f2
#print("-----------")
#print("f1 : ", f1)
#print("f2 : ", f2)
#print(res)
self.assertEqual(res[-1], ans[i][j])
def test_truediv(self): def test_truediv(self):
pass ans = [[1, Fraction(1,2), Fraction(5, 12), -1, -1, Fraction(1,3)], \
[3, Fraction(3,2), Fraction(5,4), -3, -3, 1] \
]
for (i, f1) in enumerate(self.listFrom):
for (j, f2) in enumerate(self.listAgainst):
res = f1 / f2
#print("-----------")
#print("f1 : ", f1)
#print("f2 : ", f2)
#print(res)
self.assertEqual(res[-1], ans[i][j])
def test_lt(self): def test_lt(self):
pass pass