def test_interaction_on_arrays(): # test inputs a = np.array([1, 0.5, 1. / 3, 0, 0.5, 1]) b = np.array([2, 0.75, 1, 2, 2.5, 4]) # expected interaction c = np.array([1, 0.25, 0.67, 4, 4, 9]) assert_array_almost_equal(interaction(a, b), c, 2)
def test_symmetric_on_arrays(): for a in np.arange(30).reshape((6, 5)): for b in np.arange(-3, 27).reshape((6, 5)): assert_array_almost_equal(interaction(a, b), interaction(b, a))
def test_symmetric(): for a in range(3): for b in range(-3, 2): assert_equals(interaction(a, b), interaction(b, a))
def test_far_interaction(): assert_equals(interaction(0, 2), 4) assert_equals(interaction(0.5, 2.5), 4) assert_equals(interaction(1, 4), 9)
def test_close_interaction(): assert_equals(interaction(1, 2), 1) assert_equals(interaction(0.5, 0.75), 0.25) assert_almost_equals(interaction(1. / 3, 1), 0.67, 2)
def test_far_interaction(): assert interaction(0, 2) == 4 assert interaction(0.5, 2.5) == 4 assert interaction(1, 4) == 9
def test_close_interaction(): assert interaction(1, 2) == 1 assert interaction(0.5, 0.75) == 0.25
def test_symmetric(): for a in range(3): for b in range(-3, 2): assert interaction(a, b) == interaction(b, a)