1+ from pytest import raises
12import random
23from syntax_sugar import *
4+ from syntax_sugar .infix import To
35
46def test_int_to_int ():
7+ assert list (1 / to / 1 ) == [1 ]
8+ assert list (2 / to / 1 ) == [2 , 1 ]
59 for i in range (100 ):
610 start , end = random .randint (1 , 1e3 ), random .randint (1 , 1e3 )
711 end += start
@@ -11,6 +15,8 @@ def test_int_to_int():
1115 assert list (start / to / end ) == list (range (start , end - 1 , - 1 ))
1216
1317def test_int_to_int_with_step ():
18+ assert list (1 / to / 1 / by / 2 ) == [1 ]
19+ assert list (2 / to / 1 / by / 2 ) == [2 ]
1420 for i in range (100 ):
1521 start , end = random .randint (1 , 1e3 ), random .randint (1 , 1e3 )
1622 step = random .randint (1 , 10 )
@@ -47,6 +53,22 @@ def test_str_to_str_with_step():
4753 assert str ('v' / to / 'd' / by / - 3 ) == 'vspmjgd'
4854 assert str ('v' / to / 'd' / by / 3 ) == 'vspmjgd'
4955
56+ def test_bad_step ():
57+ to_obj = To (1 , 2 )
58+ for bad_step in ["x" , [], 1.5 ]:
59+ with raises (TypeError ):
60+ to_obj .step = bad_step
61+
62+ with raises (ValueError ):
63+ to_obj .step = 0
64+
65+ with raises (ValueError ):
66+ to_obj .step = - 1
67+
68+ to_obj = To (2 , 1 )
69+ with raises (ValueError ):
70+ to_obj .step = 1
71+
5072def test_take ():
5173 assert 1 / to / INF / take / 5 == [1 ,2 ,3 ,4 ,5 ]
5274
0 commit comments