Skip to content

Commit

Permalink
Add test_title_rank_range, test_freshness_rank_range, test_seeders_ra…
Browse files Browse the repository at this point in the history
…nk_range, test_torrent_rank_range
  • Loading branch information
kozlovsky committed Nov 1, 2022
1 parent 67f9aad commit 8e513e5
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/tribler/core/tests/test_search_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pytest

from tribler.core.utilities.search_utils import filter_keywords, find_word, item_rank, split_into_keywords,\
torrent_rank, title_rank
from tribler.core.utilities.search_utils import filter_keywords, find_word, freshness_rank, item_rank, seeders_rank, \
split_into_keywords, torrent_rank, title_rank


DAY = 60 * 60 * 24
Expand All @@ -25,6 +25,34 @@ def test_filter_keywords():
assert len(result) == 4


def test_title_rank_range():
assert title_rank('Big Buck Bunny', 'Big Buck Bunny') == 1

long_query = ' '.join(['foo'] * 1000)
long_title = ' '.join(['bar'] * 1000)
assert title_rank(long_query, long_title) == pytest.approx(0.03554968)


def test_freshness_rank_range():
assert freshness_rank(-1) == 0
assert freshness_rank(0) == 0
assert freshness_rank(0.001) == pytest.approx(1.0)
assert freshness_rank(1000000000) == pytest.approx(0.0025852989)


def test_seeders_rank_range():
assert seeders_rank(0) == 0
assert seeders_rank(1000000) == pytest.approx(0.9999)


def test_torrent_rank_range():
assert torrent_rank('Big Buck Bunny', 'Big Buck Bunny', seeders=1000000, freshness=0.01) == pytest.approx(0.99999)

long_query = ' '.join(['foo'] * 1000)
long_title = ' '.join(['bar'] * 1000)
assert torrent_rank(long_query, long_title, freshness=1000000 * 365 * DAY) == pytest.approx(+0.02879524)


def test_torrent_rank():
query = 'Big Buck Bunny'
# The exact match ranked as pretty high
Expand Down

0 comments on commit 8e513e5

Please sign in to comment.