1
|
|
|
"""Test class for module calls_stage.""" |
2
|
|
|
|
3
|
|
|
from unittest import TestCase |
4
|
|
|
from unittest.mock import Mock |
5
|
|
|
|
6
|
|
|
from grortir.main.model.stages.cumulated_calls_stage import CumulatedCallsStage |
7
|
|
|
|
8
|
|
|
MAX_CALLS = 100 |
9
|
|
|
CONTRL_PARAMS = [1, 1, 1, 1, 1, 1.5] |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class TestCumulatedCallsStage(TestCase): |
13
|
|
|
"""Test class for CumulatedCallsStage.""" |
14
|
|
|
|
15
|
|
|
def test__init__(self): |
|
|
|
|
16
|
|
|
tested_object = CumulatedCallsStage("Tested obj", |
17
|
|
|
MAX_CALLS, (1, 2, 3), 0.03) |
18
|
|
|
self.assertEquals(tested_object.control_params, [0, 0]) |
19
|
|
|
self.assertEquals(tested_object.name, "Tested obj") |
20
|
|
|
self.assertEquals(tested_object.max_calls, MAX_CALLS) |
21
|
|
|
self.assertEquals(tested_object.maximum_acceptable_quality, 0.03) |
22
|
|
|
self.assertEquals(tested_object.lower_bounds, [-1, -1]) |
23
|
|
|
self.assertEquals(tested_object.upper_bounds, [1, 1]) |
24
|
|
|
|
25
|
|
|
def test_calculate_quality_ex(self): |
26
|
|
|
"""Test case when control are wrong.""" |
27
|
|
|
input_vector = (2, 3, 4, 5, 6) |
28
|
|
|
tested_object = CumulatedCallsStage('name', MAX_CALLS, input_vector) |
29
|
|
|
tested_object.control_params = [2, 2, 2, 2, 2] |
30
|
|
|
with self.assertRaises(AssertionError): |
31
|
|
|
tested_object.calculate_quality(input_vector, |
32
|
|
|
tested_object.control_params) |
33
|
|
|
|
34
|
|
|
def test_calculate_quality_ok(self): |
35
|
|
|
"""Test case when control params and input are okay.""" |
36
|
|
|
input_vector = (2, 3, 4, 5, 6, 1, 99) |
37
|
|
|
tested_object = CumulatedCallsStage('name', MAX_CALLS, input_vector) |
38
|
|
|
tested_object.control_params = CONTRL_PARAMS |
39
|
|
|
result = tested_object.calculate_quality(input_vector, |
40
|
|
|
tested_object.control_params) |
41
|
|
|
self.assertEqual(result, 55.25) |
42
|
|
|
|
43
|
|
|
def test_get_output_of_stage_empty(self): |
44
|
|
|
"""Test returning output.""" |
45
|
|
|
tested_object = CumulatedCallsStage('name', MAX_CALLS) |
46
|
|
|
with self.assertRaises(AssertionError): |
47
|
|
|
tested_object.get_output_of_stage([], []) |
48
|
|
|
|
49
|
|
|
def test_get_output_of_stage(self): |
|
|
|
|
50
|
|
|
tested_object = Mock() |
51
|
|
|
tested_object.calculate_quality.return_value = 999 |
52
|
|
|
result = CumulatedCallsStage.get_output_of_stage(tested_object, |
53
|
|
|
[1, 2, 3, 4, 99], |
54
|
|
|
[5, 6, 7, 8]) |
55
|
|
|
self.assertEqual([5, 6, 7, 8, 999], result) |
56
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.