def test_sum(self): sum1 = Sum([1, 2, 3, 4, 5]) sum2 = Sum([]) sum3 = Sum([1]) self.assertEqual(sum1.get_sum(), 15) self.assertEqual(sum2.get_sum(), 0) self.assertEqual(sum3.get_sum(), 1)
class TestSum(unittest.TestCase): def setUp(self): self.sum = Sum(8, 7) def test_forward(self): x = np.random.randn(self.sum.N, self.sum.D) self.assertEqual((1, 8), self.sum.forward(x).shape) def test_backward(self): dy = np.random.randn(1, self.sum.D) self.assertEqual((7, 8), self.sum.backward(dy).shape)
def create_addition_subtraction(sum_type): number_1 = randint(1, 100) number_2 = randint(1, 100) if sum_type == 1: sum_answer = add(number_1, number_2) else: if number_1 >= number_2: sum_answer = subtract(number_1, number_2) else: sum_answer = subtract(number_2, number_1) sum = Sum(number_2, number_1, sum_type, sum_answer) return sum sum = Sum(number_1, number_2, sum_type, sum_answer) return sum
def test_sum_plus_money(self): bank: Bank = Bank() bank.addRate("CHF", "USD", 2) sum: Expression = Sum(self.five_bucks, self.ten_flancs).plus(self.five_bucks) result: Money = bank.reduce(sum, "USD") self.assertEqual(Money.Dollar(15), result)
def test_sum_int_str_invalid(self): with self.assertRaises(TypeError): Sum().sumIntStr('2', ['2']) with self.assertRaises(ValueError): Sum().sumIntStr('a', '2')
def plus(self, addend: Expression) -> Expression: return Sum(self, addend)
def test_sum_reduce(self): sum: Sum = Sum(self.five_bucks, self.ten_flancs) self.assertFalse(sum.reduce(self.five_bucks, "USD"))
def test_reduce_sum(self): sum: Expression = Sum(Money.Dollar(3), Money.Dollar(4)) bank: Bank = Bank() result: Money = bank.reduce(sum, "USD") self.assertEqual(Money.Dollar(7).amount, result.amount)
def create_multiplication(sum_type): number_1 = randint(1, 10) number_2 = randint(1, 10) sum_answer = multiply(number_1, number_2) sum = Sum(number_1, number_2, sum_type, sum_answer) return sum
def test_sum_empty(self): num = [] actual = Sum(num).get_sum() expected = 0 self.assertEqual(actual, expected)
def setUp(self): self.sum = Sum(8, 7)
def test_sum_positive(self): nums = [1, 2, 3, 4] actual = Sum(nums).get_sum() expected = 10 self.assertEqual(actual, expected) self.assertEqual(actual, expected)
def test_sum_positive_with_None(self): nums = [1, 2, None, 4] actual = Sum(nums).get_sum() expected = 7 self.assertEqual(actual, expected)
def test_sum_single(self): num = [1] actual = Sum(num).get_sum() expected = 1 self.assertEqual(actual, expected)
def test_sum_int_str_valid(self): self.assertEqual(Sum().sumIntStr('3', '4'), 7) self.assertEqual(Sum().sumIntStr('3', '-3'), 0) self.assertEqual(Sum().sumIntStr('3', '-4'), -1) pass
def setUp(self): self.sum = Sum([1, 2, 3, 4, 5]).getSum() self.emp_sum = Sum().getSum() self.one_element_list = Sum([2]).getSum() self.multiple_list = Sum([2, 3, 4, 5]).getSum() self.none_list = Sum([None]).getSum()
def test_sum_negative(self): nums = [-1, -2, -3] actual = Sum(nums).get_sum() expected = -6 self.assertEqual(actual, expected)