Coverage for tests/unit/generation/test_bool_array_from_string.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-24 00:33 -0600

1import numpy as np 

2import pytest 

3from numpy.testing import assert_array_equal 

4 

5from maze_dataset.utils import bool_array_from_string 

6 

7 

8def test_bool_array_from_string(): 

9 connection_list = bool_array_from_string( 

10 """ 

11 TTF TFF TFF 

12 TFT FFT FFF 

13 """, 

14 shape=[2, 3, 3], 

15 ) 

16 

17 expected = np.array( 

18 [ 

19 [[True, True, False], [True, False, False], [True, False, False]], 

20 [[True, False, True], [False, False, True], [False, False, False]], 

21 ], 

22 ) 

23 

24 assert_array_equal(expected, connection_list) 

25 

26 

27def test_bool_array_from_string_wrong_shape(): 

28 with pytest.raises(ValueError): # noqa: PT011 

29 bool_array_from_string("TF TF TF F", shape=[2, 2, 2]) 

30 

31 

32def test_bool_array_from_string_custom_symbol(): 

33 actual = bool_array_from_string( 

34 """ 

35 x x x 

36 x _ x 

37 x x x 

38 """, 

39 shape=[3, 3], 

40 true_symbol="_", 

41 ) 

42 

43 expected = [[False, False, False], [False, True, False], [False, False, False]] 

44 

45 assert_array_equal(expected, actual)