Example #1
0
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_tanh():
    """
    Test the method tanh in the calculator package
    :return: None
    """
    output = calculator.tanh(0)
    assert output == 0
    output = derivatives.derivative_tanh(0)
    assert output == 1
Example #3
0
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
Example #4
0
def test_tanh_import():
    tanh_output = calculator.tanh(22 / 28)
    assert round(
        tanh_output,
        2) == 0.66, "tanh function in calculor has wrong implementation"
def test_function_dtanh():
    assert (1  - calculator.tanh(num)**2)  == derivatives.dtanh(calculator.tanh(num)), 'dTanh implementaion failed'
def test_function_tanh():
    assert math.tanh(num)  == calculator.tanh(num), 'Tanh implementaion failed'
Example #7
0
def test_tanh():
    assert math.tanh(3.14) == calc.tanh(3.14), 'Check tanh 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_tanh_module():

    assert 1.0 == calculator.tanh(
        45), "tanh_func module from cal package is not working as expected"
    assert 0.0 == derivatives.d_tanh(
        45), "tanh_func module from cal package is not working as expected"
Example #10
0
def test_tanh():
    assert calculator.tanh(4) == tanh(4)
Example #11
0
def test_tanh():
    assert math.tanh(10) == calculator.tanh(10)
Example #12
0
def test_tanh():
    assert calc.tanh(45, 'degree') == math.tanh(45)