Completed
Push — master ( 545613...55df2f )
by Daniel
14s queued 11s
created

TestBasicNeeds   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 53
dl 0
loc 74
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A TestBasicNeeds.test_add_value_to_dictionary() 0 18 3
A TestBasicNeeds.test_numbers_with_leading_zero() 0 41 3
1
import os
2
from sources.common.BasicNeeds import BasicNeeds
3
from sources.common.FileOperations import FileOperations
4
# package to facilitate multiple operation system operations
5
import unittest
6
7
8
class TestBasicNeeds(unittest.TestCase):
9
10
    def test_add_value_to_dictionary(self):
11
        class_fo = FileOperations()
12
        # load testing values from JSON file where all cases are grouped
13
        json_structure = class_fo.fn_open_file_and_get_content('dict_to_test.json')
14
        class_bn = BasicNeeds()
15
        for add_type in json_structure:
16
            if 'reference' not in json_structure[add_type]:
17
                json_structure[add_type]['reference'] = None
18
            actual = class_bn.fn_add_value_to_dictionary(json_structure[add_type]['list'].copy(),
19
                                                         json_structure[add_type]['add'], add_type,
20
                                                         json_structure[add_type]['reference'])
21
            self.assertEqual(json_structure[add_type]['expected'].copy(), actual, 'With '
22
                             + 'value "' + json_structure[add_type]['add'] + '" to be added "'
23
                             + add_type + '" the "' + str(json_structure[add_type]['reference'])
24
                             + '" in the list ' + str(json_structure[add_type]['list'].copy())
25
                             + ' expected values were: '
26
                             + str(json_structure[add_type]['expected'].copy())
27
                             + ' but found ' + str(actual))
28
29
    def test_numbers_with_leading_zero(self):
30
        pair_values = [
31
            {
32
                'given': '1',
33
                'leading_zeros': 2,
34
                'expected': '01'
35
            },
36
            {
37
                'given': '1',
38
                'leading_zeros': 10,
39
                'expected': '0000000001'
40
            },
41
            {
42
                'given': '1',
43
                'leading_zeros': 1,
44
                'expected': '1'
45
            }
46
        ]
47
        bn = BasicNeeds()
48
        for current_pair in pair_values:
49
            
50
            value_to_assert = bn.fn_numbers_with_leading_zero(current_pair['given'],
51
                                                              current_pair['leading_zeros'])
52
            self.assertEqual(value_to_assert, current_pair['expected'],
53
                             'Provided values was "' + value_to_assert + '", Expected')
54
        pair_failing_values = [
55
            {
56
                'given': '1',
57
                'leading_zeros': 2,
58
                'expected': '02'
59
            },
60
            {
61
                'given': '1',
62
                'leading_zeros': 0,
63
                'expected': ''
64
            }
65
        ]
66
        for current_pair in pair_failing_values:
67
            value_to_assert = bn.fn_numbers_with_leading_zero(current_pair['given'],
68
                                                              current_pair['leading_zeros'])
69
            self.assertNotEqual(value_to_assert, current_pair['expected'])
70
71
72
if __name__ == '__main__':
73
    unittest.main()
74