Skip to content

Commit afb2491

Browse files
author
thinwybk
committed
add: basic unittest test
add: - init.py to find modules in unit test modules - return of print statements - test for strategy
1 parent cf9cc12 commit afb2491

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎__init__.py‎

Whitespace-only changes.

‎strategy.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ def __init__(self, func=None):
2020

2121
def execute(self):
2222
print(self.name)
23+
return self.name
2324

2425

2526
def execute_replacement1(self):
2627
print(self.name + ' from execute 1')
28+
return self.name + ' from execute 1'
2729

2830

2931
def execute_replacement2(self):
3032
print(self.name + ' from execute 2')
33+
return self.name + ' from execute 2'
3134

3235

3336
if __name__ == '__main__':

‎test_strategy.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import unittest
2+
import strategy
3+
4+
class StrategyTest(unittest.TestCase):
5+
6+
def test_print_output(self):
7+
strat0 = strategy.StrategyExample()
8+
9+
strat1 = strategy.StrategyExample(strategy.execute_replacement1)
10+
strat1.name = 'Strategy Example 1'
11+
12+
strat2 = strategy.StrategyExample(strategy.execute_replacement2)
13+
strat2.name = 'Strategy Example 2'
14+
15+
first_line = strat0.execute()
16+
second_line = strat1.execute()
17+
third_line = strat2.execute()
18+
19+
self.assertEqual(first_line, 'Strategy Example 0')
20+
self.assertEqual(second_line, 'Strategy Example 1 from execute 1')
21+
self.assertEqual(third_line, 'Strategy Example 2 from execute 2')
22+
23+
if __name__ == "__main__":
24+
unitest.main()

0 commit comments

Comments
 (0)