Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d266cac

Browse files
committedNov 12, 2021
Improved test update for Loops
1 parent 50fc844 commit d266cac

File tree

6 files changed

+29
-21
lines changed

6 files changed

+29
-21
lines changed
 

‎Loops/Break keyword/tests/test_task.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def test_loop(self):
1414
msg='Your loop should only print the last three animals in reverse order.')
1515

1616
def test_list(self):
17-
self.assertEqual(zoo, ['lion', 'tiger'], msg='The zoo list in the end should contain only lion and tiger.')
17+
expected, actual = ['lion', 'tiger'], zoo
18+
self.assertEqual(expected, actual, msg='The zoo list in the end should contain only lion and tiger.')
1819

1920
except IndexError:
2021
class TestFailCase(unittest.TestCase):

‎Loops/Continue keyword/tests/test_task.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
class TestCase(unittest.TestCase):
1313
def test_default(self):
14-
correct = ['0', '1', '2', '4', '1', '3', '5', '7', '9', '']
15-
self.assertEqual(correct, output, msg='Wrong output. Check your condition. Please do not change the '
14+
expected = ['0', '1', '2', '4', '1', '3', '5', '7', '9', '']
15+
self.assertEqual(expected, output, msg='Wrong output. Check your condition. Please do not change the '
1616
'starter code.')
1717

1818
def test_condition(self):

‎Loops/Else with loops/tests/test_task.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def test_default(self):
2020
def test_correct(self):
2121
if len(output) == 13:
2222
self.test_default()
23-
correct = ["it's less than 5", "it's less than 5", "it's less than 5",
23+
expected = ["it's less than 5", "it's less than 5", "it's less than 5",
2424
"it's less than 5", "it's less than 5", "and now it's 5",
2525
'1', '2', 'Outside the for loop', '']
26-
self.assertEqual(correct, output, msg='Your code does not print what is expected. Check your condition. '
26+
self.assertEqual(expected, output, msg='Your code does not print what is expected. Check your condition. '
2727
'Please do not change the starter code.')
2828

‎Loops/For loop/tests/test_task.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010

1111
class TestCase(unittest.TestCase):
1212
def test_loop(self):
13-
self.assertEqual(output[0], '0', msg='Please do not change the starter code.')
14-
self.assertEqual(output[1], '1', msg='Please do not change the starter code.')
15-
self.assertEqual(output[2], '2', msg='Please do not change the starter code.')
16-
self.assertEqual(output[3], '3', msg='Please do not change the starter code.')
17-
self.assertEqual(output[4], '4', msg='Please do not change the starter code.')
18-
self.assertEqual(output[5], '2', msg='Your code does not print the `primes`')
19-
self.assertEqual(output[6], '3', msg='Your code does not print the `primes`')
20-
self.assertEqual(output[7], '5', msg='Your code does not print the `primes`')
21-
self.assertEqual(output[8], '7', msg='Your code does not print the `primes`')
22-
self.assertEqual(output, ['0', '1', '2', '3', '4', '2', '3', '5', '7', ''], msg='Wrong output.')
13+
self.assertEqual('0', output[0], msg='Please do not change the starter code.')
14+
self.assertEqual('1', output[1], msg='Please do not change the starter code.')
15+
self.assertEqual('2', output[2], msg='Please do not change the starter code.')
16+
self.assertEqual('3', output[3], msg='Please do not change the starter code.')
17+
self.assertEqual('4', output[4], msg='Please do not change the starter code.')
18+
self.assertEqual('2', output[5], msg='Your code does not print the `primes`')
19+
self.assertEqual('3', output[6], msg='Your code does not print the `primes`')
20+
self.assertEqual('5', output[7], msg='Your code does not print the `primes`')
21+
self.assertEqual('7', output[8], msg='Your code does not print the `primes`')
22+
self.assertEqual(['0', '1', '2', '3', '4', '2', '3', '5', '7', ''], output, msg='Wrong output.')
2323

2424
except IndentationError:
2525
class TestFailCase(unittest.TestCase):

‎Loops/Loop over a string/tests/test_task.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
output = f.getvalue().split('\n')
1010

1111
class TestCase(unittest.TestCase):
12-
def test_loop(self):
13-
self.assertEqual(len(output), 15, msg='Wrong output length. Please do not change anything '
12+
def test_out_len(self):
13+
expected, actual = 15, len(output)
14+
self.assertEqual(expected, actual, msg='Wrong output length. Please do not change anything '
1415
'in the starter code apart from the answer placeholder')
15-
self.assertEqual(output[-2], 'True', msg='`length` should be equal to `len(hello_world)`.')
16+
17+
def test_word_len(self):
18+
expected, actual = 'True', output[-2]
19+
self.assertEqual(expected, actual, msg='`length` should be equal to `len(hello_world)`.')
1620

1721
except IndentationError:
1822
class TestFailCase(unittest.TestCase):

‎Loops/While loop/tests/test_task.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010

1111
class TestCase(unittest.TestCase):
1212
def test_finished(self):
13-
self.assertEqual(output[10], 'Finished', msg='Please do not change the starter code.')
13+
expected, actual = 'Finished', output[10]
14+
self.assertEqual(expected, actual, msg='Please do not change the starter code.')
1415

1516
def test_output(self):
16-
self.assertEqual(output[11:20], ['1', '4', '9', '16', '25', '36', '49', '64', '81'],
17+
expected, actual = ['1', '4', '9', '16', '25', '36', '49', '64', '81'], output[11:20]
18+
self.assertEqual(expected, actual,
1719
msg='Your while loop does not output all of the needed squares.')
1820

1921
def test_last(self):
20-
self.assertEqual(output[-2], '81', msg='The last square should be 81. Maybe check your while loop '
22+
expected, actual = '81', output[-2]
23+
self.assertEqual(expected, actual, msg='The last square should be 81. Maybe check your while loop '
2124
'condition.')
2225

2326
except IndentationError:

0 commit comments

Comments
 (0)
Please sign in to comment.