def test_all_function_check(): import calculator assert calculator.sin(math.pi / 2) == 1 assert calculator.cos(math.pi) == -1 assert calculator.tan(0) == 0 assert calculator.tanh(0) == 0 assert calculator.softmax([1, 2]) == [0.2689414213699951, 0.7310585786300049] assert calculator.e(0) == 1 assert calculator.log(10, base=10) == 1 assert calculator.relu(10) == 10 assert calculator.relu(-10) == 0 assert calculator.sigmoid(0) == 0.5
def test_functions(): value = random.randint(-100, 100) value2 = random.randint(1, 100) assert round(c.sin(value)) == round(math.sin( value)), "Sin function is not working, you studied this in 10.." assert round(c.cos(value)) == round(math.cos( value)), "Cos function is not working, you studied this in 10.." assert round(c.tan(value)) == round(math.tan( value)), "Tan function is not working, you studied this in 10.." assert round(c.tanh(value)) == round(math.tanh( value)), "Tanh function is not working, you studied this in 10.." assert round(c.sigmoid(value)) == round( (1 / (1 + math.exp(-value)) )), "Sigmoid function is not working, this is the basic of DNN.." assert round(c.relu(value)) == round(max( 0, value)), "Relu function is not working, this is the basic of DNN,," assert round(c.log(value2)) == round(math.log( value2)), "Log function is not working, you studied this in 10.." assert round(c.e(value)) == round(math.exp( value)), "Exp function is not working, you studied this in 10.." assert [ 0.0003282279149649954, 0.0024252944769113903, 0.01792063694632493, 0.0008922159768423478, 0.9784336246849563 ] == c.softmax([1, 3, 5, 2, 9]), "Softmax not working bro.. how will you make NN then"
def test_relu_module(): assert 0.5 == calculator.relu( 0.5), "relu_func module from cal package is not working as expected" assert 0 == derivatives.d_relu( -20), "relu_funcmodule from cal package is not working as expected" assert 1 == derivatives.d_relu( 10), "relu_func module from cal package is not working as expected"
def test_relu(): """ Test the method relu in the calculator package :return: None """ output = calculator.relu(0) assert output == 0 output = derivatives.derivative_relu(0) assert output == 0
def test(): abs_tol = 0.001 rel_tol = 0.001 test_value = 25 # ================= testing sin ===================== assert math.isclose( calculator.sin(test_value), -0.132, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {calculator.sin(test_value)}', f'expected : {-0.132}') assert math.isclose( derivatives.sin(test_value), 0.991, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {derivatives.sin(test_value)}', f'expected : {0.991}') # ================= testing cosine ===================== assert math.isclose( calculator.cos(test_value), 0.991, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {calculator.cos(test_value)}', f'expected : {0.991}') assert math.isclose( derivatives.cos(test_value), 0.132, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {derivatives.cos(test_value)}', f'expected : {0.132}') # ================= testing exponential ===================== assert math.isclose( calculator.exp(test_value), 72004899337, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {calculator.exp(test_value)}', f'expected : {72004899337}') assert math.isclose( derivatives.exp(test_value), 72004899337, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {derivatives.exp(test_value)}', f'expected : {72004899337}') # ================= testing log ===================== assert math.isclose( calculator.log(test_value), 3.218, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {calculator.log(test_value)}', f'expected : {3.218}') assert math.isclose( derivatives.log(test_value), 0.04, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {derivatives.log(test_value)}', f'expected : {0.04}') # ================= testing relu ===================== assert math.isclose( calculator.relu(test_value), 25, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {calculator.relu(test_value)}', f'expected : {25}') assert math.isclose( derivatives.relu(test_value), 1, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {derivatives.relu(test_value)}', f'expected : {1}') # ================= testing sigmoid ===================== assert math.isclose( calculator.sigmoid(test_value), 0.999, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {calculator.sigmoid(test_value)}', f'expected : {0.999}') assert math.isclose( derivatives.sigmoid(test_value), 1.388794386457827062508E-11, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {derivatives.sigmoid(test_value)}', f'expected : {1.388794386457827062508E-11}') # ================= testing Softmax ===================== assert math.isclose( calculator.softmax(test_value), 1, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {calculator.softmax(test_value)}', f'expected : {1}') # assert math.isclose(derivatives.softmax(test_value), 0.04 , # rel_tol=abs_tol, # abs_tol=abs_tol),(f'actual : {derivatives.softmax(test_value)}', # f'expected : {0.04}' ) # ================= testing tan ===================== assert math.isclose( calculator.tan(test_value), -0.133, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {calculator.tan(test_value)}', f'expected : {-0.133}') assert math.isclose( derivatives.tan(test_value), 2.017, rel_tol=abs_tol, abs_tol=abs_tol), (f'actual : {derivatives.tan(test_value)}', f'expected : {2.017}')
def test_relu_import(): relu_output = calculator.relu(5) assert (relu_output == 5 ), "derivative of relu function has wrong implementation"
def test_function_drelu(): assert derivatives.drelu(calculator.relu(num)) == 0 if num <= 0 else 1 , 'dRelu implementaion failed'
def test_function_relu(): assert calculator.relu(num) == 0 if num < 0 else num , 'Relu implementaion failed'
def test_relu(): assert 3.14 == calc.relu(3.14), 'Check ReLU function'
def test_type_error(): with pytest.raises(TypeError, match=r".*Input value of invalid type*"): calculator.sin("60") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): calculator.cos("-45") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): calculator.tan("4.5") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): calculator.tanh("50") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): calculator.relu("1.3") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): calculator.sigmoid("2.4") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): calculator.euler("4") with pytest.raises(TypeError, match=r".*invalid type*"): calculator.softmax([10, "2", "3"]) with pytest.raises(TypeError, match=r".*Input value of invalid type*"): calculator.log("5", 10) with pytest.raises(TypeError, match=r".*Input value of invalid type*"): calculator.log(3, "10") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): derivatives.d_sin("45") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): derivatives.d_cos("4.5") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): derivatives.d_tan("45") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): derivatives.d_tanh([1, 3]) with pytest.raises(TypeError, match=r".*Input value of invalid type*"): derivatives.d_euler("10") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): derivatives.d_sigmoid("3") with pytest.raises(TypeError, match=r".*Input value of invalid type*"): derivatives.d_relu("-5") with pytest.raises(TypeError, match=r".*invalid type*"): derivatives.d_softmax([20, "3", 5]) with pytest.raises(TypeError, match=r".*Input value of invalid type*"): derivatives.d_log("5", 20) with pytest.raises(TypeError, match=r".*Input value of invalid type*"): derivatives.d_log(5, "20")
def test_relu(): assert calculator.relu(4) == np.maximum(0,4)
def test_relu(): assert max(0, -2) == calculator.relu(-2)
def test_relu(): assert calc.relu(5) == np.maximum(0, 5)
def test_relu(self): expect = calculator.relu(np.array([(1, 2), (-1, 0)])) ans = np.array([(1, 2), (0, 0)]) assert np.allclose(expect, ans)