@@ -6,27 +6,25 @@ chaiConfig.truncateThreshold = 0;
6
6
import * as LC from "../../src/lambda-calculus.js" ;
7
7
LC . config . purity = "LetRec" ;
8
8
LC . config . numEncoding = "Church" ;
9
- // LC.config.verbosity = "Concise"; // reinstate for production
9
+ LC . config . verbosity = "Concise" ;
10
10
11
11
const solutionText = readFileSync ( new URL ( "./solution.txt" , import . meta. url ) , { encoding : "utf8" } ) ;
12
+ const { multiply} = LC . compile ( solutionText ) ;
13
+ const fromInt = LC . fromIntWith ( LC . config ) ;
14
+ const toInt = LC . toIntWith ( LC . config ) ;
12
15
13
- describe ( "Multiply" , function ( ) {
14
- // REVIEW Is this intentional? If so, it should be tested that `compile` throws
15
- // and remove other test cases.
16
- try {
17
- const { multiply} = LC . compile ( solutionText ) ;
18
- it ( "example tests" , ( ) => {
19
- assert . equal ( multiply ( 7 ) ( 7 ) , 49 ) ;
20
- assert . equal ( multiply ( 11 ) ( 11 ) , 121 ) ;
16
+ describe ( "Multiply" , ( ) => {
17
+
18
+ it ( "example tests" , function ( ) {
19
+ assert . equal ( toInt ( multiply ( fromInt ( 7 ) ) ( fromInt ( 7 ) ) ) , 49 ) ;
20
+ assert . equal ( toInt ( multiply ( fromInt ( 11 ) ) ( fromInt ( 11 ) ) ) , 121 ) ;
21
21
} ) ;
22
- it ( "random tests" , ( ) => {
22
+
23
+ it ( "random tests" , function ( ) {
23
24
const rnd = ( m , n = 0 ) => Math . random ( ) * ( n - m ) + m | 0 ;
24
25
for ( let i = 1 ; i <= 100 ; i ++ ) {
25
26
const m = rnd ( i ) , n = rnd ( i ) ;
26
- assert . equal ( multiply ( m ) ( n ) , m * n ) ;
27
+ assert . equal ( toInt ( multiply ( fromInt ( m ) ) ( fromInt ( n ) ) ) , m * n ) ;
27
28
}
28
29
} ) ;
29
- } catch ( e ) {
30
- console . error ( e ) ;
31
- }
32
30
} ) ;
0 commit comments