@@ -6,27 +6,25 @@ chaiConfig.truncateThreshold = 0;
66import * as LC from "../../src/lambda-calculus.js" ;
77LC . config . purity = "LetRec" ;
88LC . config . numEncoding = "Church" ;
9- // LC.config.verbosity = "Concise"; // reinstate for production
9+ LC . config . verbosity = "Concise" ;
1010
1111const 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 ) ;
1215
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 ) ;
2121 } ) ;
22- it ( "random tests" , ( ) => {
22+
23+ it ( "random tests" , function ( ) {
2324 const rnd = ( m , n = 0 ) => Math . random ( ) * ( n - m ) + m | 0 ;
2425 for ( let i = 1 ; i <= 100 ; i ++ ) {
2526 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 ) ;
2728 }
2829 } ) ;
29- } catch ( e ) {
30- console . error ( e ) ;
31- }
3230} ) ;
0 commit comments