Skip to content

Commit ce31ada

Browse files
committed
Unit tests for FunctionIf
1 parent 5672aa8 commit ce31ada

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

test/functions/test_function_if.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from s2e2.error import ExpressionError
2+
from s2e2.functions.function_if import FunctionIf
3+
4+
import pytest
5+
6+
7+
class TestFunctionIf:
8+
9+
def setup_class(self):
10+
self.function = FunctionIf()
11+
12+
13+
def teardown_class(self):
14+
self.function = None
15+
16+
17+
def test_positive_good_arguments_stack_size(self):
18+
stack = [True, 'A', 'B']
19+
self.function.invoke(stack)
20+
assert len(stack) == 1
21+
22+
23+
def test_positive_good_arguments_result_type(self):
24+
stack = [True, 'A', 'B']
25+
self.function.invoke(stack)
26+
assert isinstance(stack[0], str)
27+
28+
29+
def test_positive_first_argument_true_result_value(self):
30+
stack = [True, 'A', 'B']
31+
self.function.invoke(stack)
32+
assert stack[0] == 'A'
33+
34+
35+
def test_positive_first_argument_false_result_value(self):
36+
stack = [False, 'A', 'B']
37+
self.function.invoke(stack)
38+
assert stack[0] == 'B'
39+
40+
41+
def test_positive_second_argument_none_result_value(self):
42+
stack = [True, None, 'B']
43+
self.function.invoke(stack)
44+
assert stack[0] is None
45+
46+
47+
def test_positive_third_argument_none_result_value(self):
48+
stack = [False, 'A', None]
49+
self.function.invoke(stack)
50+
assert stack[0] is None
51+
52+
53+
def test_positive_more_arguments_stack_size(self):
54+
stack = ['Arg', False, 'A', 'B']
55+
self.function.invoke(stack)
56+
assert len(stack) == 2
57+
58+
59+
def test_negative_fewer_arguments(self):
60+
stack = [False]
61+
with pytest.raises(ExpressionError) as ex:
62+
self.function.invoke(stack)
63+
assert 'Not enough arguments' in str(ex.value)
64+
65+
66+
def test_negative_first_argument_wrong_type(self):
67+
stack = ['False', 'A', 'B']
68+
with pytest.raises(ExpressionError) as ex:
69+
self.function.invoke(stack)
70+
assert 'Invalid arguments' in str(ex.value)
71+
72+
73+
def test_negative_first_argument_none(self):
74+
stack = [None, 'A', 'B']
75+
with pytest.raises(ExpressionError) as ex:
76+
self.function.invoke(stack)
77+
assert 'Invalid arguments' in str(ex.value)

0 commit comments

Comments
 (0)