test_boxplot.py 1.5 KB
Newer Older
1
2
"""This module contains the tests for the Boxplot analysis code."""

Sascha Herzinger's avatar
Sascha Herzinger committed
3
4
5
6
7
8
9
10
11
import json

import numpy as np
import pandas as pd

from fractalis.analytics.tasks.boxplot.main import BoxplotTask


# noinspection PyMissingOrEmptyDocstring,PyMissingTypeHints
12
class TestBoxplotAnalytics:
Sascha Herzinger's avatar
Sascha Herzinger committed
13
14
15

    task = BoxplotTask()

16
17
18
19
20
21
22
23
    def test_correct_output(self):
        df_1 = pd.DataFrame([[101, 'foo', 1], [102, 'foo', 2], [103, 'foo', 3],
                             [104, 'foo', 4]],
                            columns=['id', 'feature', 'value'])
        df_2 = pd.DataFrame([[101, 'bar', 1], [102, 'bar', 2], [103, 'bar', 3],
                             [104, 'bar', 4]],
                            columns=['id', 'feature', 'value'])
        results = self.task.main(features=[df_1, df_2],
Sascha Herzinger's avatar
Sascha Herzinger committed
24
25
26
                                 categories=[],
                                 id_filter=[],
                                 subsets=[])
27
        json.dumps(results)  # check if result is json serializable
Sascha Herzinger's avatar
Sascha Herzinger committed
28
29
        assert 'data' in results
        assert 'statistics' in results
30
31
32
33
34
        assert len(json.loads(results['data'])) == 8
        assert len(results['statistics']) == 2
        assert 'foo////s1' in results['statistics']
        assert 'bar////s1' in results['statistics']
        stats = results['statistics']['foo////s1']
Sascha Herzinger's avatar
Sascha Herzinger committed
35
36
37
38
39
        assert not np.isnan(stats['median'])
        assert not np.isnan(stats['l_qrt'])
        assert not np.isnan(stats['u_qrt'])
        assert not np.isnan(stats['l_wsk'])
        assert not np.isnan(stats['u_wsk'])