test_scaling.py 2.6 KB
Newer Older
1
"""Unit tests for scaling.py."""
2
import os
juga's avatar
juga committed
3
from statistics import mean
4
5

from sbws.lib import scaling
6
from sbws.lib.resultdump import load_result_file, ResultSuccess
7
8
9
10
11
12
13
14
15


def test_bw_filt():
    bw_measurements = [
        96700.00922329757, 70311.63051659254, 45531.743347556374,
        38913.97025485627, 55656.332364676025
    ]
    fb = scaling.bw_filt(bw_measurements)
    # This is greater than the mean, that is 61422.73714139576
juga's avatar
juga committed
16
17
18
19
20
    assert fb == 83506

    # When there are no measurements what can not be the case for successful
    # results.
    bw_measurements = []
21
    assert 0 == scaling.bw_filt(bw_measurements)
juga's avatar
juga committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

    bw_measurements = [1, 0]
    # Because rounded to int
    assert 0 == round(mean(bw_measurements))
    # So the filtered bw will be also 0
    assert 0 == scaling.bw_filt(bw_measurements)

    bw_measurements = [1, 2, 3]
    # Because rounded to int
    assert 2 == round(mean(bw_measurements))
    assert 2 == scaling.bw_filt(bw_measurements)

    bw_measurements = [10, 0]
    assert 5 == round(mean(bw_measurements))
    # Because the value 10 is bigger than the mean
    assert 10 == scaling.bw_filt(bw_measurements)

    bw_measurements = [0, 10, 20]
    assert 10 == round(mean(bw_measurements))
    # Because 10 and 20 are bigger or equal than the mean
    assert 15 == scaling.bw_filt(bw_measurements)
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69


def test_bw_filt_from_results(root_data_path):
    results_file = os.path.join(
        root_data_path, ".sbws", "datadir", "2019-03-25.txt"
    )
    results = load_result_file(results_file)
    bw_filts = {}
    for fp, values in results.items():
        success_results = [r for r in values if isinstance(r, ResultSuccess)]
        if success_results:
            bw_measurements = scaling.bw_measurements_from_results(
                success_results
            )
            mu = round(mean(bw_measurements))
            muf = scaling.bw_filt(bw_measurements)
            bw_filts[fp] = (mu, muf)
    for fp, values in bw_filts.items():
        assert bw_filts[fp][0] <= bw_filts[fp][1]
    assert 5526756 == bw_filts['117A456C911114076BEB4E757AC48B16CC0CCC5F'][0]
    assert 5643086 == bw_filts['117A456C911114076BEB4E757AC48B16CC0CCC5F'][1]
    assert 5664965 == bw_filts['693F73187624BE760AAD2A12C5ED89DB1DE044F5'][0]
    assert 5774274 == bw_filts['693F73187624BE760AAD2A12C5ED89DB1DE044F5'][1]
    assert 5508279 == bw_filts['270A861ABED22EC2B625198BCCD7B2B9DBFFC93C'][0]
    assert 5583737 == bw_filts['270A861ABED22EC2B625198BCCD7B2B9DBFFC93C'][1]
    assert 5379911 == bw_filts['E894C65997F8EC96558B554176EEEA39C6A43EF6'][0]
    assert 5485088 == bw_filts['E894C65997F8EC96558B554176EEEA39C6A43EF6'][1]