Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions task_1/accumulate_tests.py
Original file line number Diff line number Diff line change
@@ -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()