-
Notifications
You must be signed in to change notification settings - Fork 9
tests kata01 #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
tests kata01 #15
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| import unittest | ||
| from python_katas.kata_1 import questions | ||
| from python_katas.utils import unittest_runner | ||
|
|
||
| import questions | ||
|
|
||
| class TestSumOfElements(unittest.TestCase): | ||
| """ | ||
|
|
@@ -29,102 +27,222 @@ class TestWordsConcatenation(unittest.TestCase): | |
| """ | ||
| 1 Katas | ||
| """ | ||
|
|
||
| def test_empty_list(self): | ||
| lst = [] | ||
| self.assertEqual(questions.words_concatenation(lst), "") | ||
| self.assertEqual(questions.words_concatenation([]), '') | ||
|
|
||
| def test_full_list(self): | ||
| lst = ['no', 'place', 'like', 'home'] | ||
| self.assertEqual(questions.words_concatenation(lst), 'no place like home') | ||
| def test_one_element_none(self): | ||
| self.assertEqual(questions.words_concatenation(['abc', None, 'xyz']), 'abc xyz') | ||
|
|
||
| def test_empty_string_in_list(self): | ||
| lst = ['no', '', 'place', '', 'like', 'home'] | ||
| self.assertEqual(questions.words_concatenation(lst), 'no place like home') | ||
|
|
||
| def test_list_of_empty_strings(self): | ||
| lst = ["","","","",""] | ||
| self.assertEqual(questions.words_concatenation(lst),"") | ||
| def test_if_return_string(self): | ||
| self.assertIsInstance(questions.words_concatenation(['x', 'y', 'z']), str) | ||
|
|
||
| def test_str(self): | ||
| self.assertEqual(questions.words_concatenation(['I', 'am', 'a', 'list']), 'I am a list') | ||
|
|
||
| class TestReverseWordsConcatenation(unittest.TestCase): | ||
| """ | ||
| 1 Katas | ||
| """ | ||
| def test_empty_list(self): | ||
| self.assertEqual(questions.reverse_words_concatenation([]), '') | ||
|
|
||
| def test_sample(self): | ||
| # your code here | ||
| pass | ||
| def test_one_element_none(self): | ||
| self.assertEqual(questions.reverse_words_concatenation(['abc',None,'xyz']), 'xyz abc') | ||
|
|
||
| def test_if_return_string(self): | ||
| self.assertIsInstance(questions.reverse_words_concatenation(['x', 'y', 'z']), str) | ||
|
|
||
| def tes_str(self): | ||
| self.assertEqual(questions.reverse_words_concatenation(['I', 'am', 'a', 'list']), 'list a am I') | ||
|
|
||
| class TestIsUniqueString(unittest.TestCase): | ||
| """ | ||
| 2 Katas | ||
| """ | ||
| def test_empty_str(self): | ||
| self.assertTrue(questions.is_unique_string('')) | ||
|
|
||
| def test_sample(self): | ||
| # your code here | ||
| pass | ||
| def test_None(self): | ||
| self.assertTrue(questions.is_unique_string(None)) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is_unique_string expects string as input, not None |
||
|
|
||
| def test_not_unique(self): | ||
| self.assertFalse(questions.is_unique_string('aabbcc')) | ||
|
|
||
| def tes_unique(self): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. function name must starts with |
||
| self.assertTrue(questions.is_unique_string('abc')) | ||
|
|
||
|
|
||
| class TestListDiff(unittest.TestCase): | ||
| """ | ||
| 1 Katas | ||
| """ | ||
| def test_if_return_list(self): | ||
| self.assertIsInstance(questions.list_diff([1, 2]), list) | ||
|
|
||
| def test_sample(self): | ||
| # your code here | ||
| pass | ||
| def test_first_element_None(self): | ||
| self.assertIsNone(questions.list_diff([1, 2, 3])[0]) | ||
|
|
||
| def test_empty_list(self): | ||
| self.assertEqual(questions.list_diff([]), []) | ||
|
|
||
| def test_all_negative(self): | ||
| self.assertEqual(questions.list_diff([-1, -2, -3, -4, -5]), [None, -1, -1, -1, -1]) | ||
|
|
||
| def test_first_negative(self): | ||
| self.assertEqual(questions.list_diff([-1, 1, 1]), [None, 2, 0]) | ||
|
|
||
| def test_all_positive(self): | ||
| self.assertEqual(questions.list_diff([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), [None, 1, 1, 1, 1, 1, 1, 1, 1, 1]) | ||
|
|
||
|
|
||
| class TestPrimeNumber(unittest.TestCase): | ||
| """ | ||
| 1 Katas | ||
| """ | ||
|
|
||
| def test_sample(self): | ||
| # your code here | ||
| pass | ||
| def test_negative(self): | ||
| self.assertFalse(questions.prime_number(-1)) | ||
|
|
||
| def test_zero(self): | ||
| self.assertFalse(questions.prime_number(0)) | ||
|
|
||
| def test_none(self): | ||
| self.assertFalse(questions.prime_number(None)) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prime_number should receive only int as an argument |
||
|
|
||
| def test_float(self): | ||
| self.assertFalse(questions.prime_number(5.5)) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prime_number should receive only int as an argument |
||
|
|
||
| def test_one(self): | ||
| self.assertFalse(questions.prime_number(1)) | ||
|
|
||
| def test_prime_true(self): | ||
| self.assertTrue(questions.prime_number(47)) | ||
|
|
||
| def test_prime_false(self): | ||
| self.assertFalse(questions.prime_number(55)) | ||
|
|
||
| class TestPalindromeNum(unittest.TestCase): | ||
| """ | ||
| 1 Katas | ||
| """ | ||
|
|
||
| def test_sample(self): | ||
| # your code here | ||
| pass | ||
| def test_single_digit(self): | ||
| self.assertTrue(questions.palindrome_num(0)) | ||
|
|
||
| def test_true(self): | ||
| self.assertTrue(questions.palindrome_num(1221)) | ||
|
|
||
| def test_false(self): | ||
| self.assertFalse(questions.palindrome_num(577)) | ||
|
|
||
|
|
||
|
|
||
| class TestPairMatch(unittest.TestCase): | ||
| """ | ||
| 3 Katas | ||
| """ | ||
|
|
||
| def test_sample(self): | ||
| # your code here | ||
| pass | ||
| def negative_vaules(self): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test function must starts with |
||
| men = {"John": -20, "Abraham": -45} | ||
| women = {"July": -18, "Kim": -26} | ||
| result = ('John', 'July') | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aren't |
||
| self.assertEqual(questions.pair_match(men, women), result) | ||
|
|
||
| def is_result_tuple(self): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test function must starts with |
||
| men = {"John": -20, "Abraham": -45} | ||
| women = {"July": -18, "Kim": -26} | ||
| self.assertIsInstance(questions.pair_match(men,women), tuple) | ||
|
|
||
| def none_value(self): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test function must starts with |
||
| men = {"John": -20, "Abraham": -45} | ||
| women = {"July": None, "Kim": -26} | ||
| self.assertEqual(questions.pair_match(men,women), ('Abraham', 'Kim')) | ||
|
|
||
| def none_key(self): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test function must starts with |
||
| men = {None: 255, "Abraham": 55} | ||
| women = {"July": 55, "Kim": 256} | ||
| self.assertEqual(questions.pair_match(men,women), (None, 'Kim')) | ||
|
|
||
| def zero_values(self): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test function must starts with |
||
| men = {'Mony': 0, "Nick": 0} | ||
| women = {"Imbal": 0, "Irit": 0} | ||
| self.assertEqual(questions.pair_match(men,women), ('Mony', 'Imbal')) | ||
|
|
||
| class TestBadAverage(unittest.TestCase): | ||
| """ | ||
| 1 Katas | ||
| """ | ||
|
|
||
| def test_sample(self): | ||
| # your code here | ||
| pass | ||
| def test_zeros(self): | ||
| self.assertEqual(questions.bad_average(0, 0, 0), 0) | ||
|
|
||
| def test_negative(self): | ||
| self.assertEqual(questions.bad_average(-5, -5, -5), -5) | ||
|
|
||
| def test_correct(self): | ||
| self.assertEqual(questions.bad_average(20, 40, 40), 33) | ||
|
|
||
| def test_float(self): | ||
| self.assertEqual(questions.bad_average(5.5, 5.5, 5.5), 5) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The answer should be |
||
|
|
||
| def test_return_int(self): | ||
| self.assertIsInstance(questions.bad_average(0, 0, 0), int) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
|
|
||
| class TestBestStudent(unittest.TestCase): | ||
| """ | ||
| 1 Katas | ||
| """ | ||
|
|
||
| def test_sample(self): | ||
| # your code here | ||
| pass | ||
| def test_none_value(self): | ||
| data = { | ||
| "Ben": 78, | ||
| "Dan": 88, | ||
| "Nathan": None, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function expects |
||
| "Daniel": 65, | ||
| "Tal": 95 | ||
| } | ||
| self.assertEqual(questions.best_student(data), 'Tal') | ||
|
|
||
| def return_string(self): | ||
| data = { | ||
| "Ben": 78, | ||
| "Dan": 88, | ||
| "Nathan": None, | ||
| "Daniel": 65, | ||
| "Tal": 95 | ||
| } | ||
| self.assertIsInstance(questions.best_student(data), str) | ||
|
|
||
| def test_float(self): | ||
| data = { | ||
| "Ben": 78.55, | ||
| "Dan": 88.66, | ||
| "Nathan": None, | ||
| "Daniel": 65.66, | ||
| "Tal": 5.1 | ||
| } | ||
| self.assertEqual(questions.best_student(data), 'Dan') | ||
|
|
||
| def test_value_string(self): | ||
| data = { | ||
| None: 'x', | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function expects |
||
| "Dan": 88, | ||
| "Nathan": None, | ||
| "Daniel": 65, | ||
| "Tal": 95 | ||
| } | ||
| self.assertEqual(questions.best_student(data), 'Tal') | ||
|
|
||
| def test_key_not_str(self): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function expects |
||
| data = { | ||
| None: 'x', | ||
| "Dan": 88, | ||
| "Nathan": None, | ||
| "Daniel": 65, | ||
| "Tal": 95 | ||
| } | ||
| self.assertEqual(questions.best_student(data), 'Tal') | ||
|
|
||
|
|
||
| class TestPrintDictAsTable(unittest.TestCase): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will remove this function from the katas |
||
|
|
@@ -142,20 +260,77 @@ class TestMergeDicts(unittest.TestCase): | |
| 1 Katas | ||
| """ | ||
|
|
||
| def test_sample(self): | ||
| # your code here | ||
| pass | ||
| def test_empty_dict(self): | ||
| dict1 = {} | ||
| dict2 = {} | ||
| self.assertEqual(questions.merge_dicts(dict1, dict2), {}) | ||
|
|
||
| def test_return_dict(self): | ||
| dict1 = {} | ||
| dict2 = {} | ||
| self.assertIsInstance(questions.merge_dicts(dict1, dict2), dict) | ||
|
|
||
| def test_arg_dict(self): | ||
| dict1 = {} | ||
| dict2 = 'xx' | ||
| self.assertEqual(questions.merge_dicts(dict1, dict2), {}) | ||
| dict1 = 1 | ||
| dict2 = 2 | ||
| self.assertEqual(questions.merge_dicts(dict1, dict2), {}) | ||
|
|
||
|
|
||
|
|
||
| class TestSevenBoom(unittest.TestCase): | ||
| """ | ||
| 1 Katas | ||
| """ | ||
|
|
||
| def test_sample(self): | ||
| # your code here | ||
| pass | ||
| def test_negative(self): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| n = -7 | ||
| self.assertEqual(questions.seven_boom(n), [-7]) | ||
|
|
||
| def test_positive_seven(self): | ||
| n = 7 | ||
| self.assertEqual(questions.seven_boom(n), [7]) | ||
|
|
||
| def test_zero(self): | ||
| n = 0 | ||
| self.assertEqual(questions.seven_boom(n), []) | ||
|
|
||
| def test_numeric_string(self): | ||
| n = '7' | ||
| self.assertEqual(questions.seven_boom(n), [7]) | ||
|
|
||
| def test_negative_numeric_string(self): | ||
| n = '-7' | ||
| self.assertEqual(questions.seven_boom(n), [-7]) | ||
|
|
||
| def test_return_int_element(self): | ||
| n = 7 | ||
| self.assertIsInstance(questions.seven_boom(n)[0], int) | ||
|
|
||
| def test_return_list(self): | ||
| n = 7 | ||
| self.assertIsInstance(questions.seven_boom(n), list) | ||
|
|
||
| def test_none(self): | ||
| self.assertEqual(questions.seven_boom(None), []) | ||
|
|
||
| def test_tuple(self): | ||
| n = (4, 4) | ||
| self.assertEqual(questions.seven_boom(n), []) | ||
|
|
||
| def test_list(self): | ||
| n = [7,7] | ||
| self.assertEqual(questions.seven_boom(n), []) | ||
|
|
||
| def test_dict(self): | ||
| n = {4:4} | ||
| self.assertEqual(questions.seven_boom(n), []) | ||
|
|
||
| def test_string(self): | ||
| n = '7x' | ||
| self.assertEqual(questions.seven_boom(n), []) | ||
|
|
||
| class TestCaesarCipher(unittest.TestCase): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test suite should test |
||
| """ | ||
|
|
@@ -172,12 +347,28 @@ class TestSumOfDigits(unittest.TestCase): | |
| 1 Katas | ||
| """ | ||
|
|
||
| def test_sample(self): | ||
| # your code here | ||
| pass | ||
| def test_empty_string(self): | ||
| n = '' | ||
| self.assertEqual(questions.sum_of_digits(n), 0) | ||
|
|
||
| def test_return_int(self): | ||
| n='' | ||
| self.assertIsInstance(questions.sum_of_digits(n),int) | ||
|
|
||
| def test_none(self): | ||
| self.assertEqual(questions.sum_of_digits(None), 0) | ||
|
|
||
| def test_positive_value(self): | ||
| n = '011' | ||
| self.assertEqual(questions.sum_of_digits(n), 2) | ||
|
|
||
| def test_negative_value(self): | ||
| n = '0-1-5-6-7' | ||
| self.assertEqual(questions.sum_of_digits(n), -19) | ||
| def test_zero_value(self): | ||
| n = '0' | ||
| self.assertEqual(questions.sum_of_digits(n), 0) | ||
| if __name__ == '__main__': | ||
| import inspect | ||
| import sys | ||
| unittest_runner(inspect.getmembers(sys.modules[__name__], inspect.isclass)) | ||
| unittest_runner(inspect.getmembers(sys.modules[__name__], inspect.isclass)) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function name must starts with
test_