12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
import unittest
15
+ from dataclasses import asdict
15
16
16
17
from dash import dash_table
17
18
from numpy import asarray
@@ -47,14 +48,14 @@ def test_initial_sched(self):
47
48
48
49
# Check that CQM created has the right number of variables
49
50
def test_cqm (self ):
50
- cqm = employee_scheduling .build_cqm (self .test_params )
51
+ cqm = employee_scheduling .build_cqm (** asdict ( self .test_params ) )
51
52
52
53
self .assertEqual (len (cqm .variables ),
53
54
self .num_employees * len (self .shifts ))
54
55
55
56
# Check that NL assignments variable is the correct shape
56
57
def test_nl (self ):
57
- _ , assignments = employee_scheduling .build_nl (self .test_params )
58
+ _ , assignments = employee_scheduling .build_nl (** asdict ( self .test_params ) )
58
59
59
60
self .assertEqual (assignments .shape (),
60
61
(self .num_employees , len (self .shifts )))
@@ -84,7 +85,7 @@ def test_samples_cqm(self):
84
85
max_consecutive_shifts = 6
85
86
)
86
87
87
- cqm = employee_scheduling .build_cqm (test_params )
88
+ cqm = employee_scheduling .build_cqm (** asdict ( test_params ) )
88
89
89
90
feasible_sample = {
90
91
"A-Mgr_1" : 0.0 ,
@@ -180,7 +181,7 @@ def test_states_nl(self):
180
181
max_consecutive_shifts = 6
181
182
)
182
183
183
- model , assignments = employee_scheduling .build_nl (test_params )
184
+ model , assignments = employee_scheduling .build_nl (** asdict ( test_params ) )
184
185
185
186
if not model .is_locked ():
186
187
model .lock ()
@@ -274,6 +275,7 @@ def test_build_from_sample(self):
274
275
275
276
def test_build_from_state (self ):
276
277
employees = ["A-Mgr" , "B-Mgr" , "C" , "D" , "E" , "E-Tr" ]
278
+ shifts = [str (i + 1 ) for i in range (14 )]
277
279
278
280
# Make every employee available for every shift
279
281
availability = {
@@ -286,15 +288,17 @@ def test_build_from_state(self):
286
288
}
287
289
288
290
state = asarray ([
289
- [0 , 0 , 1 , 1 , 1 ],
290
- [1 , 1 , 0 , 0 , 0 ],
291
- [1 , 1 , 1 , 1 , 1 ],
292
- [1 , 1 , 1 , 1 , 1 ],
293
- [1 , 1 , 1 , 1 , 1 ]
291
+ # Give managers alternating shifts
292
+ [i % 2 for i in range (14 )],
293
+ [(i + 1 ) % 2 for i in range (14 )],
294
+ [1 for _ in range (14 )],
295
+ [1 for _ in range (14 )],
296
+ [1 for _ in range (14 )],
297
+ [1 for _ in range (14 )],
294
298
])
295
299
296
300
disp_datatable = utils .display_schedule (
297
- utils .build_schedule_from_state (state , employees ),
301
+ utils .build_schedule_from_state (state , employees , shifts ),
298
302
availability
299
303
)
300
304
0 commit comments