Пример #1
0
def test_cached_time():
    result1 = memoization.memoize(memoization.add_to_time, 0, 1, 10, x)
    t1 = int(round(time.time() * 1000))

    while (memoization.memoize(memoization.add_to_time, 0, 1, 10, x)) == result1:
        t2 = int(round(time.time() * 1000))
    print('..value was stored for {} ms in memory'.format(t2 - t1))
Пример #2
0
def test_updated_value():
    result1 = memoization.memoize(memoization.add_to_time, 0, 1, 00, x)
    t1 = int(round(time.time() * 1000))

    while True:
        if (memoization.memoize(memoization.add_to_time, 0, 1, 00, x)) > result1:
            t2 = int(round(time.time() * 1000))
            break
    print('..value  should be updated if called  as it has to be stored for only {} ms in memory'.format(t2 - t1))
Пример #3
0
def test_run_time():
    t1= int(round(time.time() * 1000))
    result1 = memoization.memoize(memoization.add_to_time, 1, 1, 00, x)
    t2 = int(round(time.time() * 1000))
    print("the function was executed in {} ms by running the function".format(t2-t1))

    t1 = int(round(time.time() * 1000))
    result1 = memoization.memoize(memoization.add_to_time, 1, 1, 00, x)
    t2 = int(round(time.time() * 1000))
    print("the function was executed in {} ms by returning  from memory ".format(t2 - t1))
Пример #4
0
    def test_TS2_TC1(self):
        returnValue = 50

        # Function, which return value should be memoized
        testFunction = lambda key: returnValue

        # Setting up callback function
        memoized = memoization.memoize(testFunction, lambda key: key, 1000)

        # Assertion for checking bool valid type (key), should passed
        assert memoized(True) == 50

        # Assertion for checking bytes valid type (key), should passed
        assert memoized(b"bytes") == 50

        # Assertion for checking integer valid type (key), should passed
        assert memoized(10) == 50

        # Assertion for checking float valid type (key), should passed
        assert memoized(10.55) == 50

        # Assertion for checking complex valid type (key), should passed
        assert memoized(1j) == 50

        # Assertion for checking string valid type (key), should passed
        assert memoized("String_Value") == 50

        # Assertion for checking tuples valid type (key), should passed
        assert memoized((0, 10)) == 50

        # Assertion for checking range valid type (key), should passed
        assert memoized(range(10)) == 50
Пример #5
0
    def test_TS1_TC1(self):
        returnValue = 5

        # Function, which return value should be memoized
        testFunction = lambda key: returnValue

        # Setting up callback function
        memoized = memoization.memoize(testFunction, lambda key: key, 1000)

        # Assertion for checking return value via callback to be memoized, it should passed
        assert memoized("e1-51-01-efg") == 5

        returnValue = 10

        # Should returned memoized value as their is no timeout no testFunction call, hence, passed,
        # despite having new returnValue in the variable
        assert memoized("e1-51-01-efg") == 5
Пример #6
0
    def test_TS2_TC2(self):
        returnValue = 50

        # Function, which return value should be memoized
        testFunction = lambda key: returnValue

        # Setting up callback function
        memoized = memoization.memoize(testFunction, lambda key: key, 1000)

        # Assertion for checking set invalid type (key), should passed as exception (None) object is returned
        assert memoized({1, "Set2"}) is None

        # Assertion for checking list invalid type (key), should passed as exception (None) object is returned
        assert memoized([1, "List2"]) is None

        # Assertion for checking dictionary invalid type (key), should passed as exception (None) object is returned
        assert memoized({"Dict1": 1, 1: "Dict2"}) is None
Пример #7
0
    def test_TS1_TC2(self):
        returnValue = 45

        # Function, which return value should be memoized
        testFunction = lambda key: returnValue

        # Setting up callback function
        memoized = memoization.memoize(testFunction, lambda key: key, 5000)

        # Assertion for checking return value via callback to be memoized, it should passed
        assert memoized("e1-51-01-efg") == 45

        returnValue = 55

        memoization.timeout_results_FakeTimer.pass_time(5)

        # Should returned new value to be memoized as their is timeout, hence failing with old value check
        assert memoized("e1-51-01-efg") == 45
Пример #8
0
    def test_TS1_TC3(self):
        args1 = 5
        args2 = 10
        args3 = 15

        # Function, which return value should be memoized
        testFunction = lambda args1, arg2, arg3: args1 + arg2 + arg3

        # Setting up callback function
        memoized = memoization.memoize(testFunction, None, 1000)

        # Assertion for checking return value via callback to be memoized, it should passed
        assert memoized(args1, args2, args3) == 30

        args1 = 5
        args2 = 20
        args3 = 30

        # Should returned memoized value as their is no timeout, hence passed despite having new returnValue
        assert memoized(args1, args2, args3) == 30
Пример #9
0
    def test_TS1_TC4(self):
        args1 = 5
        args2 = 10
        args3 = 15

        # Function, which return value should be memoized
        testFunction = lambda args1, arg2, arg3: args1 + arg2 + arg3

        # Setting up callback function
        memoized = memoization.memoize(testFunction, None, 5000)

        # Assertion for checking return value via callback to be memoized, it should passed
        assert memoized(args1, args2, args3) == 30

        args1 = 5
        args2 = 20
        args3 = 30

        memoization.timeout_results_FakeTimer.pass_time(5)

        # Should returned new value to be memoized as their is timeout, hence failing with old value check
        assert memoized(args1, args2, args3) == 30
Пример #10
0
def test_memoize():
    result1 = memoization.memoize(memoization.add_to_time, 1, 1, 1, x)
    # time.sleep()
    result2 = memoization.memoize(memoization.add_to_time, 1, 1, 1, x)
    assert result1 == result2