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