def test_value_errors():

    with pytest.raises(ValueError, match=r".*should be greater than 0*"):
        calculator.log(0, 2)

    with pytest.raises(ValueError, match=r".*value should be greater than 0*"):
        calculator.log(-2, 10)

    with pytest.raises(
            ValueError,
            match=r".*base should be greater than 0 and not equal to 1*"):
        calculator.log(5, -10)

    with pytest.raises(
            ValueError,
            match=r".*base should be greater than 0 and not equal to 1*"):
        calculator.log(5, 1)

    with pytest.raises(ValueError, match=r".*value should be greater than 0*"):
        derivatives.d_log(0, 10)

    with pytest.raises(ValueError, match=r".*value should be greater than 0*"):
        derivatives.d_log(-2, 10)

    with pytest.raises(
            ValueError,
            match=r".*base should be greater than 0 and not equal to 1*"):
        derivatives.d_log(5, -10)

    with pytest.raises(
            ValueError,
            match=r".*base should be greater than 0 and not equal to 1*"):
        derivatives.d_log(5, 1)
Esempio n. 2
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_log():
    """
    Test the method log in the calculator package
    :return: None
    """
    output = calculator.log(1)
    assert output == 0
    output = derivatives.derivative_log(1)
    assert output == 1
Esempio n. 4
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
Esempio n. 5
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}')
Esempio n. 6
0
def test_log_import():
    log_val = calculator.log(10, 4)
    assert (log_val == 1.6609640474436813
            ), "derivative of relu function has wrong implementation"
def test_function_dlog():
    assert 1/calculator.log(num)  == derivatives.dlog(calculator.log(num)), 'dLog implementaion failed'
def test_function_log():
    assert math.log(num)  == calculator.log(num), ' Log implementaion failed'
Esempio n. 9
0
def test_log():
    assert math.log(3) == calc.log(3), 'Check log 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_log_module():

    assert 0.6989700043360187 == calculator.log(
        5, 10), "log_func module from cal package is not working as expected"
    assert 0.08685889638065035 == derivatives.d_log(
        5, 10), "log_func module from cal package is not working as expected"
Esempio n. 12
0
def test_log():
    assert math.log(10) == calculator.log(10)
Esempio n. 13
0
def test_log():
    assert calc.log(45) == math.log(45)
 def test_log(self):
     assert 1.58 == calculator.log(3, 2)
    def test_log(self):
        self.assertEqual(cl.log(1, 10), 0.0)
        self.assertEqual(cl.log(10, 2), 3.32)
        self.assertEqual(cl.log(1.2, 10), 0.08)
        self.assertEqual(cl.log(10, 1.2), 12.63)

        with self.assertRaises(ZeroDivisionError):
            cl.log(10, 1)

        with self.assertRaises(ValueError):
            cl.log(-1, 10)
            cl.log(10, -1)

        with self.assertRaises(TypeError):
            cl.log(5, 'abc')
            cl.log('abc', 5)
            cl.log(5, True)
            cl.log(True, 5)