11# Copyright 2009-2014 Ram Rachum.
22# This program is distributed under the MIT license.
33
4+ import pickle
5+
46from python_toolbox import sequence_tools
57
68from python_toolbox .combi import *
911infinities = (infinity , - infinity )
1012
1113
12- def test_perms ():
14+ def test_perm_spaces ():
1315 pure_0a = PermSpace (4 )
1416 pure_0b = PermSpace (range (4 ))
1517 pure_0c = PermSpace (list (range (4 )))
@@ -41,6 +43,8 @@ def test_perms():
4143 assert pure_perm_space_dict [pure_0a ] == pure_perm_space_dict [pure_0b ] == \
4244 pure_perm_space_dict [pure_0c ] == pure_perm_space_dict [pure_0d ] == 'd'
4345
46+ assert None not in pure_0a # Because, damn.
47+
4448 assert type (first_perm ) == type (some_perm ) == type (last_perm ) == Perm
4549 assert set (some_perm ) == set (range (4 ))
4650 assert tuple (first_perm ) == (0 , 1 , 2 , 3 )
@@ -101,6 +105,15 @@ def test_perms():
101105 assert '...' in repr_of_big_perm_space
102106 assert len (repr_of_big_perm_space ) <= 100
103107
108+ fixed_perm_space = pure_perm_space .get_fixed ({0 : 3 ,})
109+ assert fixed_perm_space .length == 6
110+ assert fixed_perm_space .is_fixed
111+ assert not fixed_perm_space .is_pure
112+ assert fixed_perm_space .unfixed .is_pure
113+ assert fixed_perm_space .unfixed == pure_perm_space
114+
115+ assert pickle .loads (pickle .dumps (pure_perm_space )) == pure_perm_space
116+
104117def test_fixed_perm_space ():
105118 pure_perm_space = PermSpace (5 )
106119 small_fixed_perm_space = PermSpace (5 , fixed_map = {0 : 0 , 2 : 2 , 4 : 4 ,})
@@ -152,6 +165,7 @@ def test_rapplied_perm_space():
152165
153166 assert 'mowe' in rapplied_perm_space
154167 assert 'woof' not in rapplied_perm_space
168+ assert infinite_pure_perm_space [7 ] not in rapplied_perm_space
155169 assert rapplied_perm_space [rapplied_perm_space .index ('wome' )] == \
156170 Perm ('wome' , rapplied_perm_space )
157171
@@ -170,6 +184,7 @@ def test_dapplied_perm_space():
170184
171185 assert (0 , 4 , 2 , 3 , 1 ) in dapplied_perm_space
172186 assert (0 , 4 , 'ooga booga' , 2 , 3 , 1 ) not in dapplied_perm_space
187+ assert infinite_pure_perm_space [7 ] not in rapplied_perm_space
173188
174189 dapplied_perm = dapplied_perm_space [- 1 ]
175190 assert dapplied_perm in dapplied_perm_space
@@ -249,6 +264,9 @@ def test_degreed_perm_space():
249264 assert funky_perm_space .domain == 'travels'
250265 assert funky_perm_space .canonical_slice .start == 2
251266
267+ assert funky_perm_space .undegreed .get_degreed (2 )[0 ] not in funky_perm_space
268+ assert funky_perm_space .get_fixed ({'t' : 'i' , 'v' : 'g' ,}) == funky_perm_space
269+
252270 for i , perm in enumerate (funky_perm_space ):
253271 assert perm .is_dapplied
254272 assert perm .is_rapplied
@@ -307,6 +325,12 @@ def test_degreed_perm_space():
307325 assert not funky_perm_space ._just_fixed .is_sliced
308326 assert not funky_perm_space ._just_fixed .is_degreed
309327
328+ assert pickle .loads (pickle .dumps (funky_perm_space )) == funky_perm_space
329+ assert funky_perm_space != \
330+ pickle .loads (pickle .dumps (funky_perm_space .unfixed )) == \
331+ funky_perm_space .unfixed
332+
333+
310334
311335def test_partial_perm_space ():
312336 with cute_testing .RaiseAssertor ():
0 commit comments