forked from zandraaperjesi/exam-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test) create 3 test cases and modified function to pass them
- Loading branch information
Showing
2 changed files
with
27 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
# Create a function called `odd_average` that takes a list of numbers as parameter | ||
# and returns the average value of the odd numbers in the list | ||
# Create basic unit tests for it with at least 3 different test cases | ||
nums = [15, 2, 3, 4, 3, 6] | ||
nums = [1, 2, 3, 4, 5] | ||
|
||
def odd_average(nums): | ||
odds = 0 | ||
odd_num = [] | ||
for num in nums: | ||
if num%2 == 1: | ||
odds += num | ||
odd_num.append(num) | ||
return odds//len(odd_num) | ||
try: | ||
if num%2 == 1: | ||
This comment has been minimized.
Sorry, something went wrong. |
||
odds += num | ||
odd_num.append(num) | ||
return odds//len(odd_num) | ||
This comment has been minimized.
Sorry, something went wrong.
gygabor
|
||
except ZeroDivisionError: | ||
return 0 | ||
|
||
print(odd_average(nums)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import unittest | ||
from odd_avg import odd_average | ||
|
||
class AverageMethod(unittest.TestCase): | ||
|
||
def test_average(self): | ||
list_of_nums = [9, 9, 10, 9, 3] | ||
self.assertEqual(odd_average(list_of_nums), 9) | ||
This comment has been minimized.
Sorry, something went wrong.
gygabor
|
||
|
||
def test_odds(self): | ||
list_of_nums = [4, 6, 8] | ||
self.assertEqual(odd_average(list_of_nums), 0) | ||
|
||
def test_empty_list(self): | ||
list_of_nums = [ ] | ||
self.assertEqual(odd_average(list_of_nums), None) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
It should be whitespaces around the operator according the style guide.