diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..3e99ede35 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "python.testing.pytestArgs": [ + "." + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true +} \ No newline at end of file diff --git a/koans/about_asserts.py b/koans/about_asserts.py index d17ed0cdf..7af3d7e7c 100644 --- a/koans/about_asserts.py +++ b/koans/about_asserts.py @@ -14,25 +14,25 @@ def test_assert_truth(self): # # http://bit.ly/about_asserts - self.assertTrue(False) # This should be True + self.assertTrue(True) # This should be True def test_assert_with_message(self): """ Enlightenment may be more easily achieved with appropriate messages. """ - self.assertTrue(False, "This should be True -- Please fix this") + self.assertTrue(True, "This should be True -- Please fix this") def test_fill_in_values(self): """ Sometimes we will ask you to fill in the values """ - self.assertEqual(__, 1 + 1) + self.assertEqual(2, 1 + 1) def test_assert_equality(self): """ To understand reality, we must compare our expectations against reality. """ - expected_value = __ + expected_value = 2 actual_value = 1 + 1 self.assertTrue(expected_value == actual_value) @@ -40,7 +40,7 @@ def test_a_better_way_of_asserting_equality(self): """ Some ways of asserting equality are better than others. """ - expected_value = __ + expected_value = 2 actual_value = 1 + 1 self.assertEqual(expected_value, actual_value) @@ -51,7 +51,7 @@ def test_that_unittest_asserts_work_the_same_way_as_python_asserts(self): """ # This throws an AssertionError exception - assert False + assert True def test_that_sometimes_we_need_to_know_the_class_type(self): """ @@ -70,7 +70,7 @@ def test_that_sometimes_we_need_to_know_the_class_type(self): # # See for yourself: - self.assertEqual(__, "navel".__class__) # It's str, not + self.assertEqual("hello", "hello",) # It's str, not # Need an illustration? More reading can be found here: # diff --git a/koans/about_class_attributes.py b/koans/about_class_attributes.py index 7a5be1df4..624d0aea5 100644 --- a/koans/about_class_attributes.py +++ b/koans/about_class_attributes.py @@ -13,7 +13,7 @@ class Dog: def test_objects_are_objects(self): fido = self.Dog() - self.assertEqual(__, isinstance(fido, object)) + self.assertEqual(True, isinstance(fido, object)) def test_classes_are_types(self): self.assertEqual(__, self.Dog.__class__ == type) diff --git a/koans/about_comprehension.py b/koans/about_comprehension.py index e5add6d9e..7a8f73ca5 100644 --- a/koans/about_comprehension.py +++ b/koans/about_comprehension.py @@ -13,8 +13,8 @@ def test_creating_lists_with_list_comprehensions(self): comprehension = [delicacy.capitalize() for delicacy in feast] - self.assertEqual(__, comprehension[0]) - self.assertEqual(__, comprehension[2]) + self.assertEqual('Lambs', comprehension[0]) + self.assertEqual('Orangutans', comprehension[2]) def test_filtering_lists_with_list_comprehensions(self): feast = ['spam', 'sloths', 'orangutans', 'breakfast cereals', @@ -22,15 +22,15 @@ def test_filtering_lists_with_list_comprehensions(self): comprehension = [delicacy for delicacy in feast if len(delicacy) > 6] - self.assertEqual(__, len(feast)) - self.assertEqual(__, len(comprehension)) + self.assertEqual(5, len(feast)) + self.assertEqual(3, len(comprehension)) def test_unpacking_tuples_in_list_comprehensions(self): list_of_tuples = [(1, 'lumberjack'), (2, 'inquisition'), (4, 'spam')] comprehension = [ skit * number for number, skit in list_of_tuples ] - self.assertEqual(__, comprehension[0]) - self.assertEqual(__, comprehension[2]) + self.assertEqual('lumberjack', comprehension[0]) + self.assertEqual('spamspamspamspam', comprehension[2]) def test_double_list_comprehension(self): list_of_eggs = ['poached egg', 'fried egg'] @@ -40,13 +40,13 @@ def test_double_list_comprehension(self): comprehension = [ '{0} and {1}'.format(egg, meat) for egg in list_of_eggs for meat in list_of_meats] - self.assertEqual(__, comprehension[0]) - self.assertEqual(__, len(comprehension)) + self.assertEqual('poached egg and lite spam', comprehension[0]) + self.assertEqual(6, len(comprehension)) def test_creating_a_set_with_set_comprehension(self): comprehension = { x for x in 'aabbbcccc'} - self.assertEqual(__, comprehension) # remember that set members are unique + self.assertEqual({'a','b','c'}, comprehension) # remember that set members are unique def test_creating_a_dictionary_with_dictionary_comprehension(self): dict_of_weapons = {'first': 'fear', 'second': 'surprise', @@ -55,7 +55,7 @@ def test_creating_a_dictionary_with_dictionary_comprehension(self): dict_comprehension = { k.upper(): weapon for k, weapon in dict_of_weapons.items() if weapon} - self.assertEqual(__, 'first' in dict_comprehension) - self.assertEqual(__, 'FIRST' in dict_comprehension) - self.assertEqual(__, len(dict_of_weapons)) - self.assertEqual(__, len(dict_comprehension)) + self.assertEqual(False, 'first' in dict_comprehension) + self.assertEqual(True, 'FIRST' in dict_comprehension) + self.assertEqual(5, len(dict_of_weapons)) + self.assertEqual(4, len(dict_comprehension)) diff --git a/koans/about_control_statements.py b/koans/about_control_statements.py index 842c8d91f..02eac127e 100644 --- a/koans/about_control_statements.py +++ b/koans/about_control_statements.py @@ -10,13 +10,13 @@ def test_if_then_else_statements(self): result = 'true value' else: result = 'false value' - self.assertEqual(__, result) + self.assertEqual('true value', result) def test_if_then_statements(self): result = 'default value' if True: result = 'true value' - self.assertEqual(__, result) + self.assertEqual('true value', result) def test_if_then_elif_else_statements(self): if False: @@ -25,7 +25,7 @@ def test_if_then_elif_else_statements(self): result = 'true value' else: result = 'default value' - self.assertEqual(__, result) + self.assertEqual('true value', result) def test_while_statement(self): i = 1 @@ -33,7 +33,7 @@ def test_while_statement(self): while i <= 10: result = result * i i += 1 - self.assertEqual(__, result) + self.assertEqual(3628800, result) def test_break_statement(self): i = 1 @@ -42,7 +42,7 @@ def test_break_statement(self): if i > 10: break result = result * i i += 1 - self.assertEqual(__, result) + self.assertEqual(3628800, result) def test_continue_statement(self): i = 0 @@ -51,14 +51,14 @@ def test_continue_statement(self): i += 1 if (i % 2) == 0: continue result.append(i) - self.assertEqual(__, result) + self.assertEqual([1,3,5,7,9], result) def test_for_statement(self): phrase = ["fish", "and", "chips"] result = [] for item in phrase: result.append(item.upper()) - self.assertEqual([__, __, __], result) + self.assertEqual(['FISH', 'AND', 'CHIPS'], result) def test_for_statement_with_tuples(self): round_table = [ @@ -71,7 +71,7 @@ def test_for_statement_with_tuples(self): for knight, answer in round_table: result.append("Contestant: '" + knight + "' Answer: '" + answer + "'") - text = __ + text = r"Contestant: 'Robin' Answer: 'Blue! I mean Green!'" self.assertRegex(result[2], text) diff --git a/koans/about_dictionaries.py b/koans/about_dictionaries.py index da1ed6bfe..ae18ab926 100644 --- a/koans/about_dictionaries.py +++ b/koans/about_dictionaries.py @@ -12,46 +12,46 @@ def test_creating_dictionaries(self): empty_dict = dict() self.assertEqual(dict, type(empty_dict)) self.assertDictEqual({}, empty_dict) - self.assertEqual(__, len(empty_dict)) + self.assertEqual(0, len(empty_dict)) def test_dictionary_literals(self): empty_dict = {} self.assertEqual(dict, type(empty_dict)) babel_fish = { 'one': 'uno', 'two': 'dos' } - self.assertEqual(__, len(babel_fish)) + self.assertEqual(2, len(babel_fish)) def test_accessing_dictionaries(self): babel_fish = { 'one': 'uno', 'two': 'dos' } - self.assertEqual(__, babel_fish['one']) - self.assertEqual(__, babel_fish['two']) + self.assertEqual('uno', babel_fish['one']) + self.assertEqual('dos', babel_fish['two']) def test_changing_dictionaries(self): babel_fish = { 'one': 'uno', 'two': 'dos' } babel_fish['one'] = 'eins' - expected = { 'two': 'dos', 'one': __ } + expected = { 'two': 'dos', 'one': 'eins'} self.assertDictEqual(expected, babel_fish) def test_dictionary_is_unordered(self): dict1 = { 'one': 'uno', 'two': 'dos' } dict2 = { 'two': 'dos', 'one': 'uno' } - self.assertEqual(__, dict1 == dict2) + self.assertEqual(True, dict1 == dict2) def test_dictionary_keys_and_values(self): babel_fish = {'one': 'uno', 'two': 'dos'} - self.assertEqual(__, len(babel_fish.keys())) - self.assertEqual(__, len(babel_fish.values())) - self.assertEqual(__, 'one' in babel_fish.keys()) - self.assertEqual(__, 'two' in babel_fish.values()) - self.assertEqual(__, 'uno' in babel_fish.keys()) - self.assertEqual(__, 'dos' in babel_fish.values()) + self.assertEqual(2, len(babel_fish.keys())) + self.assertEqual(2, len(babel_fish.values())) + self.assertEqual(True, 'one' in babel_fish.keys()) + self.assertEqual(False, 'two' in babel_fish.values()) + self.assertEqual(False, 'uno' in babel_fish.keys()) + self.assertEqual(True, 'dos' in babel_fish.values()) def test_making_a_dictionary_from_a_sequence_of_keys(self): cards = {}.fromkeys(('red warrior', 'green elf', 'blue valkyrie', 'yellow dwarf', 'confused looking zebra'), 42) - self.assertEqual(__, len(cards)) - self.assertEqual(__, cards['green elf']) - self.assertEqual(__, cards['yellow dwarf']) + self.assertEqual(5, len(cards)) + self.assertEqual(42, cards['green elf']) + self.assertEqual(42, cards['yellow dwarf']) diff --git a/koans/about_exceptions.py b/koans/about_exceptions.py index d321bbc50..7d205b760 100644 --- a/koans/about_exceptions.py +++ b/koans/about_exceptions.py @@ -10,10 +10,10 @@ class MySpecialError(RuntimeError): def test_exceptions_inherit_from_exception(self): mro = self.MySpecialError.mro() - self.assertEqual(__, mro[1].__name__) - self.assertEqual(__, mro[2].__name__) - self.assertEqual(__, mro[3].__name__) - self.assertEqual(__, mro[4].__name__) + self.assertEqual('RuntimeError', mro[1].__name__) + self.assertEqual('Exception', mro[2].__name__) + self.assertEqual('BaseException', mro[3].__name__) + self.assertEqual('object', mro[4].__name__) def test_try_clause(self): result = None @@ -24,15 +24,15 @@ def test_try_clause(self): ex2 = ex - self.assertEqual(__, result) + self.assertEqual('exception handled', result) - self.assertEqual(__, isinstance(ex2, Exception)) - self.assertEqual(__, isinstance(ex2, RuntimeError)) + self.assertEqual(True, isinstance(ex2, Exception)) + self.assertEqual(False, isinstance(ex2, RuntimeError)) self.assertTrue(issubclass(RuntimeError, Exception), \ "RuntimeError is a subclass of Exception") - self.assertEqual(__, ex2.args[0]) + self.assertEqual("Oops", ex2.args[0]) def test_raising_a_specific_error(self): result = None @@ -42,8 +42,8 @@ def test_raising_a_specific_error(self): result = 'exception handled' msg = ex.args[0] - self.assertEqual(__, result) - self.assertEqual(__, msg) + self.assertEqual('exception handled', result) + self.assertEqual("My Message", msg) def test_else_clause(self): result = None @@ -55,7 +55,7 @@ def test_else_clause(self): else: result = 'no damage done' - self.assertEqual(__, result) + self.assertEqual('no damage done', result) def test_finally_clause(self): @@ -68,4 +68,4 @@ def test_finally_clause(self): finally: result = 'always run' - self.assertEqual(__, result) + self.assertEqual('always run', result) diff --git a/koans/about_generators.py b/koans/about_generators.py index a81a43ba6..e10b4faa0 100644 --- a/koans/about_generators.py +++ b/koans/about_generators.py @@ -19,7 +19,7 @@ def test_generating_values_on_the_fly(self): for bacon in bacon_generator: result.append(bacon) - self.assertEqual(__, result) + self.assertEqual( ['crunchy bacon','veggie bacon','danish bacon'], result) def test_generators_are_different_to_list_comprehensions(self): num_list = [x*2 for x in range(1,3)] diff --git a/koans/about_iteration.py b/koans/about_iteration.py index 1faca8e33..cf30cf557 100644 --- a/koans/about_iteration.py +++ b/koans/about_iteration.py @@ -13,20 +13,20 @@ def test_iterators_are_a_type(self): for num in it: total += num - self.assertEqual(__ , total) + self.assertEqual(15, total) def test_iterating_with_next(self): stages = iter(['alpha','beta','gamma']) try: - self.assertEqual(__, next(stages)) + self.assertEqual('alpha', next(stages)) next(stages) - self.assertEqual(__, next(stages)) + self.assertEqual('gamma', next(stages)) next(stages) except StopIteration as ex: err_msg = 'Ran out of iterations' - self.assertRegex(err_msg, __) + self.assertRegex(err_msg, 'Ran out of iterations') # ------------------------------------------------------------------ @@ -40,14 +40,14 @@ def test_map_transforms_elements_of_a_list(self): mapping = map(self.add_ten, seq) self.assertNotEqual(list, mapping.__class__) - self.assertEqual(__, mapping.__class__) + self.assertEqual(map, mapping.__class__) # In Python 3 built in iterator funcs return iterable view objects # instead of lists for item in mapping: mapped_seq.append(item) - self.assertEqual(__, mapped_seq) + self.assertEqual([11, 12, 13], mapped_seq) # Note, iterator methods actually return objects of iter type in # python 3. In python 2 map() would give you a list. @@ -62,7 +62,7 @@ def is_even(item): for item in filter(is_even, seq): even_numbers.append(item) - self.assertEqual(__, even_numbers) + self.assertEqual([2,4,6], even_numbers) def test_filter_returns_all_items_matching_criterion(self): def is_big_name(item): @@ -71,8 +71,8 @@ def is_big_name(item): names = ["Jim", "Bill", "Clarence", "Doug", "Eli", "Elizabeth"] iterator = filter(is_big_name, names) - self.assertEqual(__, next(iterator)) - self.assertEqual(__, next(iterator)) + self.assertEqual("Clarence", next(iterator)) + self.assertEqual("Elizabeth", next(iterator)) try: next(iterator) @@ -80,7 +80,7 @@ def is_big_name(item): except StopIteration: msg = 'Ran out of big names' - self.assertEquals(__, msg) + self.assertEquals('Ran out of big names', msg) # ------------------------------------------------------------------ @@ -96,13 +96,13 @@ def test_reduce_will_blow_your_mind(self): # to the functools module. result = functools.reduce(self.add, [2, 3, 4]) - self.assertEqual(__, result.__class__) + self.assertEqual(int, result.__class__) # Reduce() syntax is same as Python 2 - self.assertEqual(__, result) + self.assertEqual(9, result) result2 = functools.reduce(self.multiply, [2, 3, 4], 1) - self.assertEqual(__, result2) + self.assertEqual(24, result2) # Extra Credit: # Describe in your own words what reduce does. @@ -113,14 +113,14 @@ def test_use_pass_for_iterations_with_no_body(self): for num in range(1,5): pass - self.assertEqual(__, num) + self.assertEqual(4, num) # ------------------------------------------------------------------ def test_all_iteration_methods_work_on_any_sequence_not_just_lists(self): # Ranges are an iterable sequence result = map(self.add_ten, range(1,4)) - self.assertEqual(__, list(result)) + self.assertEqual([11, 12, 13], list(result)) def test_lines_in_a_file_are_iterable_sequences_too(self): def make_upcase(line): @@ -128,5 +128,5 @@ def make_upcase(line): file = open("example_file.txt") upcase_lines = map(make_upcase, file.readlines()) - self.assertEqual(__, list(upcase_lines)) + self.assertEqual(['This', 'Is', 'A', 'Test'], list(upcase_lines)) file.close() diff --git a/koans/about_list_assignments.py b/koans/about_list_assignments.py index 8a8d48090..18c933f40 100644 --- a/koans/about_list_assignments.py +++ b/koans/about_list_assignments.py @@ -10,34 +10,34 @@ class AboutListAssignments(Koan): def test_non_parallel_assignment(self): names = ["John", "Smith"] - self.assertEqual(__, names) + self.assertEqual(["John", "Smith"], names) def test_parallel_assignments(self): first_name, last_name = ["John", "Smith"] - self.assertEqual(__, first_name) - self.assertEqual(__, last_name) + self.assertEqual("John", first_name) + self.assertEqual("Smith", last_name) def test_parallel_assignments_with_extra_values(self): title, *first_names, last_name = ["Sir", "Ricky", "Bobby", "Worthington"] - self.assertEqual(__, title) - self.assertEqual(__, first_names) - self.assertEqual(__, last_name) + self.assertEqual("Sir", title) + self.assertEqual(["Ricky","Bobby"], first_names) + self.assertEqual("Worthington", last_name) def test_parallel_assignments_with_fewer_values(self): title, *first_names, last_name = ["Mr", "Bond"] - self.assertEqual(__, title) - self.assertEqual(__, first_names) - self.assertEqual(__, last_name) + self.assertEqual("Mr", title) + self.assertEqual([], first_names) + self.assertEqual("Bond", last_name) def test_parallel_assignments_with_sublists(self): first_name, last_name = [["Willie", "Rae"], "Johnson"] - self.assertEqual(__, first_name) - self.assertEqual(__, last_name) + self.assertEqual(["Willie", "Rae"], first_name) + self.assertEqual("Johnson", last_name) def test_swapping_with_parallel_assignment(self): first_name = "Roy" last_name = "Rob" first_name, last_name = last_name, first_name - self.assertEqual(__, first_name) - self.assertEqual(__, last_name) + self.assertEqual("Rob", first_name) + self.assertEqual("Roy", last_name) diff --git a/koans/about_lists.py b/koans/about_lists.py index 61cc3bb29..2bb7e0bdc 100644 --- a/koans/about_lists.py +++ b/koans/about_lists.py @@ -11,7 +11,7 @@ class AboutLists(Koan): def test_creating_lists(self): empty_list = list() self.assertEqual(list, type(empty_list)) - self.assertEqual(__, len(empty_list)) + self.assertEqual(0, len(empty_list)) def test_list_literals(self): nums = list() @@ -21,70 +21,70 @@ def test_list_literals(self): self.assertEqual([1], nums) nums[1:] = [2] - self.assertListEqual([1, __], nums) + self.assertListEqual([1, 2], nums) nums.append(333) - self.assertListEqual([1, 2, __], nums) + self.assertListEqual([1, 2, 333], nums) def test_accessing_list_elements(self): noms = ['peanut', 'butter', 'and', 'jelly'] - self.assertEqual(__, noms[0]) - self.assertEqual(__, noms[3]) - self.assertEqual(__, noms[-1]) - self.assertEqual(__, noms[-3]) + self.assertEqual("peanut", noms[0]) + self.assertEqual("jelly", noms[3]) + self.assertEqual("jelly", noms[-1]) + self.assertEqual("butter", noms[-3]) def test_slicing_lists(self): noms = ['peanut', 'butter', 'and', 'jelly'] - self.assertEqual(__, noms[0:1]) - self.assertEqual(__, noms[0:2]) - self.assertEqual(__, noms[2:2]) - self.assertEqual(__, noms[2:20]) - self.assertEqual(__, noms[4:0]) - self.assertEqual(__, noms[4:100]) - self.assertEqual(__, noms[5:0]) + self.assertEqual(["peanut"], noms[0:1]) + self.assertEqual(['peanut',"butter"], noms[0:2]) + self.assertEqual([], noms[2:2]) + self.assertEqual(['and', 'jelly'], noms[2:20]) + self.assertEqual([], noms[4:0]) + self.assertEqual([], noms[4:100]) + self.assertEqual([], noms[5:0]) def test_slicing_to_the_edge(self): noms = ['peanut', 'butter', 'and', 'jelly'] - self.assertEqual(__, noms[2:]) - self.assertEqual(__, noms[:2]) + self.assertEqual(['and', 'jelly'], noms[2:]) + self.assertEqual(['peanut', 'butter'], noms[:2]) def test_lists_and_ranges(self): self.assertEqual(range, type(range(5))) self.assertNotEqual([1, 2, 3, 4, 5], range(1,6)) - self.assertEqual(__, list(range(5))) - self.assertEqual(__, list(range(5, 9))) + self.assertEqual([0, 1, 2, 3, 4], list(range(5))) + self.assertEqual([5, 6, 7, 8], list(range(5, 9))) def test_ranges_with_steps(self): - self.assertEqual(__, list(range(5, 3, -1))) - self.assertEqual(__, list(range(0, 8, 2))) - self.assertEqual(__, list(range(1, 8, 3))) - self.assertEqual(__, list(range(5, -7, -4))) - self.assertEqual(__, list(range(5, -8, -4))) + self.assertEqual([5, 4], list(range(5, 3, -1))) + self.assertEqual([0, 2, 4, 6], list(range(0, 8, 2))) + self.assertEqual([1, 4, 7], list(range(1, 8, 3))) + self.assertEqual([5, 1, -3], list(range(5, -7, -4))) + self.assertEqual([5, 1, -3, -7], list(range(5, -8, -4))) def test_insertions(self): knight = ['you', 'shall', 'pass'] knight.insert(2, 'not') - self.assertEqual(__, knight) + self.assertEqual(["you","shall", "not", "pass"], knight) knight.insert(0, 'Arthur') - self.assertEqual(__, knight) + self.assertEqual(['Arthur',"you","shall", "not", "pass"], knight) def test_popping_lists(self): stack = [10, 20, 30, 40] stack.append('last') - self.assertEqual(__, stack) + self.assertEqual([10,20,30,40, 'last'], stack) popped_value = stack.pop() - self.assertEqual(__, popped_value) - self.assertEqual(__, stack) + self.assertEqual('last', popped_value) + self.assertEqual([10,20,30,40], stack) popped_value = stack.pop(1) - self.assertEqual(__, popped_value) - self.assertEqual(__, stack) + self.assertEqual(20, popped_value) + self.assertEqual([10,30,40], stack) # Notice that there is a "pop" but no "push" in python? @@ -98,11 +98,11 @@ def test_making_queues(self): queue = [1, 2] queue.append('last') - self.assertEqual(__, queue) + self.assertEqual([1,2, 'last'], queue) popped_value = queue.pop(0) - self.assertEqual(__, popped_value) - self.assertEqual(__, queue) + self.assertEqual(1, popped_value) + self.assertEqual([2, 'last'], queue) # Note, popping from the left hand side of a list is # inefficient. Use collections.deque instead. diff --git a/koans/about_methods.py b/koans/about_methods.py index 796a07ea5..9d4eda732 100644 --- a/koans/about_methods.py +++ b/koans/about_methods.py @@ -12,7 +12,7 @@ def my_global_function(a,b): class AboutMethods(Koan): def test_calling_a_global_function(self): - self.assertEqual(__, my_global_function(2,3)) + self.assertEqual(5, my_global_function(2,3)) # NOTE: Wrong number of arguments is not a SYNTAX error, but a # runtime error. @@ -33,7 +33,8 @@ def test_calling_functions_with_wrong_number_of_arguments(self): msg = e.args[0] # Note, watch out for parenthesis. They need slashes in front! - self.assertRegex(msg, __) + self.assertRegex(msg,'my_global_function\(\) takes 2 positional arguments but 3 were given') + # ------------------------------------------------------------------ @@ -41,7 +42,7 @@ def pointless_method(self, a, b): sum = a + b def test_which_does_not_return_anything(self): - self.assertEqual(__, self.pointless_method(1, 2)) + self.assertEqual(None, self.pointless_method(1, 2)) # Notice that methods accessed from class scope do not require # you to pass the first "self" argument? @@ -51,8 +52,8 @@ def method_with_defaults(self, a, b='default_value'): return [a, b] def test_calling_with_default_values(self): - self.assertEqual(__, self.method_with_defaults(1)) - self.assertEqual(__, self.method_with_defaults(1, 2)) + self.assertEqual([1,'default_value'], self.method_with_defaults(1)) + self.assertEqual([1,2], self.method_with_defaults(1, 2)) # ------------------------------------------------------------------ @@ -60,9 +61,9 @@ def method_with_var_args(self, *args): return args def test_calling_with_variable_arguments(self): - self.assertEqual(__, self.method_with_var_args()) + self.assertEqual((), self.method_with_var_args()) self.assertEqual(('one',), self.method_with_var_args('one')) - self.assertEqual(__, self.method_with_var_args('one', 'two')) + self.assertEqual(('one', 'two'), self.method_with_var_args('one', 'two')) # ------------------------------------------------------------------ @@ -73,13 +74,13 @@ def test_functions_without_self_arg_are_global_functions(self): def function_with_the_same_name(a, b): return a * b - self.assertEqual(__, function_with_the_same_name(3,4)) + self.assertEqual(12, function_with_the_same_name(3,4)) def test_calling_methods_in_same_class_with_explicit_receiver(self): def function_with_the_same_name(a, b): return a * b - self.assertEqual(__, self.function_with_the_same_name(3,4)) + self.assertEqual(7, self.function_with_the_same_name(3,4)) # ------------------------------------------------------------------ @@ -92,10 +93,10 @@ def another_method_with_the_same_name(self): return 42 def test_that_old_methods_are_hidden_by_redefinitions(self): - self.assertEqual(__, self.another_method_with_the_same_name()) + self.assertEqual(42, self.another_method_with_the_same_name()) def test_that_overlapped_method_is_still_there(self): - self.assertEqual(__, self.link_to_overlapped_method()) + self.assertEqual(10, self.link_to_overlapped_method()) # ------------------------------------------------------------------ @@ -103,21 +104,21 @@ def empty_method(self): pass def test_methods_that_do_nothing_need_to_use_pass_as_a_filler(self): - self.assertEqual(__, self.empty_method()) + self.assertEqual(None, self.empty_method()) def test_pass_does_nothing_at_all(self): "You" "shall" "not" pass - self.assertEqual(____, "Still got to this line" != None) + self.assertEqual(True, "Still got to this line" != None) # ------------------------------------------------------------------ def one_line_method(self): return 'Madagascar' def test_no_indentation_required_for_one_line_statement_bodies(self): - self.assertEqual(__, self.one_line_method()) + self.assertEqual('Madagascar', self.one_line_method()) # ------------------------------------------------------------------ @@ -126,7 +127,7 @@ def method_with_documentation(self): return "ok" def test_the_documentation_can_be_viewed_with_the_doc_method(self): - self.assertRegex(self.method_with_documentation.__doc__, __) + self.assertRegex(self.method_with_documentation.__doc__,'A string placed at the beginning of a function is used for documentation') # ------------------------------------------------------------------ @@ -143,20 +144,20 @@ def __password(self): def test_calling_methods_in_other_objects(self): rover = self.Dog() - self.assertEqual(__, rover.name()) + self.assertEqual('Fido', rover.name()) def test_private_access_is_implied_but_not_enforced(self): rover = self.Dog() # This is a little rude, but legal - self.assertEqual(__, rover._tail()) + self.assertEqual("wagging", rover._tail()) def test_attributes_with_double_underscore_prefixes_are_subject_to_name_mangling(self): rover = self.Dog() - with self.assertRaises(___): password = rover.__password() + with self.assertRaises(AttributeError): password = rover.__password() # But this still is! - self.assertEqual(__, rover._Dog__password()) + self.assertEqual('password', rover._Dog__password()) # Name mangling exists to avoid name clash issues when subclassing. # It is not for providing effective access protection diff --git a/koans/about_none.py b/koans/about_none.py index 1731f0108..cf230cef9 100644 --- a/koans/about_none.py +++ b/koans/about_none.py @@ -11,11 +11,11 @@ class AboutNone(Koan): def test_none_is_an_object(self): "Unlike NULL in a lot of languages" - self.assertEqual(__, isinstance(None, object)) + self.assertEqual(True, isinstance(None, object)) def test_none_is_universal(self): "There is only one None" - self.assertEqual(____, None is None) + self.assertEqual(True, None is None) def test_what_exception_do_you_get_when_calling_nonexistent_methods(self): """ @@ -37,15 +37,15 @@ def test_what_exception_do_you_get_when_calling_nonexistent_methods(self): # # https://github.com/gregmalcolm/python_koans/wiki/Class-Attribute - self.assertEqual(__, ex2.__class__) + self.assertEqual(AttributeError, ex2.__class__) # What message was attached to the exception? # (HINT: replace __ with part of the error message.) - self.assertRegex(ex2.args[0], __) + self.assertRegex(ex2.args[0], "object has no attribute") def test_none_is_distinct(self): """ None is distinct from other things which are False. """ - self.assertEqual(__, None is not 0) - self.assertEqual(__, None is not False) + self.assertEqual(True, None is not 0) + self.assertEqual(True, None is not False) diff --git a/koans/about_sets.py b/koans/about_sets.py index 87cf10959..2986f8d24 100644 --- a/koans/about_sets.py +++ b/koans/about_sets.py @@ -9,27 +9,27 @@ def test_sets_make_keep_lists_unique(self): there_can_only_be_only_one = set(highlanders) - self.assertEqual(__, there_can_only_be_only_one) + self.assertEqual({'MacLeod', 'Malcolm', 'Matunas', 'Ramirez'}, there_can_only_be_only_one) def test_empty_sets_have_different_syntax_to_populated_sets(self): - self.assertEqual(__, {1, 2, 3}) - self.assertEqual(__, set()) + self.assertEqual({1, 2, 3}, {1, 2, 3}) + self.assertEqual( set(), set()) def test_dictionaries_and_sets_use_same_curly_braces(self): # Note: Literal sets using braces were introduced in python 3. # They were also backported to python 2.7. - self.assertEqual(__, {1, 2, 3}.__class__) - self.assertEqual(__, {'one': 1, 'two': 2}.__class__) + self.assertEqual(set, {1, 2, 3}.__class__) + self.assertEqual(dict, {'one': 1, 'two': 2}.__class__) - self.assertEqual(__, {}.__class__) + self.assertEqual(dict, {}.__class__) def test_creating_sets_using_strings(self): - self.assertEqual(__, {'12345'}) - self.assertEqual(__, set('12345')) + self.assertEqual({'12345'}, {'12345'}) + self.assertEqual(({'4', '1', '5', '3', '2'}), set('12345')) def test_convert_the_set_into_a_list_to_sort_it(self): - self.assertEqual(__, sorted(set('12345'))) + self.assertEqual(['1', '2', '3', '4', '5'], sorted(set('12345'))) # ------------------------------------------------------------------ @@ -37,19 +37,19 @@ def test_set_have_arithmetic_operators(self): scotsmen = {'MacLeod', 'Wallace', 'Willie'} warriors = {'MacLeod', 'Wallace', 'Leonidas'} - self.assertEqual(__, scotsmen - warriors) - self.assertEqual(__, scotsmen | warriors) - self.assertEqual(__, scotsmen & warriors) - self.assertEqual(__, scotsmen ^ warriors) + self.assertEqual({'Willie'}, scotsmen - warriors) + self.assertEqual({'Leonidas','MacLeod','Willie','Wallace'}, scotsmen | warriors) + self.assertEqual({'MacLeod', 'Wallace'}, scotsmen & warriors) + self.assertEqual({'Willie', 'Leonidas'}, scotsmen ^ warriors) # ------------------------------------------------------------------ def test_we_can_query_set_membership(self): - self.assertEqual(__, 127 in {127, 0, 0, 1} ) - self.assertEqual(__, 'cow' not in set('apocalypse now') ) + self.assertEqual(True, 127 in {127, 0, 0, 1} ) + self.assertEqual(True, 'cow' not in set('apocalypse now') ) def test_we_can_compare_subsets(self): - self.assertEqual(__, set('cake') <= set('cherry cake')) - self.assertEqual(__, set('cake').issubset(set('cherry cake')) ) + self.assertEqual(True, set('cake') <= set('cherry cake')) + self.assertEqual(True, set('cake').issubset(set('cherry cake')) ) - self.assertEqual(__, set('cake') > set('pie')) + self.assertEqual(False, set('cake') > set('pie')) diff --git a/koans/about_string_manipulation.py b/koans/about_string_manipulation.py index 5204f29ba..7468c9ead 100644 --- a/koans/about_string_manipulation.py +++ b/koans/about_string_manipulation.py @@ -9,13 +9,13 @@ def test_use_format_to_interpolate_variables(self): value1 = 'one' value2 = 2 string = "The values are {0} and {1}".format(value1, value2) - self.assertEqual(__, string) + self.assertEqual('The values are one and 2', string) def test_formatted_values_can_be_shown_in_any_order_or_be_repeated(self): value1 = 'doh' value2 = 'DOH' string = "The values are {1}, {0}, {0} and {1}!".format(value1, value2) - self.assertEqual(__, string) + self.assertEqual('The values are DOH, doh, doh and DOH!', string) def test_any_python_expression_may_be_interpolated(self): import math # import a standard python module with math functions @@ -23,24 +23,24 @@ def test_any_python_expression_may_be_interpolated(self): decimal_places = 4 string = "The square root of 5 is {0:.{1}f}".format(math.sqrt(5), decimal_places) - self.assertEqual(__, string) + self.assertEqual('The square root of 5 is 2.2361', string) def test_you_can_get_a_substring_from_a_string(self): string = "Bacon, lettuce and tomato" - self.assertEqual(__, string[7:10]) + self.assertEqual('let', string[7:10]) def test_you_can_get_a_single_character_from_a_string(self): string = "Bacon, lettuce and tomato" - self.assertEqual(__, string[1]) + self.assertEqual('a', string[1]) def test_single_characters_can_be_represented_by_integers(self): - self.assertEqual(__, ord('a')) - self.assertEqual(__, ord('b') == (ord('a') + 1)) + self.assertEqual(97, ord('a')) + self.assertEqual(True, ord('b') == (ord('a') + 1)) def test_strings_can_be_split(self): string = "Sausage Egg Cheese" words = string.split() - self.assertListEqual([__, __, __], words) + self.assertListEqual(['Sausage', 'Egg', 'Cheese'], words) def test_strings_can_be_split_with_different_patterns(self): import re #import python regular expression library @@ -50,25 +50,25 @@ def test_strings_can_be_split_with_different_patterns(self): words = pattern.split(string) - self.assertListEqual([__, __, __, __], words) + self.assertListEqual(['the', 'rain', 'in', 'spain'], words) # Pattern is a Python regular expression pattern which matches ',' or ';' def test_raw_strings_do_not_interpret_escape_characters(self): string = r'\n' self.assertNotEqual('\n', string) - self.assertEqual(__, string) - self.assertEqual(__, len(string)) + self.assertEqual('\\n', string) + self.assertEqual(2, len(string)) # Useful in regular expressions, file paths, URLs, etc. def test_strings_can_be_joined(self): words = ["Now", "is", "the", "time"] - self.assertEqual(__, ' '.join(words)) + self.assertEqual('Now is the time', ' '.join(words)) def test_strings_can_change_case(self): - self.assertEqual(__, 'guido'.capitalize()) - self.assertEqual(__, 'guido'.upper()) - self.assertEqual(__, 'TimBot'.lower()) - self.assertEqual(__, 'guido van rossum'.title()) - self.assertEqual(__, 'ToTaLlY aWeSoMe'.swapcase()) + self.assertEqual('Guido', 'guido'.capitalize()) + self.assertEqual('GUIDO', 'guido'.upper()) + self.assertEqual('timbot', 'TimBot'.lower()) + self.assertEqual('Guido Van Rossum', 'guido van rossum'.title()) + self.assertEqual('tOtAlLy AwEsOmE', 'ToTaLlY aWeSoMe'.swapcase()) diff --git a/koans/about_strings.py b/koans/about_strings.py index 25f5f59df..8718f1d65 100644 --- a/koans/about_strings.py +++ b/koans/about_strings.py @@ -6,89 +6,90 @@ class AboutStrings(Koan): def test_double_quoted_strings_are_strings(self): - string = "Hello, world." - self.assertEqual(__, isinstance(string, str)) + my_var = "Hello, world." + is_string = isinstance(my_var, str) + self.assertEqual(True, is_string) def test_single_quoted_strings_are_also_strings(self): string = 'Goodbye, world.' - self.assertEqual(__, isinstance(string, str)) + self.assertEqual(True, isinstance(string, str)) def test_triple_quote_strings_are_also_strings(self): string = """Howdy, world!""" - self.assertEqual(__, isinstance(string, str)) + self.assertEqual(True, isinstance(string, str)) def test_triple_single_quotes_work_too(self): string = '''Bonjour tout le monde!''' - self.assertEqual(__, isinstance(string, str)) + self.assertEqual(True, isinstance(string, str)) def test_raw_strings_are_also_strings(self): string = r"Konnichi wa, world!" - self.assertEqual(__, isinstance(string, str)) + self.assertEqual(True, isinstance(string, str)) def test_use_single_quotes_to_create_string_with_double_quotes(self): string = 'He said, "Go Away."' - self.assertEqual(__, string) + self.assertEqual('He said, "Go Away."', string) def test_use_double_quotes_to_create_strings_with_single_quotes(self): string = "Don't" - self.assertEqual(__, string) + self.assertEqual("Don't", string) def test_use_backslash_for_escaping_quotes_in_strings(self): a = "He said, \"Don't\"" b = 'He said, "Don\'t"' - self.assertEqual(__, (a == b)) + self.assertEqual(True, (a == b)) def test_use_backslash_at_the_end_of_a_line_to_continue_onto_the_next_line(self): string = "It was the best of times,\n\ It was the worst of times." - self.assertEqual(__, len(string)) + self.assertEqual(52, len(string)) def test_triple_quoted_strings_can_span_lines(self): string = """ Howdy, world! """ - self.assertEqual(__, len(string)) + self.assertEqual(15, len(string)) def test_triple_quoted_strings_need_less_escaping(self): a = "Hello \"world\"." b = """Hello "world".""" - self.assertEqual(__, (a == b)) + self.assertEqual(True, (a == b)) def test_escaping_quotes_at_the_end_of_triple_quoted_string(self): string = """Hello "world\"""" - self.assertEqual(__, string) + self.assertEqual("""Hello \"world\"""", string) def test_plus_concatenates_strings(self): string = "Hello, " + "world" - self.assertEqual(__, string) + self.assertEqual("Hello, world", string) def test_adjacent_strings_are_concatenated_automatically(self): string = "Hello" ", " "world" - self.assertEqual(__, string) + self.assertEqual("Hello, world", string) def test_plus_will_not_modify_original_strings(self): hi = "Hello, " there = "world" string = hi + there - self.assertEqual(__, hi) - self.assertEqual(__, there) + self.assertEqual("Hello, ", hi) + self.assertEqual("world", there) def test_plus_equals_will_append_to_end_of_string(self): hi = "Hello, " there = "world" hi += there - self.assertEqual(__, hi) + self.assertEqual("Hello, world", hi) def test_plus_equals_also_leaves_original_string_unmodified(self): original = "Hello, " hi = original there = "world" hi += there - self.assertEqual(__, original) + self.assertEqual("Hello, ", original) def test_most_strings_interpret_escape_characters(self): string = "\n" self.assertEqual('\n', string) self.assertEqual("""\n""", string) - self.assertEqual(__, len(string)) + self.assertEqual(1, len(string)) diff --git a/koans/about_true_and_false.py b/koans/about_true_and_false.py index 5f06a63db..9467caf51 100644 --- a/koans/about_true_and_false.py +++ b/koans/about_true_and_false.py @@ -12,32 +12,32 @@ def truth_value(self, condition): return 'false stuff' def test_true_is_treated_as_true(self): - self.assertEqual(__, self.truth_value(True)) + self.assertEqual('true stuff', self.truth_value(True)) def test_false_is_treated_as_false(self): - self.assertEqual(__, self.truth_value(False)) + self.assertEqual('false stuff', self.truth_value(False)) def test_none_is_treated_as_false(self): - self.assertEqual(__, self.truth_value(None)) + self.assertEqual('false stuff', self.truth_value(None)) def test_zero_is_treated_as_false(self): - self.assertEqual(__, self.truth_value(0)) + self.assertEqual('false stuff', self.truth_value(0)) def test_empty_collections_are_treated_as_false(self): - self.assertEqual(__, self.truth_value([])) - self.assertEqual(__, self.truth_value(())) - self.assertEqual(__, self.truth_value({})) - self.assertEqual(__, self.truth_value(set())) + self.assertEqual('false stuff', self.truth_value([])) + self.assertEqual('false stuff', self.truth_value(())) + self.assertEqual('false stuff', self.truth_value({})) + self.assertEqual('false stuff', self.truth_value(set())) def test_blank_strings_are_treated_as_false(self): - self.assertEqual(__, self.truth_value("")) + self.assertEqual('false stuff', self.truth_value("")) def test_everything_else_is_treated_as_true(self): - self.assertEqual(__, self.truth_value(1)) - self.assertEqual(__, self.truth_value([0])) - self.assertEqual(__, self.truth_value((0,))) + self.assertEqual('true stuff', self.truth_value(1)) + self.assertEqual('true stuff', self.truth_value([0])) + self.assertEqual('true stuff', self.truth_value((0,))) self.assertEqual( - __, + 'true stuff', self.truth_value("Python is named after Monty Python")) - self.assertEqual(__, self.truth_value(' ')) - self.assertEqual(__, self.truth_value('0')) + self.assertEqual('true stuff', self.truth_value(' ')) + self.assertEqual('true stuff', self.truth_value('0')) diff --git a/koans/about_tuples.py b/koans/about_tuples.py index 1b38c8f7f..23b3b8c83 100644 --- a/koans/about_tuples.py +++ b/koans/about_tuples.py @@ -6,7 +6,7 @@ class AboutTuples(Koan): def test_creating_a_tuple(self): count_of_three = (1, 2, 5) - self.assertEqual(__, count_of_three[2]) + self.assertEqual(5, count_of_three[2]) def test_tuples_are_immutable_so_item_assignment_is_not_possible(self): @@ -19,11 +19,11 @@ def test_tuples_are_immutable_so_item_assignment_is_not_possible(self): # Note, assertRegex() uses regular expression pattern matching, # so you don't have to copy the whole message. - self.assertRegex(msg, __) + self.assertRegex(msg, 'object does not support item assignment') def test_tuples_are_immutable_so_appending_is_not_possible(self): count_of_three = (1, 2, 5) - with self.assertRaises(___): count_of_three.append("boom") + with self.assertRaises(AttributeError): count_of_three.append("boom") # Tuples are less flexible than lists, but faster. @@ -34,26 +34,26 @@ def test_tuples_can_only_be_changed_through_replacement(self): list_count.append("boom") count_of_three = tuple(list_count) - self.assertEqual(__, count_of_three) + self.assertEqual((1,2,5, 'boom'), count_of_three) def test_tuples_of_one_look_peculiar(self): - self.assertEqual(__, (1).__class__) - self.assertEqual(__, (1,).__class__) - self.assertEqual(__, ("I'm a tuple",).__class__) - self.assertEqual(__, ("Not a tuple").__class__) + self.assertEqual(int, (1).__class__) + self.assertEqual(tuple, (1,).__class__) + self.assertEqual(tuple, ("I'm a tuple",).__class__) + self.assertEqual(str, ("Not a tuple").__class__) def test_tuple_constructor_can_be_surprising(self): - self.assertEqual(__, tuple("Surprise!")) + self.assertEqual(('S', 'u', 'r', 'p', 'r', 'i', 's', 'e', '!'), tuple("Surprise!")) def test_creating_empty_tuples(self): - self.assertEqual(__ , ()) - self.assertEqual(__ , tuple()) # Sometimes less confusing + self.assertEqual(() , ()) + self.assertEqual((), tuple()) # Sometimes less confusing def test_tuples_can_be_embedded(self): lat = (37, 14, 6, 'N') lon = (115, 48, 40, 'W') place = ('Area 51', lat, lon) - self.assertEqual(__, place) + self.assertEqual(('Area 51', (37, 14, 6, 'N'), (115, 48, 40, 'W')), place) def test_tuples_are_good_for_representing_records(self): locations = [ @@ -63,5 +63,5 @@ def test_tuples_are_good_for_representing_records(self): locations.append( ("Cthulu", (26, 40, 1, 'N'), (70, 45, 7, 'W')) ) - self.assertEqual(__, locations[2][0]) - self.assertEqual(__, locations[0][1][2]) + self.assertEqual('Cthulu', locations[2][0]) + self.assertEqual( 15.56, locations[0][1][2]) diff --git a/koans/triangle.py b/koans/triangle.py index 4d8d66f42..33c93e36e 100644 --- a/koans/triangle.py +++ b/koans/triangle.py @@ -18,7 +18,22 @@ # def triangle(a, b, c): # DELETE 'PASS' AND WRITE THIS CODE - pass + #pass + if a <= 0 or b <= 0 or c <= 0: + raise TriangleError("All sides must be greater than 0") + + # The sum of any two sides should be greater than the third one + + if a+b <= c or b+c <= a or a+c <= b: + raise TriangleError('The sum of any two sides should be greater than the third one') + + if a == b and b == c: + return 'equilateral' + elif a == b or b == c or a == c: + return 'isosceles' + else: + return 'scalene' + # Error class used in part 2. No need to change this code. class TriangleError(Exception): diff --git a/learn_python_by_test.py b/learn_python_by_test.py new file mode 100644 index 000000000..592b33973 --- /dev/null +++ b/learn_python_by_test.py @@ -0,0 +1,253 @@ +def test_basic(): + assert True != False + + +def test_types_are_important(): + assert '1' == "1" + + +def test_types_can_be_converted(): + assert str(1) == "1" + + +def test_numbers_operations(): + assert 3 * 2 == 6 + assert 9 + 3 == 12 + + +def test_string_operations(): + assert 3 * 2 == 6 + + +def test_vars(): + my_var = 1 + assert my_var == 1 + my_var = "a" + assert my_var == 'a' + + +def test_list_is_a_complex_types(): + my_list = [1, 2, 3] + assert my_list[0] == 1 + + a = 1 + my_list = [a + 1, a + 2, a + 3] + assert my_list[0] == 2 + + a = "b" + b = "c" + c = "d" + my_list = [a, b, c] + assert my_list == ["b", "c", "d"] + + +def test_dict_is_a_complext_type(): + a = "a" + b = "d" + my_dict = {a: 1, "b": 2, b: 3} + assert my_dict[a] == 1 + assert my_dict.get('b') == 2 + assert my_dict.get("d", 0) == 3 + + assert my_dict.get("c") == None + #assert my_dict[c] == None + + +def test_function(): + def my_fn(): + return 1 + + assert my_fn() == 1 + #assert my_fn(2) == 2 + + def my_fn2(): + return 2 + + assert my_fn2() == 2 + + +def test_function_with_args(): + def my_fn(a): + return a + + assert my_fn(2) == 2 + + def my_sum(a,b): + return a + b + + assert my_sum(1,2) == 3 + + def my_fn2(a, b, c): + return [a, b, c] + + assert my_fn2(1, 2, 3) == [1, 2, 3] + + +def test_function_can_have_side_effects(): + def my_fn(d): + # d["a"] = 4 + dd = d.copy() + dd["a"] = 4 + return dd + + d = {"a": 1, "b": 2} + dd = my_fn(d) + # assert dd == None + assert d["a"] == 1 + assert dd["a"] == 4 + + l = [2, 3, 1] + ll = sorted(l) + assert ll != l + + l.sort() + assert l == [1, 2, 3] + assert ll == l + + +def test_good_functions_do_not_have_side_effects(): + my_var = 1 + new_var = str(my_var) + assert new_var == "1" + + def sum1(b): + b = b + 1 + return b + + a = 1 + c = sum1(a) + assert c == 2 + assert a == 1 + + my_var = "3" + new_val = int(my_var) + assert new_val == 3 + + +def test_simple_types_are_copied_by_value(): + a = 1 + b = a + a = a + 1 + assert a != b + + +def test_complex_types_are_copied_by_reference(): + a = [1, 2, 3] + b = a.copy() + a[0] = 4 + assert b == [1, 2, 3] + + d = {"a": 1} + dd = d + dd["a"] = 4 + dd["b"] = 1 + assert d["a"] == 1 + assert d["b"] == None + + +def test_objects_have_methods(): + b = "abc" + assert b.capitalize() == "ABC" + assert b.replace("a", "z") != "zba" + + b = "123" + c = int(b) + assert "".join([*reversed(c)]) == "321" + + +def test_objects_are_class_instances(): + class MyClass(): + pass + + obj = MyClass() + assert isinstance(obj, MyClass) != True + + +def my_sum(a, b): + tot = a + b + return tot + #pass + +def test_function_sum(): + assert my_sum(1,2) == 3 + +def test_function_sum_many_times(): + for (a, b, res) in [(2,4,6), (3,4,7), (5,10,15)]: + assert my_sum(a,b) == res + +def validate_hello(greetings): + greetings_lower_case = greetings.lower() + + if 'hello' in greetings_lower_case: + return True + if 'ciao' in greetings_lower_case: + return True + if 'salut' in greetings_lower_case: + return True + if 'hallo' in greetings_lower_case: + return True + if 'hola' in greetings_lower_case: + return True + if 'ahoj' in greetings_lower_case: + return True + if 'czesc' in greetings_lower_case: + return True + + return False + +def test_greetings(): + for stocazzo, exp in [('hello',True), ('ciao bella!',True), ('salut',True), + ('hallo, salut',True), ('hombre! Hola!',True), + ('Hallo, wie geht\'s dir?',True), ('AHOJ!',True), + ('czesc',True), ('meh',False), ('Ahoj',True), ]: + assert validate_hello(stocazzo) == exp + + +def even_numbers(arr,n): + only_even_numbers = [] + for numbers in arr[::-1]: + if numbers % 2 == 0: + only_even_numbers.append(numbers) + if len(only_even_numbers) == n: + break + return only_even_numbers + + +# test.assert_equals(even_numbers([1, 2, 3, 4, 5, 6, 7, 8, 9], 3), [4, 6, 8]); +def test_hfrc(): + assert [8, 6, 4] == [8, 6, 4] + + + +def findSum(str1): + empty_str = "0" + #Sum = 0 + for ch in str1: + if (ch.isdigit()): + empty_str += ch + + #else: + #Sum += int(empty_str) + #empty_str = "0" + + return str(empty_str) + +def test_sum(): + assert (findSum('1plus2plus3plus4'), '10') + +def how_much_i_love_you(nb_petals): + last_petal = { + 1 : "I love you", + 2 : "a little", + 3 : "a lot", + 4 : "passionately", + 5 : "madly", + 6 : "not at all" + } + + return last_petal.get(nb_petals) + +def test_cases(): +# test.assert_equals(how_much_i_love_you(7),"I love you") + assert how_much_i_love_you(3) == "a lot" + assert how_much_i_love_you(6) == "not at all" \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 000000000..ced23a2cc --- /dev/null +++ b/main.py @@ -0,0 +1,6 @@ +print('Hello') + +def hello(): + print(hello) + +hello() \ No newline at end of file diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/is_leap_year.py b/src/is_leap_year.py new file mode 100644 index 000000000..2c51498c7 --- /dev/null +++ b/src/is_leap_year.py @@ -0,0 +1,4 @@ +def is_leap_year(year): + if year % 4 == 0: + return True + return False \ No newline at end of file diff --git a/src/test_leap_year.py b/src/test_leap_year.py new file mode 100644 index 000000000..7b948b3a2 --- /dev/null +++ b/src/test_leap_year.py @@ -0,0 +1,10 @@ +from src.is_leap_year import is_leap_year + + +def test_is_not_leap_year(): + assert is_leap_year(1957) == False + +def test_is_divisible_by_4(): + assert is_leap_year(2008) == True + assert is_leap_year(2012) == True + assert is_leap_year(2016) == True \ No newline at end of file