コード例 #1
0
ファイル: test_score.py プロジェクト: thomasjpfan/cachey
def test_halflife():
    s = Scorer(1)
    a = s.touch('x', 10)
    b = s.touch('y', 1)
    b = s.touch('y', 1)
    b = s.touch('y', 1)
    b = s.touch('y', 1)
    assert b > a
コード例 #2
0
ファイル: test_score.py プロジェクト: thomasjpfan/cachey
def test_Scorer():
    s = Scorer(10)

    a = s.touch('x', 10)
    b = s.touch('y', 1)
    assert a > b

    a = s.touch('x')
    b = s.touch('x')
    assert a < b
コード例 #3
0
ファイル: test_cache_utils.py プロジェクト: jtsamas/FlowKit
def test_scoring(flowmachine_connect):
    """
    Test that score updating algorithm is correct by comparing to cachey as reference implementation
    """
    dl = daily_location("2016-01-01").store().result()
    dl_time = get_compute_time(get_db(), dl.query_id)
    dl_size = get_size_of_table(get_db(), dl.table_name, "cache")
    initial_score = get_score(get_db(), dl.query_id)
    cachey_scorer = Scorer(halflife=1000.0)
    cache_score = cachey_scorer.touch("dl", dl_time / dl_size)
    assert cache_score == pytest.approx(initial_score)

    # Touch again
    new_score = touch_cache(get_db(), dl.query_id)
    updated_cache_score = cachey_scorer.touch("dl")
    assert updated_cache_score == pytest.approx(new_score)

    # Add another unrelated cache record, which should have a higher initial score
    dl_2 = daily_location("2016-01-02").store().result()
    dl_time = get_compute_time(get_db(), dl_2.query_id)
    dl_size = get_size_of_table(get_db(), dl_2.table_name, "cache")
    cache_score = cachey_scorer.touch("dl_2", dl_time / dl_size)
    assert cache_score == pytest.approx(get_score(get_db(), dl_2.query_id))