1
1
# -*- coding: utf-8 -*-
2
- # pylint: disable=no-name-in-module, missing-function-docstring
3
- # pylint: disable=missing-class-docstring, invalid-name
4
2
5
3
# Copyright (c) 2021, J. D. Mitchell + Maria Tsalakou
6
4
#
13
11
derived classes, i.e. KnuthBendix, FpSemigroup, etc.
14
12
"""
15
13
14
+ # pylint: disable=no-name-in-module, missing-function-docstring, invalid-name
15
+
16
16
from datetime import timedelta
17
+ import pytest
17
18
from runner import check_runner
18
19
from libsemigroups_pybind11 import ReportGuard , FroidurePin , Transf
19
20
20
21
21
- def check_validation (self , t ):
22
+ def check_validation (t ):
22
23
ReportGuard (False )
23
24
x = t ()
24
25
x .set_alphabet ("ab" )
25
26
26
- with self . assertRaises (RuntimeError ):
27
+ with pytest . raises (RuntimeError ):
27
28
x .validate_letter ("c" )
28
29
try :
29
30
x .validate_letter ("a" )
30
31
except RuntimeError as e :
31
- self .fail (
32
+ pytest .fail (
32
33
"unexpected exception raised for FpSemigroupInterface::validate_letter: "
33
34
+ e
34
35
)
35
36
36
- with self . assertRaises (RuntimeError ):
37
+ with pytest . raises (RuntimeError ):
37
38
x .validate_letter (3 )
38
39
try :
39
40
x .validate_letter (0 )
40
41
except RuntimeError as e :
41
- self .fail (
42
+ pytest .fail (
42
43
"unexpected exception raised for FpSemigroupInterface::validate_letter: "
43
44
+ e
44
45
)
45
- with self . assertRaises (RuntimeError ):
46
+ with pytest . raises (RuntimeError ):
46
47
x .validate_word ("abc" )
47
48
try :
48
49
x .validate_word ("abab" )
49
50
except RuntimeError as e :
50
- self .fail (
51
+ pytest .fail (
51
52
"unexpected exception raised for FpSemigroupInterface::validate_letter: "
52
53
+ e
53
54
)
54
55
55
- with self . assertRaises (RuntimeError ):
56
+ with pytest . raises (RuntimeError ):
56
57
x .validate_word ([0 , 1 , 2 ])
57
58
58
59
try :
59
60
x .validate_word ([0 , 1 , 0 , 1 ])
60
61
except RuntimeError as e :
61
- self .fail (
62
+ pytest .fail (
62
63
"unexpected exception raised for FpSemigroupInterface::validate_letter: "
63
64
+ e
64
65
)
65
66
66
67
67
- def check_converters (self , t ):
68
+ def check_converters (t ):
68
69
ReportGuard (False )
69
70
x = t ()
70
71
x .set_alphabet ("ba" )
71
- self . assertEqual ( x .char_to_uint ("a" ), 1 )
72
- self . assertEqual ( x .char_to_uint ("b" ), 0 )
72
+ assert x .char_to_uint ("a" ) == 1
73
+ assert x .char_to_uint ("b" ) == 0
73
74
74
- self . assertEqual ( x .string_to_word ("ab" ), [1 , 0 ])
75
- self . assertEqual ( x .string_to_word ("aaaaaa" ), [1 ] * 6 )
76
- with self . assertRaises (RuntimeError ):
75
+ assert x .string_to_word ("ab" ) == [1 , 0 ]
76
+ assert x .string_to_word ("aaaaaa" ) == [1 ] * 6
77
+ with pytest . raises (RuntimeError ):
77
78
x .string_to_word ("c" )
78
79
79
- self . assertEqual ( x .uint_to_char (0 ), "b" )
80
- self . assertEqual ( x .uint_to_char (1 ), "a" )
81
- with self . assertRaises (RuntimeError ):
80
+ assert x .uint_to_char (0 ) == "b"
81
+ assert x .uint_to_char (1 ) == "a"
82
+ with pytest . raises (RuntimeError ):
82
83
x .uint_to_char (2 )
83
84
84
- self . assertEqual ( x .word_to_string ([1 , 0 ]), "ab" )
85
- self . assertEqual ( x .word_to_string ([1 ] * 6 ), "a" * 6 )
86
- with self . assertRaises (RuntimeError ):
85
+ assert x .word_to_string ([1 , 0 ]) == "ab"
86
+ assert x .word_to_string ([1 ] * 6 ) == "a" * 6
87
+ with pytest . raises (RuntimeError ):
87
88
x .word_to_string ([2 ])
88
89
89
90
90
- def check_initialisation (self , t ):
91
+ def check_initialisation (t ):
91
92
ReportGuard (False )
92
93
x = t ()
93
94
x .set_alphabet ("ba" )
94
95
x .add_rule ([0 , 1 ], [1 , 0 ])
95
96
96
- with self . assertRaises (RuntimeError ):
97
+ with pytest . raises (RuntimeError ):
97
98
x .add_rule ([0 , 1 ], [2 ])
98
99
99
100
S = FroidurePin ([Transf ([1 , 2 , 0 ]), Transf ([1 , 0 , 2 ])])
100
101
S .run ()
101
102
x .add_rules (S )
102
- self . assertEqual ( x .size (), 2 )
103
+ assert x .size () == 2
103
104
104
105
x = t ()
105
106
x .set_alphabet ("abBe" )
@@ -109,15 +110,15 @@ def check_initialisation(self, t):
109
110
110
111
x .add_rule ("bb" , "B" )
111
112
x .add_rule ("BaBa" , "abab" )
112
- self . assertEqual ( x .size (), 24 )
113
+ assert x .size () == 24
113
114
114
115
x = t ()
115
116
x .set_alphabet (1 )
116
117
x .set_identity (0 )
117
- self . assertEqual ( x .size (), 1 )
118
+ assert x .size () == 1
118
119
119
120
120
- def check_attributes (self , t ):
121
+ def check_attributes (t ):
121
122
ReportGuard (False )
122
123
x = t ()
123
124
x .set_alphabet ("abBe" )
@@ -128,36 +129,33 @@ def check_attributes(self, t):
128
129
x .add_rule ("BaBa" , "abab" )
129
130
x .run ()
130
131
131
- self .assertEqual (
132
- list (x .rules ()),
133
- [
134
- ("ae" , "a" ),
135
- ("ea" , "a" ),
136
- ("be" , "b" ),
137
- ("eb" , "b" ),
138
- ("Be" , "B" ),
139
- ("eB" , "B" ),
140
- ("ee" , "e" ),
141
- ("aa" , "e" ),
142
- ("bB" , "e" ),
143
- ("Bb" , "e" ),
144
- ("bb" , "B" ),
145
- ("BaBa" , "abab" ),
146
- ],
147
- )
148
- self .assertEqual (x .number_of_rules (), 12 )
149
-
150
- self .assertEqual (x .alphabet (), "abBe" )
151
- self .assertFalse (x .has_froidure_pin ())
152
- self .assertEqual (x .froidure_pin ().size (), 24 )
153
- self .assertEqual (x .identity (), "e" )
154
- self .assertEqual (x .inverses (), "aBbe" )
155
- self .assertFalse (x .is_obviously_infinite ())
156
- self .assertTrue (x .is_obviously_finite ())
157
- self .assertEqual (x .size (), 24 )
158
-
159
-
160
- def check_operators (self , t ):
132
+ assert list (x .rules ()) == [
133
+ ("ae" , "a" ),
134
+ ("ea" , "a" ),
135
+ ("be" , "b" ),
136
+ ("eb" , "b" ),
137
+ ("Be" , "B" ),
138
+ ("eB" , "B" ),
139
+ ("ee" , "e" ),
140
+ ("aa" , "e" ),
141
+ ("bB" , "e" ),
142
+ ("Bb" , "e" ),
143
+ ("bb" , "B" ),
144
+ ("BaBa" , "abab" ),
145
+ ]
146
+ assert x .number_of_rules () == 12
147
+
148
+ assert x .alphabet () == "abBe"
149
+ assert not x .has_froidure_pin ()
150
+ assert x .froidure_pin ().size () == 24
151
+ assert x .identity () == "e"
152
+ assert x .inverses () == "aBbe"
153
+ assert not x .is_obviously_infinite ()
154
+ assert x .is_obviously_finite ()
155
+ assert x .size () == 24
156
+
157
+
158
+ def check_operators (t ):
161
159
x = t ()
162
160
x .set_alphabet ("abBe" )
163
161
x .set_identity ("e" )
@@ -166,31 +164,31 @@ def check_operators(self, t):
166
164
x .add_rule ("bb" , "B" )
167
165
x .add_rule ("BaBa" , "abab" )
168
166
x .run ()
169
- self . assertTrue ( x .equal_to ("bb" , "B" ) )
170
- self . assertTrue ( x .equal_to ([1 , 1 ], [2 ]) )
167
+ assert x .equal_to ("bb" , "B" )
168
+ assert x .equal_to ([1 , 1 ], [2 ])
171
169
172
- with self . assertRaises (RuntimeError ):
170
+ with pytest . raises (RuntimeError ):
173
171
x .equal_to ([1 , 1 ], [5 ])
174
172
175
- with self . assertRaises (RuntimeError ):
173
+ with pytest . raises (RuntimeError ):
176
174
x .equal_to ("aa" , "z" )
177
175
178
- self . assertEqual ( x .normal_form ("bb" ), "B" )
179
- self . assertEqual ( x .normal_form ("B" ), "B" )
180
- self . assertEqual ( x .normal_form ([1 , 1 ]), [2 ])
181
- self . assertEqual ( x .normal_form ([0 , 0 ]), [3 ])
176
+ assert x .normal_form ("bb" ) == "B"
177
+ assert x .normal_form ("B" ) == "B"
178
+ assert x .normal_form ([1 , 1 ]) == [2 ]
179
+ assert x .normal_form ([0 , 0 ]) == [3 ]
182
180
183
- with self . assertRaises (RuntimeError ):
181
+ with pytest . raises (RuntimeError ):
184
182
x .normal_form ([1 , 5 ])
185
- with self . assertRaises (RuntimeError ):
183
+ with pytest . raises (RuntimeError ):
186
184
x .normal_form ("z" )
187
185
188
186
if hasattr (t , "rewrite" ):
189
- self . assertEqual ( x .rewrite ("aa" ), "" )
190
- self . assertEqual ( x .rewrite ("bb" ), "B" )
187
+ assert x .rewrite ("aa" ) == ""
188
+ assert x .rewrite ("bb" ) == "B"
191
189
192
- with self . assertRaises (TypeError ):
193
- self . assertEqual ( x .rewrite ("z" ) )
190
+ with pytest . raises (TypeError ):
191
+ x .rewrite ("z" )
194
192
195
193
196
194
def check_running_and_state (T ):
0 commit comments