File: test_combine_ratings.py

package info (click to toggle)
freeorion 0.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 194,940 kB
  • sloc: cpp: 186,508; python: 40,969; ansic: 1,164; xml: 719; makefile: 32; sh: 7
file content (40 lines) | stat: -rw-r--r-- 1,014 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import pytest

from freeorion_tools import combine_ratings


@pytest.mark.parametrize(
    ("rating1", "raring2", "combined"),
    (
        (1, 1, pytest.approx(4.0)),
        (2, 1, pytest.approx(5.82, rel=1e-2)),
        (2, 2, pytest.approx(8.0)),
        (4, 2, pytest.approx(11.65, rel=1e-2)),
    ),
)
def test_two_rating_are_merged(rating1, raring2, combined):
    assert combine_ratings(rating1, raring2) == combined


def test_merge_3_ratings():
    assert combine_ratings(1, 1, 2) == pytest.approx(11.65, rel=1e-2)


@pytest.mark.parametrize(
    ("iterable"),
    (
        (1, 1, 2),
        iter((1, 1, 2)),
        [1, 1, 2],
    ),
)
def test_merge_3_ratings_as_collection(iterable):
    assert combine_ratings(iterable) == pytest.approx(11.65, rel=1e-2)


def test_merge_3_ratings_as_collection_and_args():
    assert combine_ratings([1, 1], 2) == pytest.approx(11.65, rel=1e-2)


def test_idempotency():
    assert combine_ratings(1, 1, 2) == combine_ratings(2, 1, 1) == combine_ratings(1, 2, 1)