from app.api.scenes import ( _SEARCH_WALK_BUDGET_MS, _SEARCH_WALK_BUDGET_NO_TRGM_MS, _search_walk_budget, ) # 1000 tytulow jak histogram z pg_stats: 20 z "anal", 1 z "hailey rose", reszta obojetna. SAMPLE = ["anal scene %d" % i for i in range(20)] + ["hailey rose pov"] + [ "other title %d" % i for i in range(979) ] def _budget(q, off=0, want=51, narrowed=False): return _search_walk_budget(q, off, want, narrowed, lambda: SAMPLE) def test_common_phrase_walks(): # 20/1000 = 2%: na strone 1 trzeba przejsc ~2,5 tys. scen assert _budget("anal") == _SEARCH_WALK_BUDGET_MS def test_phrase_absent_from_sample_goes_to_trigrams(): assert _budget("jackerman") is None def test_single_hit_phrase_goes_to_trigrams(): # 1/1000 = 0,1%: ~51 tys. scen do przejscia, powyzej progu assert _budget("hailey rose") is None def test_deep_page_of_common_phrase_goes_to_trigrams(): # strona 13 "anal": (600 + 51) / 2% = ~32 tys. assert _budget("anal", off=600) is None def test_narrowed_search_goes_to_trigrams(): assert _budget("anal", narrowed=True) is None def test_short_phrase_always_walks(): # bez trigramu zwykly plan czyta caly indeks; tez przy zawezeniu i poza probka for q in ("vo", "q", "xz", " a "): assert _budget(q, narrowed=True) == _SEARCH_WALK_BUDGET_NO_TRGM_MS assert _budget("zq", off=5000) == _SEARCH_WALK_BUDGET_NO_TRGM_MS def test_sample_not_read_when_not_needed(): def boom(): raise AssertionError("probka niepotrzebna") assert _search_walk_budget("vo", 0, 51, False, boom) == _SEARCH_WALK_BUDGET_NO_TRGM_MS assert _search_walk_budget("anal", 0, 51, True, boom) is None