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