Skip to content

Commit fde73e7

Browse files
committed
Fixed FullText and polygon unit test, added FullText and Compare.Program unit test
1 parent 848506b commit fde73e7

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

cyaron/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@
1616
from .compare import Compare
1717
from .math import *
1818
from random import randint, randrange, uniform, choice, random
19-

cyaron/graders/fulltext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
def fulltext(content, std):
66
content_hash = hashlib.sha256(content).hexdigest()
77
std_hash = hashlib.sha256(std).hexdigest()
8-
return True, None if content_hash == std_hash else False, "Hash mismatch: read %s, expected %s" % (content_hash, std_hash)
8+
return (True, None) if content_hash == std_hash else (False, "Hash mismatch: read %s, expected %s" % (content_hash, std_hash))
99

cyaron/math.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ def miller_rabin_pass(a, s, d, n):
147147

148148

149149
#--- factor a number into primes and frequency----------------------------------------------------
150-
"""
151-
find the prime factors of n along with their frequencies. Example:
152-
153-
>>> factor(786456)
154-
[(2,3), (3,3), (11,1), (331,1)]
155-
156-
Source: Project Euler forums for problem #3
157-
"""
158150
def factor(n):
151+
"""
152+
find the prime factors of n along with their frequencies. Example:
153+
154+
>>> factor(786456)
155+
[(2,3), (3,3), (11,1), (331,1)]
156+
157+
Source: Project Euler forums for problem #3
158+
"""
159159
f, factors, prime_gaps = 1, [], [2, 4, 2, 4, 6, 2, 6, 4]
160160
if n < 1:
161161
return []
@@ -268,9 +268,9 @@ def exgcd(a,b):
268268
269269
Result is the tuple: (u, v, gcd(a,b)). Examples:
270270
271-
>>> bezout(7*3, 15*3)
271+
>>> exgcd(7*3, 15*3)
272272
(-2, 1, 3)
273-
>>> bezout(24157817, 39088169) #sequential Fibonacci numbers
273+
>>> exgcd(24157817, 39088169) #sequential Fibonacci numbers
274274
(-14930352, 9227465, 1)
275275
276276
Algorithm source: Pierre L. Douillet

cyaron/tests/compare_test.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,25 @@ def test_noipstyle_incorrect(self):
4242
Compare.output("test_another_incorrect.out", std=io)
4343

4444
result = out.getvalue().strip()
45-
self.assertEqual(result, "test_another_incorrect.out: !!!INCORRECT!!! On line 2 column 7, read 4, expected 3.")
45+
self.assertEqual(result, "test_another_incorrect.out: !!!INCORRECT!!! On line 2 column 7, read 4, expected 3.")
46+
47+
def test_fulltext_program(self):
48+
with open("correct.py", "w") as f:
49+
f.write("print(1)")
50+
51+
with open("incorrect.py", "w") as f:
52+
f.write("print(2)")
53+
54+
io = None
55+
with captured_output() as (out, err):
56+
io = IO("test_fulltext.in", "test_fulltext.out")
57+
58+
io.output_writeln("1")
59+
60+
with captured_output() as (out, err):
61+
Compare.program("python correct.py", "python incorrect.py", std=io, input=io, grader="FullText")
62+
63+
result = out.getvalue().strip()
64+
correct_text = 'python correct.py: Correct \npython incorrect.py: !!!INCORRECT!!! Hash mismatch: read 53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3, expected 4355a46b19d348dc2f57c046f8ef63d4538ebb936000f3c9ee954a27460dd865'
65+
self.assertEqual(result, correct_text)
66+

cyaron/tests/polygon_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_perimeter_area(self):
4040
self.assertEqual(poly.perimeter(),4)
4141
self.assertEqual(poly.area(),1)
4242
def test_simple_polygon(self):
43-
poly = Polygon.simple_polygon(Vector.random(300, [1000, 1000]))
43+
poly = Polygon.simple_polygon(Vector.random(300, [1000, 1000], 2))
4444
points = poly.points
4545
for i in range(0,len(points)):
4646
for j in range(i+2,len(points)):

0 commit comments

Comments
 (0)