4
4
from safeds .data .tabular .containers import Table
5
5
from syrupy import SnapshotAssertion
6
6
7
+ from safeds .exceptions import ColumnNotFoundError , ColumnTypeError
8
+
7
9
8
10
@pytest .mark .parametrize (
9
11
("table" , "x_name" , "y_name" , "window_size" ),
10
12
[
11
13
(Table ({"A" : [1 , 2 , 3 ], "B" : [2 , 4 , 7 ]}), "A" , "B" , 2 ),
12
- # (Table({"A": [1, 1, 2, 2, 3, 3, 4, 4, 5, 5], "B": [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]}), "A", "B", 2),
14
+ (Table ({"A" : [1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 , 5 , 5 ], "B" : [2 , 4 , 6 , 8 , 10 , 12 , 14 , 16 , 18 , 20 ]}), "A" , "B" , 2 ),
13
15
(
14
16
Table (
15
17
{
45
47
2 ,
46
48
),
47
49
],
48
- ids = ["numerical" , "date grouped" , "date" ],
50
+ ids = ["numerical" ,"numerical grouped" , "date grouped" , "date" ],
49
51
)
50
52
def test_should_match_snapshot (
51
53
table : Table ,
@@ -56,3 +58,41 @@ def test_should_match_snapshot(
56
58
) -> None :
57
59
line_plot = table .plot .moving_average_plot (x_name , y_name , window_size )
58
60
assert line_plot == snapshot_png_image
61
+
62
+
63
+ @pytest .mark .parametrize (
64
+ ("x" , "y" ),
65
+ [
66
+ ("C" , "A" ),
67
+ ("A" , "C" ),
68
+ ("C" , "D" ),
69
+ ],
70
+ ids = ["x column" , "y column" , "x and y column" ],
71
+ )
72
+ def test_should_raise_if_column_does_not_exist_error_message (x : str , y : str ) -> None :
73
+ table = Table ({"A" : [1 , 2 , 3 ], "B" : [2 , 4 , 7 ]})
74
+ with pytest .raises (ColumnNotFoundError ):
75
+ table .plot .moving_average_plot (x , y , window_size = 2 )
76
+
77
+
78
+
79
+
80
+ @pytest .mark .parametrize (
81
+ ("table" ),
82
+ [
83
+ (Table ({"A" : [1 , 2 , 3 ], "B" : ["2" , 4 , 7 ]})),
84
+ (Table ({"A" : ["1" , 2 , 3 ], "B" : [2 , 4 , 7 ]})),
85
+ ],
86
+ ids = ["x column" , "y column" ],
87
+ )
88
+
89
+ def test_should_raise_if_column_is_not_numerical (table : Table ) -> None :
90
+ print (table )
91
+ with pytest .raises (ColumnTypeError ):
92
+ table .plot .moving_average_plot ("A" , "B" , window_size = 2 )
93
+
94
+
95
+ def test_should_raise_if_column_has_missing_value () -> None :
96
+ table = Table ({"A" : [None , 2 , 3 ], "B" : [2 , 4 , 7 ]})
97
+ with pytest .raises (ValueError ):
98
+ table .plot .moving_average_plot ("A" , "B" , window_size = 2 )
0 commit comments