1+ import numpy as np
2+ import pytest
3+ from github_tutorial .tests .base_test import BaseTest
4+ #from github_tutorial.utils.math import (add_2_numbers, multiple_of_2_numbers)
5+ from github_tutorial .main_functions .main_functions import (math_function_class , _add_1_to_value )
6+
7+ class TestMainFunction (BaseTest ):
8+ def test__add_1_to_value_int (self ):
9+ val_0 = 1
10+
11+ value = _add_1_to_value (val_0 )
12+
13+ assert value == 2
14+ assert isinstance (value , (int , float ))
15+
16+ def test__add_1_to_value_float (self ):
17+ val_0 = 2.5
18+
19+ value = _add_1_to_value (val_0 )
20+
21+ assert np .isclose (value , 3.5 )
22+ assert isinstance (value , (int , float ))
23+
24+ def test__add_1_to_value_val_0_str (self ):
25+ with pytest .raises (
26+ TypeError ,
27+ match = f"ERROR: In the '_add_1_to_value' function, the initial_value is a { type ('initial_value' )} "
28+ f"and not a int or float" ,
29+ ):
30+ val_0 = '1.5'
31+
32+ value = _add_1_to_value (val_0 )
33+
34+ def test__add_1_to_value_val_0_equal_99_99 (self ):
35+ val_0 = 99.999
36+
37+ value = _add_1_to_value (val_0 )
38+
39+ assert np .isclose (value , 100.999 )
40+ assert isinstance (value , (int , float ))
41+
42+ def test__add_1_to_value_val_0_equal_negative_99999_99 (self ):
43+ val_0 = - 99999.99
44+
45+ value = _add_1_to_value (val_0 )
46+
47+ assert np .isclose (value , - 99998.99 )
48+ assert isinstance (value , (int , float ))
49+
50+ def test__add_1_to_value_val_0_value_greater_equal_100 (self ):
51+ with pytest .warns (
52+ UserWarning ,
53+ match = f"WARNING: In the '_add_1_to_value' function, the { 'initial_value' } >= 100 "
54+ f"\(initial_value = { 101 } \). Are you sure you want to use a large number?" ,
55+ ):
56+ val_0 = 101
57+
58+ value = _add_1_to_value (val_0 )
59+
60+ def test__add_1_to_value_val_0_value_greater_equal_100000 (self ):
61+ with pytest .warns (
62+ UserWarning ,
63+ match = f"WARNING: In the '_add_1_to_value' function, the { 'initial_value' } >= 100 "
64+ f"\(initial_value = { 100000 } \). Are you sure you want to use a large number?" ,
65+ ):
66+ val_0 = 100000
67+
68+ value = _add_1_to_value (val_0 )
69+
70+ def test_math_function_class (self ):
71+ val_0 = 1
72+ val_1 = 2
73+
74+ math_variable = math_function_class (val_0 , val_1 )
75+
76+ assert np .isclose (math_variable .added_numbers , 3 )
77+ assert isinstance (math_variable .added_numbers , (int , float ))
78+ assert np .isclose (math_variable .multiplied_numbers , 2 )
79+ assert isinstance (math_variable .multiplied_numbers , (int , float ))
80+ assert np .isclose (math_variable .add_1_to_both_numbers_and_multiply (), 6 )
81+ assert isinstance (math_variable .add_1_to_both_numbers_and_multiply (), (int , float ))
82+
83+ def test_math_function_class_val_0_str (self ):
84+ with pytest .raises (
85+ TypeError ,
86+ match = f"ERROR: In the 'math_function_class' class, the value_0 is a { type ('value_0' )} "
87+ f"and not a int or float" ,
88+ ):
89+ val_0 = '1.5'
90+ val_1 = 2.0
91+
92+ math_variable = math_function_class (val_0 , val_1 )
93+
94+ def test_math_function_class_val_1_str (self ):
95+ with pytest .raises (
96+ TypeError ,
97+ match = f"ERROR: In the 'math_function_class' class, the value_1 is a { type ('value_1' )} "
98+ f"and not a int or float" ,
99+ ):
100+ val_0 = 1.5
101+ val_1 = '2.0'
102+
103+ math_variable = math_function_class (val_0 , val_1 )
0 commit comments