Completed
Push — master ( 375895...8c5af0 )
by Wojtek
8s
created

test_could_be_optimized_pos()   A

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 7
rs 9.4285
1
"""Test class for module calls_stage."""
2
3
from unittest import TestCase
4
from unittest.mock import Mock, sentinel
5
6
from grortir.main.model.stages.calls_stage import CallsStage
7
8
MAX_CALLS = 100
9
10
11
class TestCallsStage(TestCase):
12
    """Test class for CallsStage."""
13
14
    def test_get_quality(self):
15
        """Test for get_quality method."""
16
        tested_object = Mock()
17
        tested_object.cost = 7
18
        tested_object.calculate_quality.return_value = sentinel.quality
19
        result = CallsStage.get_quality(tested_object)
20
        self.assertEqual(tested_object.cost, 8)
21
        tested_object.calculate_quality.assert_called_with()
22
        self.assertEqual(result, sentinel.quality)
23
24
    def test_get_cost(self):
25
        """Test for get_cost method."""
26
        tested_object = Mock()
27
        tested_object.cost = sentinel.cost
28
        result = CallsStage.get_cost(tested_object)
29
        self.assertEqual(result, sentinel.cost)
30
31
    def test_calculate_quality_ex(self):
32
        """Test case when control are wrong."""
33
        input_vector = (2, 3, 4, 5, 6)
34
        tested_object = CallsStage('name', MAX_CALLS, input_vector)
35
        tested_object.control_params = [2, 2]
36
        with self.assertRaises(AssertionError):
37
            tested_object.calculate_quality()
38
39
    def test_calculate_quality_ok(self):
40
        """Test case when control params and input are okay."""
41
        input_vector = (2, 3, 4, 5, 6, 1)
42
        tested_object = CallsStage('name', MAX_CALLS, input_vector)
43
        tested_object.control_params = [1, 1, 1, 1, 1, 1.5]
44
        result = tested_object.calculate_quality()
45
        self.assertEqual(result, 55.25)
46
47
    def test_could_be_optimized_pos(self):
48
        """Positive case for test could_be_optimized method."""
49
        tested_object = Mock()
50
        tested_object.get_cost.return_value = MAX_CALLS - 1
51
        tested_object.max_calls = MAX_CALLS
52
        result = CallsStage.could_be_optimized(tested_object)
53
        self.assertTrue(result)
54
55
    def test_could_be_optimized_neg(self):
56
        """Negative case for test could_be_optimized method."""
57
        tested_object = Mock()
58
        tested_object.get_cost.return_value = MAX_CALLS + 1
59
        tested_object.max_calls = MAX_CALLS
60
        result = CallsStage.could_be_optimized(tested_object)
61
        self.assertFalse(result)
62