-
Notifications
You must be signed in to change notification settings - Fork 0
/
testPolyEval.py
56 lines (56 loc) · 1.58 KB
/
testPolyEval.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from unittest import TestCase,main
from polyEval import polyEval1, polyEval2
from random import randint
class testPoly(TestCase):
def testGen1(self):
k, trueSig = 1, True
while k <= 10:
A = [1 for i in range(k)]
x = randint(2,10)
c = polyEval1(A,x)
trueSig = trueSig and (c == int((x**k-1)/(x-1)))
k = k + 1
self.assertTrue(trueSig)
def testSpecific1(self):
A = [1,-2,1]
x = 1
self.assertEqual(polyEval1(A,x),0)
def testSpecific2(self):
A = [1,-2,1]
x = (-1)
self.assertEqual(polyEval1(A,x),4)
def testSpecific3(self):
A = [1,-6,9]
x = 3
self.assertEqual(polyEval1(A,x),0)
def testSpecific4(self):
A = [1,-6,9]
x = 15
self.assertEqual(polyEval1(A,x),144)
def testGen2(self):
k, trueSig = 1, True
while k <= 10:
A = [1 for i in range(k)]
x = randint(2,10)
c = polyEval2(A,x)
trueSig = trueSig and (c == int((x**k-1)/(x-1)))
k = k + 1
self.assertTrue(trueSig)
def testSpecific5(self):
A = [1,-2,1]
x = 1
self.assertEqual(polyEval2(A,x),0)
def testSpecific6(self):
A = [1,-2,1]
x = (-1)
self.assertEqual(polyEval2(A,x),4)
def testSpecific7(self):
A = [1,-6,9]
x = 3
self.assertEqual(polyEval2(A,x),0)
def testSpecific8(self):
A = [1,-6,9]
x = 15
self.assertEqual(polyEval2(A,x),144)
if __name__ == '__main__':
main()