forked from pcewebpython/streams-exercise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
82 lines (58 loc) · 2.11 KB
/
tests.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""
streams-exercise.tests.py
This file is intentionally written without the benefit of the Python
unittest library. This can be used to demonstrate in-class that unit testing
is a simple concept which benefits from the use of a library, but does not
require it.
Run with `python tests.py`. The return code will be the number of test failures.
"""
import io
from stream_exercise import StreamProcessor
failures = 0
value = "234761640930110349378289194"
expected = 5
my_stream_processor = StreamProcessor(io.StringIO(value))
result = my_stream_processor.process()
success = result == expected
failures += (not success)
message = "Testing \"{}\", expected {} got {}. ".format(value, expected, result)
message += "SUCCESS" if success else "FAILURE"
print(message)
value = "03050403020309060707070708"
expected = 10
my_stream_processor = StreamProcessor(io.StringIO(value))
result = my_stream_processor.process()
success = result == expected
failures += (not success)
message = "Testing \"{}\", expected {} got {}. ".format(value, expected, result)
message += "SUCCESS" if success else "FAILURE"
print(message)
value = "3"
expected = 0
my_stream_processor = StreamProcessor(io.StringIO(value))
result = my_stream_processor.process()
success = result == expected
failures += (not success)
message = "Testing \"{}\", expected {} got {}. ".format(value, expected, result)
message += "SUCCESS" if success else "FAILURE"
print(message)
value = "2347"
expected = 2
my_stream_processor = StreamProcessor(io.StringIO(value))
result = my_stream_processor.process()
success = result == expected
failures += (not success)
message = "Testing \"{}\", expected {} got {}. ".format(value, expected, result)
message += "SUCCESS" if success else "FAILURE"
print(message)
value = "23478"
expected = 2
my_stream_processor = StreamProcessor(io.StringIO(value))
result = my_stream_processor.process()
success = result == expected
failures += (not success)
message = "Testing \"{}\", expected {} got {}. ".format(value, expected, result)
message += "SUCCESS" if success else "FAILURE"
print(message)
print("\n\nTest failures: {} ".format(failures))
exit(failures)