-
Notifications
You must be signed in to change notification settings - Fork 0
/
bounceTest.py
67 lines (57 loc) · 1.47 KB
/
bounceTest.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
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: latin-1 -*-
from io import StringIO
import sys
import Uppgift3
#import __main__ as main
import __main__
def testBounce(bounceFkn, printName, num, correctOutput):
print("Testar "+printName+"("+str(num)+")...",)
oldStdOut = sys.stdout
sys.stdout = StringIO()
#main.bounce(num)
bounceFkn(num)
outString = sys.stdout.getvalue()
sys.stdout = oldStdOut
if outString==correctOutput:
print("funkar!")
else:
print("funkar inte!")
print("Testresultat:")
print(outString)
print("R�tt resultat:")
print(correctOutput)
##def testBounce2():
## bounceOutput = '0 5 4 3 2 1 0 1 2 3 4 5'
## oldStdOut = sys.stdout
## sys.stdout = StringIO.StringIO()
##
## try:
## main.bounce2(0)
## main.bounce2(5)
## except AttributeError:
## sys.stdout = oldStdOut
## print("Bounce2 finns ej")
## return
##
##
## outString = sys.stdout.getvalue()
##
## sys.stdout = oldStdOut
##
## if outString==bounceOutput:
## print("Bounce2 funkar!")
## else:
## print(" Testresultat: ",outString)
## print(" R�tt resultat: ",bounceOutput)
def suitTestBounce(fkn, printName):
testBounce(fkn, printName, 5, "5\n4\n3\n2\n1\n0\n1\n2\n3\n4\n5\n")
testBounce(fkn, printName, 0, "0\n")
#suitTestBounce(__main__.bounce, "bounce")
try:
suitTestBounce(__main__.bounce, "bounce")
except AttributeError:
print("'bounce' finns ej.")
try:
suitTestBounce(__main__.bounce2, "bounce2")
except AttributeError:
print("'bounce2' finns ej.")