simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

tests.js (1805B)


      1 import { transformer } from "./index.js";
      2 
      3 let VERBOSE = true;
      4 let print = (x) => {
      5   if (VERBOSE) {
      6     console.log(x);
      7   }
      8 };
      9 
     10 let testTransformer = (string) => {
     11   console.log(string);
     12   console.group();
     13   print("");
     14   let result = transformer(string, print);
     15   print("");
     16   console.groupEnd();
     17   console.log(`=> ${result.squiggleString}`);
     18   print("");
     19   print(result);
     20   print("-".repeat(52));
     21   console.log("");
     22 };
     23 
     24 // Define tests
     25 let tests1 = [
     26   `lognormal(1,10) * lognormal(1,10) + lognormal(1,10)`,
     27   `lognormal(1,10) * lognormal(1,10) * lognormal(1,10)`,
     28   `1 to 10 * lognormal(1, 10)`,
     29   `lognormal(1, 10) * 1 to 20`,
     30   `1 to 20 * 100 to 1000`,
     31   `(lognormal(1,10) / lognormal(1,10)) + lognormal(1,10)`,
     32   `lognormal(1,10) * lognormal(1,10) / lognormal(1,10)`,
     33   `1 to 10 * lognormal(1, 10) / 1 to 10`,
     34   `lognormal(1, 10) * 1 to 20 / 1 to 20`,
     35   `1 to 20 * 100 to 1000 / 1 to 100`,
     36 ];
     37 
     38 let tests2 = [
     39   `3 * lognormal(1,10)`,
     40   `lognormal(1,10) * 4`,
     41   `lognormal(1, 10) / 3`,
     42   `3 / lognormal(1, 10)`,
     43   `lognormal(1,10) * lognormal(1/10) / 3`,
     44   `lognormal(1, 10) / (1 to 3)`,
     45 ];
     46 
     47 let tests3 = [
     48   `(lognormal(1,10))`,
     49   `lognormal(1,10) * (lognormal(1, 10) * 3) / (4 * lognormal(1,10))`,
     50 ];
     51 
     52 let tests4 = [
     53   `(1 to 2) * 3 * lognormal(1,10) * (1/lognormal(1,10)) / (1 to 10)`,
     54   `lognormal(2.4451858789480823, 10.002219515733781) * lognormal(-1, 10) `,
     55 ];
     56 
     57 // Run tests
     58 console.log("\n".repeat(10));
     59 console.clear();
     60 let runTests1 = true;
     61 if (runTests1) {
     62   tests1.forEach((test) => testTransformer(test));
     63 }
     64 
     65 let runTests2 = true;
     66 if (runTests2) {
     67   tests2.forEach((test) => testTransformer(test));
     68 }
     69 
     70 let runTests3 = true;
     71 if (runTests3) {
     72   tests3.forEach((test) => testTransformer(test));
     73 }
     74 
     75 let runTests4 = true;
     76 if (runTests4) {
     77   tests4.forEach((test) => testTransformer(test));
     78 }