@@ -46,6 +46,32 @@ class TestGraphics(unittest.TestCase):
4646 def teardown_method (self , method ):
4747 plt .close ("all" )
4848
49+ def test_expand_dims_unspecified (self ):
50+ self .assertIsNone (expand_dims ())
51+ for nd in (2 , 3 ):
52+ with self .subTest (nd = nd ):
53+ self .assertIsNone (expand_dims (nd = nd ))
54+ self .assertIsNone (expand_dims (None , nd = nd ))
55+
56+ def test_expand_dims_specified (self ):
57+ for nd in (2 , 3 ):
58+ with self .subTest (nd = nd ):
59+ # Zero is an explicit extent, not an unspecified one.
60+ np .testing .assert_array_equal (expand_dims (0 , nd ), [0 , 0 ] * nd )
61+ np .testing .assert_array_equal (expand_dims (3 , nd ), [- 3 , 3 ] * nd )
62+ np .testing .assert_array_equal (expand_dims ([- 2 , 5 ], nd ), [- 2 , 5 ] * nd )
63+ limits = np .arange (2 * nd )
64+ np .testing .assert_array_equal (expand_dims (limits , nd ), limits )
65+ with self .assertRaises (ValueError ):
66+ expand_dims ([1 , 2 , 3 ], nd )
67+
68+ def test_expand_dims_invalid_nd (self ):
69+ for nd in (1 , 4 ):
70+ for dim in (None , 1 ):
71+ with self .subTest (nd = nd , dim = dim ):
72+ with self .assertRaisesRegex (ValueError , "nd is 2 or 3" ):
73+ expand_dims (dim , nd )
74+
4975 def test_expand_dims (self ):
5076 np .testing .assert_array_equal (expand_dims (3 ), [- 3 , 3 , - 3 , 3 ])
5177 np .testing .assert_array_equal (expand_dims (- 3 ), [- 3 , 3 , - 3 , 3 ])
@@ -56,7 +82,9 @@ def test_expand_dims(self):
5682
5783 np .testing .assert_array_equal (expand_dims (- 3 , nd = 3 ), [- 3 , 3 , - 3 , 3 , - 3 , 3 ])
5884 np .testing .assert_array_equal (expand_dims ([1 , 2 ], nd = 3 ), [1 , 2 ] * 3 )
59- np .testing .assert_array_equal (expand_dims ([1 , 2 , 3 , 4 , 5 , 6 ], nd = 3 ), [1 , 2 , 3 , 4 , 5 , 6 ])
85+ np .testing .assert_array_equal (
86+ expand_dims ([1 , 2 , 3 , 4 , 5 , 6 ], nd = 3 ), [1 , 2 , 3 , 4 , 5 , 6 ]
87+ )
6088
6189 with self .assertRaises (ValueError ):
6290 expand_dims ([1 , 2 , 3 ])
0 commit comments