コード例 #1
0
    def test_vector_function_add_happy_path(self):
        def f(x, y):
            return x + y

        def g(x, y):
            return x + y + 1

        vector_f = Function2(f)
        vector_g = Function2(g)

        self.assertEqual((vector_f + vector_g)(5, 6), 23)
コード例 #2
0
    def test_vector_negate_happy_path(self):
        def f(x, y):
            return x + y

        vector_f = Function2(f)

        self.assertEqual(-vector_f(5, 6), -11)
コード例 #3
0
    def test_vector_function_mult_happy_path(self):
        def f(x, y):
            return x + y

        vector_f = Function2(f)

        self.assertEqual(5 * vector_f(5, 6), 55)
コード例 #4
0
 def test_approx_equal_function_happy_path_3(self):
     f = Function2(lambda x, y: x + y)
     g = Function2(lambda x, y: x - y + 1)
     h = Function2(lambda x, y: 2 * x + 1)
     self.assertTrue(self.approx_equal(f + g, h))
コード例 #5
0
 def test_approx_equal_function_happy_path_2(self):
     f1 = Function2(lambda x, y: x + y + 1)
     f2 = Function2(lambda x, y: sin(x) + sin(y))
     self.assertFalse(self.approx_equal(f1, f2))
コード例 #6
0
 def test_approx_equal_function_happy_path(self):
     f1 = Function2(lambda x, y: x + y + 1)
     f2 = Function2(lambda x, y: x + y + 0.5 * 2)
     self.assertTrue(self.approx_equal(f1, f2))
コード例 #7
0
 def test_zero_function_happy_path(self):
     vector_f0 = Function2.zero()
     for _ in range(0, 1000):
         self.assertEqual(
             vector_f0(self.random_scalar(), self.random_scalar()), 0)
コード例 #8
0
    def test_vector_function_creation_happy_path(self):
        def f(x, y):
            return x + y

        vector_f = Function2(f)
        self.assertEqual(vector_f(5, 7), 12)
コード例 #9
0
 def test_vector_function_creation_with_num(self):
     with self.assertRaises(
             TypeError,
             msg='should raise TypeError when passing non-function arg'):
         Function2(2)