@@ -88,26 +88,34 @@ def test_error_duplicate_case(self):
88
88
s .case (1 , lambda : None )
89
89
90
90
def test_multiple_values_one_case_range (self ):
91
- value = 7
92
-
93
91
executed_case = None
94
92
95
93
def get_set_case (val ):
96
94
nonlocal executed_case
97
95
executed_case = val
98
96
99
- # I'm a little unsure what is the right way to handle this
100
- # On one hand, reading case(range(1,5)) seems like it should
101
- # include 1, 2, 3, 4, 5.
102
- # But list(range(1,5)) is [1,2,3,4]. So that would be inconsistent.
103
- # Thoughts?
104
- # I'm going with 1,2,3,4,5 for range(1,5) for now.
105
- with switch (value ) as s :
106
- s .case (range (1 , 5 ), lambda : get_set_case ("1-to-5" ))
97
+ for value in range (1 , 5 ):
98
+ with switch (value ) as s :
99
+ s .case (range (1 , 6 ), lambda : get_set_case ("1-to-5" ))
100
+ s .case (range (6 , 7 ), lambda : get_set_case ("6-to-7" ))
101
+ s .default (lambda : get_set_case ('default' ))
102
+
103
+ self .assertEqual (executed_case , "1-to-5" )
104
+
105
+ for value in range (6 , 7 ):
106
+ with switch (value ) as s :
107
+ s .case (range (1 , 6 ), lambda : get_set_case ("1-to-5" ))
108
+ s .case (range (6 , 7 ), lambda : get_set_case ("6-to-7" ))
109
+ s .default (lambda : get_set_case ('default' ))
110
+
111
+ self .assertEqual (executed_case , "6-to-7" )
112
+
113
+ with switch (7 ) as s :
114
+ s .case (range (1 , 6 ), lambda : get_set_case ("1-to-5" ))
107
115
s .case (range (6 , 7 ), lambda : get_set_case ("6-to-7" ))
108
116
s .default (lambda : get_set_case ('default' ))
109
117
110
- self .assertEqual (executed_case , "6-to-7 " )
118
+ self .assertEqual (executed_case , "default " )
111
119
112
120
def test_multiple_values_one_case_list (self ):
113
121
value = 6
0 commit comments