22
33import com .jnape .palatable .lambda .adt .hlist .Tuple2 ;
44import com .jnape .palatable .lambda .functions .Fn1 ;
5- import com .jnape .palatable .lambda .io .IO ;
65import com .jnape .palatable .traitor .annotations .TestTraits ;
76import com .jnape .palatable .traitor .runners .Traits ;
87import org .junit .Test ;
1817import java .util .function .Function ;
1918
2019import static com .jnape .palatable .lambda .adt .Unit .UNIT ;
21- import static com .jnape .palatable .lambda .io .IO .externallyManaged ;
22- import static com .jnape .palatable .lambda .io .IO .io ;
2320import static com .jnape .palatable .lambda .functions .builtin .fn2 .Tupler2 .tupler ;
2421import static com .jnape .palatable .lambda .functions .builtin .fn3 .Times .times ;
2522import static com .jnape .palatable .lambda .functions .specialized .checked .CheckedSupplier .checked ;
23+ import static com .jnape .palatable .lambda .io .IO .externallyManaged ;
24+ import static com .jnape .palatable .lambda .io .IO .io ;
2625import static java .util .concurrent .CompletableFuture .completedFuture ;
2726import static java .util .concurrent .Executors .newFixedThreadPool ;
2827import static java .util .concurrent .ForkJoinPool .commonPool ;
2928import static org .junit .Assert .assertEquals ;
29+ import static testsupport .Constants .STACK_EXPLODING_NUMBER ;
3030
3131@ RunWith (Traits .class )
3232public class IOTest {
3333
34- private static final int STACK_EXPLODING_NUMBER = 50_000 ;
35-
3634 @ TestTraits ({FunctorLaws .class , ApplicativeLaws .class , MonadLaws .class })
3735 public EqualityAwareIO <Integer > testSubject () {
3836 return new EqualityAwareIO <>(io (1 ));
@@ -125,23 +123,23 @@ public void exceptionallyRescuesFutures() {
125123
126124 @ Test
127125 public void linearSyncStackSafety () {
128- assertEquals (( Integer ) STACK_EXPLODING_NUMBER ,
126+ assertEquals (STACK_EXPLODING_NUMBER ,
129127 times (STACK_EXPLODING_NUMBER , f -> f .fmap (x -> x + 1 ), io (0 )).unsafePerformIO ());
130- assertEquals (( Integer ) STACK_EXPLODING_NUMBER ,
128+ assertEquals (STACK_EXPLODING_NUMBER ,
131129 times (STACK_EXPLODING_NUMBER , f -> f .zip (f .pure (x -> x + 1 )), io (0 )).unsafePerformIO ());
132130 assertEquals ((Integer ) 0 ,
133131 times (STACK_EXPLODING_NUMBER , f -> f .pure (0 ).discardR (f ), io (0 )).unsafePerformIO ());
134132 assertEquals ((Integer ) 1 ,
135133 times (STACK_EXPLODING_NUMBER , f -> f .pure (1 ).discardR (f ), io (0 )).unsafePerformIO ());
136134 assertEquals ((Integer ) 0 ,
137135 times (STACK_EXPLODING_NUMBER , f -> f .pure (1 ).discardL (f ), io (0 )).unsafePerformIO ());
138- assertEquals (( Integer ) STACK_EXPLODING_NUMBER ,
136+ assertEquals (STACK_EXPLODING_NUMBER ,
139137 times (STACK_EXPLODING_NUMBER , f -> f .flatMap (x -> f .pure (x + 1 )), io (0 )).unsafePerformIO ());
140138 }
141139
142140 @ Test
143141 public void recursiveSyncFlatMapStackSafety () {
144- assertEquals (( Integer ) STACK_EXPLODING_NUMBER ,
142+ assertEquals (STACK_EXPLODING_NUMBER ,
145143 new Fn1 <IO <Integer >, IO <Integer >>() {
146144 @ Override
147145 public IO <Integer > apply (IO <Integer > a ) {
@@ -153,9 +151,9 @@ public IO<Integer> apply(IO<Integer> a) {
153151
154152 @ Test
155153 public void linearAsyncStackSafety () {
156- assertEquals (( Integer ) STACK_EXPLODING_NUMBER ,
154+ assertEquals (STACK_EXPLODING_NUMBER ,
157155 times (STACK_EXPLODING_NUMBER , f -> f .fmap (x -> x + 1 ), io (0 )).unsafePerformAsyncIO ().join ());
158- assertEquals (( Integer ) STACK_EXPLODING_NUMBER ,
156+ assertEquals (STACK_EXPLODING_NUMBER ,
159157 times (STACK_EXPLODING_NUMBER , f -> f .zip (f .pure (x -> x + 1 )), io (0 )).unsafePerformAsyncIO ()
160158 .join ());
161159 assertEquals ((Integer ) 0 ,
@@ -164,14 +162,14 @@ public void linearAsyncStackSafety() {
164162 times (STACK_EXPLODING_NUMBER , f -> f .pure (1 ).discardR (f ), io (0 )).unsafePerformAsyncIO ().join ());
165163 assertEquals ((Integer ) 0 ,
166164 times (STACK_EXPLODING_NUMBER , f -> f .pure (1 ).discardL (f ), io (0 )).unsafePerformAsyncIO ().join ());
167- assertEquals (( Integer ) STACK_EXPLODING_NUMBER ,
165+ assertEquals (STACK_EXPLODING_NUMBER ,
168166 times (STACK_EXPLODING_NUMBER , f -> f .flatMap (x -> f .pure (x + 1 )), io (0 )).unsafePerformAsyncIO ()
169167 .join ());
170168 }
171169
172170 @ Test
173171 public void recursiveAsyncFlatMapStackSafety () {
174- assertEquals (( Integer ) STACK_EXPLODING_NUMBER ,
172+ assertEquals (STACK_EXPLODING_NUMBER ,
175173 new Fn1 <IO <Integer >, IO <Integer >>() {
176174 @ Override
177175 public IO <Integer > apply (IO <Integer > a ) {
0 commit comments