aboutsummaryrefslogtreecommitdiff
path: root/gn2/tests/unit/utility/test_corr_result_helpers.py
blob: 59260ba6a48a76db5ab0b579d3f9e705e136fdc2 (about) (plain)
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
""" Test correlation helper methods """

import unittest
from gn2.utility.corr_result_helpers import normalize_values, common_keys, normalize_values_with_samples


class TestCorrelationHelpers(unittest.TestCase):
    """Test methods for normalising lists"""

    def test_normalize_values(self):
        """Test that a list is normalised correctly"""
        self.assertEqual(
            normalize_values([2.3, None, None, 3.2, 4.1, 5], [
                             3.4, 7.2, 1.3, None, 6.2, 4.1]),
            ([2.3, 4.1, 5], [3.4, 6.2, 4.1], 3)
        )

    def test_common_keys(self):
        """Test that common keys are returned as a list"""
        a = dict(BXD1=9.113, BXD2=9.825, BXD14=8.985, BXD15=9.300)
        b = dict(BXD1=9.723, BXD3=9.825, BXD14=9.124, BXD16=9.300)
        self.assertEqual(sorted(common_keys(a, b)), ['BXD1', 'BXD14'])

    def test_normalize_values_with_samples(self):
        """Test that a sample(dict) is normalised correctly"""
        self.assertEqual(
            normalize_values_with_samples(
                dict(BXD1=9.113, BXD2=9.825, BXD14=8.985,
                     BXD15=9.300, BXD20=9.300),
                dict(BXD1=9.723, BXD3=9.825, BXD14=9.124, BXD16=9.300)),
            (({'BXD1': 9.113, 'BXD14': 8.985}, {'BXD1': 9.723, 'BXD14': 9.124}, 2))
        )