]> gitweb.factorcode.org Git - factor.git/blob - basis/combinators/short-circuit/short-circuit-tests.factor
factor: rename [ ] [ ] unit-test -> { } [ ] unit-test using a refactoring tool!
[factor.git] / basis / combinators / short-circuit / short-circuit-tests.factor
1 USING: kernel math tools.test combinators.short-circuit accessors ;
2 IN: combinators.short-circuit.tests
3
4 { 3 } [ { [ 1 ] [ 2 ] [ 3 ] } 0&& ] unit-test
5 { 5 } [ 3 { [ 0 > ] [ odd? ] [ 2 + ] } 1&& ] unit-test
6 { 30 } [ 10 20 { [ + 0 > ] [ - even? ] [ + ] } 2&& ] unit-test
7
8 { f } [ { [ 1 ] [ f ] [ 3 ] } 0&& ] unit-test
9 { f } [ 3 { [ 0 > ] [ even? ] [ 2 + ] } 1&& ] unit-test
10 { f } [ 10 20 { [ + 0 > ] [ - odd? ] [ + ] } 2&& ] unit-test
11
12 { "factor" } [ { [ 10 0 < ] [ f ] [ "factor" ] } 0|| ] unit-test
13 { 11 } [ 10 { [ odd? ] [ 100 > ] [ 1 + ] } 1|| ] unit-test
14 { 30 } [ 10 20 { [ + odd? ] [ + 100 > ] [ + ] } 2|| ] unit-test
15 { f } [ { [ 10 0 < ] [ f ] [ 0 1 = ] } 0|| ] unit-test
16
17 : compiled-&& ( a -- ? ) { [ 0 > ] [ even? ] [ 2 + ] } 1&& ;
18
19 { f } [ 3 compiled-&& ] unit-test
20 { 4 } [ 2 compiled-&& ] unit-test
21
22 : compiled-|| ( a b -- ? ) { [ + odd? ] [ + 100 > ] [ + ] } 2|| ;
23
24 { 30 } [ 10 20 compiled-|| ] unit-test
25 { 2 } [ 1 1 compiled-|| ] unit-test
26
27 ! && and || should be row-polymorphic both when compiled and when interpreted
28
29 : row-&& ( -- ? )
30     f t { [ drop dup ] } 1&& nip ;
31
32 { f } [ row-&& ] unit-test
33 { f } [ \ row-&& def>> call ] unit-test
34
35 : row-|| ( -- ? )
36     f t { [ drop dup ] } 1|| nip ;
37
38 { f } [ row-|| ] unit-test
39 { f } [ \ row-|| def>> call ] unit-test