From 4c42d4797cdbd0d50229f88da0b2d06e25243b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=A1=D1=82=D0=BE=D0=B8=D1=87=D0=BA=D0=BE=D0=B2?= Date: Thu, 10 Oct 2019 22:18:45 +0300 Subject: [PATCH] Add more tests for first challenge --- task_1/accumulate_tests.py | 83 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 task_1/accumulate_tests.py diff --git a/task_1/accumulate_tests.py b/task_1/accumulate_tests.py new file mode 100644 index 0000000..33781a9 --- /dev/null +++ b/task_1/accumulate_tests.py @@ -0,0 +1,83 @@ +import unittest +from solution import * + +class TestAccumulateLeft(unittest.TestCase): + # tuple tests left + def test_if_tuple_of_one_element_is_the_collection_given_and_addition_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_left(lambda a, b: a + b, 64, (2,)), 66.0) + + def test_if_tuple_of_one_hundred_elements_is_the_collection_given_and_addition_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_left(lambda a, b: a + b, 64, tuple(range(1, 501))), 125314.0) + + def test_if_tuple_is_the_collection_given_and_addition_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_left(lambda a, b: a + b, 64, (2, 4, 8)), 78.0) + + def test_if_tuple_is_the_collection_given_and_subtraction_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_left(lambda a, b: a - b, 64, (2, 4, 8)), 50.0) + + def test_if_tuple_is_the_collection_given_and_multiplication_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_left(lambda a, b: a * b, 64, (2, 4, 8)), 4096.0) + + def test_if_tuple_is_the_collection_given_and_division_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_left(lambda a, b: a / b, 64, (2, 4, 8)), 1.0) + + # list tests left + def test_if_list_of_one_element_is_the_collection_given_and_addition_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_left(lambda a, b: a + b, 64, [2]), 66.0) + + def test_if_list_of_one_hundred_elements_is_the_collection_given_and_addition_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_left(lambda a, b: a + b, 64, list(range(1, 501))), 125314.0) + + def test_if_list_is_the_collection_given_and_addition_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_left(lambda a, b: a + b, 64, [2, 4, 8]), 78.0) + + def test_if_list_is_the_collection_given_and_subtraction_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_left(lambda a, b: a - b, 64, [2, 4, 8]), 50.0) + + def test_if_list_is_the_collection_given_and_multiplication_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_left(lambda a, b: a * b, 64, [2, 4, 8]), 4096.0) + + def test_if_list_is_the_collection_given_and_division_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_left(lambda a, b: a / b, 64, [2, 4, 8]), 1.0) + +class TestAccumulateRight(unittest.TestCase): + # tuple tests right + def test_if_tuple_of_one_element_is_the_collection_given_and_addition_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_right(lambda a, b: a + b, 8, (2,)), 10.0) + + def test_if_tuple_of_five_hundred_elements_is_the_collection_given_and_addition_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_right(lambda a, b: a + b, 8, tuple(range(1, 501))), 125258.0) + + def test_if_tuple_is_the_collection_given_and_addition_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_right(lambda a, b: a + b, 8, (16, 32, 64)), 120.0) + + def test_if_tuple_is_the_collection_given_and_subtraction_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_right(lambda a, b: a - b, 8, (16, 32, 64)), 40.0) + + def test_if_tuple_is_the_collection_given_and_multiplication_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_right(lambda a, b: a * b, 8, (16, 32, 64)), 262144.0) + + def test_if_tuple_is_the_collection_given_and_division_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_right(lambda a, b: a / b, 8, (16, 32, 64)), 4.0) + + # list tests right + def test_if_list_of_one_element_is_the_collection_given_and_addition_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_right(lambda a, b: a + b, 8, [2]), 10.0) + + def test_if_list_of_five_hundred_elements_is_the_collection_given_and_addition_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_right(lambda a, b: a + b, 8, list(range(1, 501))), 125258.0) + + def test_if_list_is_the_collection_given_and_addition_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_right(lambda a, b: a + b, 8, [16, 32, 64]), 120.0) + + def test_if_list_is_the_collection_given_and_subtraction_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_right(lambda a, b: a - b, 8, [16, 32, 64]), 40.0) + + def test_if_list_is_the_collection_given_and_multiplication_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_right(lambda a, b: a * b, 8, [16, 32, 64]), 262144.0) + + def test_if_list_is_the_collection_given_and_division_is_the_operation_then_return_correct_result(self): + self.assertEqual(accumulate_right(lambda a, b: a / b, 8, [16, 32, 64]), 4.0) + +if __name__ == "__main__": + unittest.main() \ No newline at end of file