def test_CMF_main(monkeypatch): monkeypatch.setattr('sys.stdin', StringIO('-1\n1\n-1\n1\n1\n1\n8\n2\n2\n')) CMflow.main()
def test_CMF_identify(): assert isinstance(CMflow.identify_flow('source', np.array([1, 2, 3, 4])), CMflow.source)
def test_CMF_generate(): gradients_cart, phi = CMflow.generate_cart_gradients( [CMG(3, np.array([1, 0]))], np.array([[1, 0]])) assert isinstance(gradients_cart, np.ndarray) assert isinstance(phi, np.ndarray)
def test_CMF_tornado(): tor = CMflow.tornado('1', np.array([1, 2, 3, 4])) assert isinstance(tor.compute_flow(), CMflow.Flow_it)
def test_CMF_whirlpool(): assert isinstance(CMflow.whirlpool('1', np.array([1, 2, 3, 4])), CMflow.whirlpool)
def test_CMF_vortex(): vor = CMflow.vortex('1', np.array([1, 2, 3])) assert isinstance(vor.rule_out_points(np.array([[1, 0]])), np.ndarray) assert isinstance(vor.compute_flow(), CMflow.Flow_it)
def test_CMF_doublet(): dou = CMflow.doublet('1', np.array([1, 2, 3])) assert isinstance(dou.compute_flow(), CMflow.Flow_it)
def test_CMF_source(): src = CMflow.source('1', np.array([1, 2, 3, 4])) assert isinstance(src.rule_out_points(np.array([[1, 0]])), np.ndarray) assert isinstance(src.compute_flow(), CMflow.Flow_it)
def test_CMF_sink(): sink = CMflow.sink('1', np.array([1, 2, 3, 4])) assert isinstance(sink, CMflow.sink)
def test_CMF_flow(): flow = CMflow.Flow('1', np.array([1, 2])) assert flow._key == '1' assert flow._strength == 1 assert isinstance(flow.rule_out_points(np.array([[1, 0]])), np.ndarray)
def test_CMF_uniform(): uni = CMflow.uniform('1', np.array([1, 2])) assert isinstance(uni.rule_out_points(np.array([[1, 0]])), np.ndarray) assert isinstance(uni.compute_flow(), CMflow.Flow_it)
def test_CMF_flow_it(): flow = CMflow.Flow_it(np.array([1, 1])) assert isinstance(flow.flow, np.ndarray) assert flow.max_it == 2 assert list(iter(flow)) == [1, 1] assert list(iter(flow + np.array([1, 0]))) == [2, 1]
def test_CMF_pol2cart_grad(): grad = CMflow.pol2cart_grad(np.array([[2, np.pi / 3]]), np.array([[1, 0]])) # assert np.array_equal(np.round(grad, 8), np.round(np.array([2, ]), 8)) # assert shape, type assert (grad.shape[0], grad.shape[1]) == (1, 2)
def test_CMF_pol2cart(): cart = CMflow.pol2cart(np.array([[np.sqrt(2), np.pi / 4]])) assert np.array_equal(np.round(cart, 8), np.array([[1, 1]]))
def test_CMF_cart2pol_zero(): polar = CMflow.cart2pol(np.array([[0, 1]])) assert np.array_equal(np.round(polar[0], 8), np.round(np.array([1, np.pi / 2]), 8))
def test_CMF_cart2pol(): polar = CMflow.cart2pol(np.array([[1, 1]])) assert np.array_equal(np.round(polar[0], 8), np.round(np.array([np.sqrt(2), np.pi / 4]), 8))