Skip to content

Commit

Permalink
feat: Updated packages/squiggle-lang/__tests__/lib
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] authored Oct 29, 2023
1 parent 214c4f0 commit d876c36
Showing 1 changed file with 37 additions and 22 deletions.
59 changes: 37 additions & 22 deletions packages/squiggle-lang/__tests__/library/number_test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,50 @@
import { testEvalToBe } from "../helpers/reducerHelpers.js";

describe("Numbers", () => {
testEvalToBe("Number.floor(5.5)", "5");
testEvalToBe("Number.ceil(5.5)", "6");
testEvalToBe("floor(5.5)", "5");
testEvalToBe("ceil(5.5)", "6");
testEvalToBe("Number.abs(5.5)", "5.5");
testEvalToBe("Number.abs(-5.5)", "5.5");
const num = 5.5;
const negativeNum = -5.5;
const expNum = 10;
const sumEmptyList = [];
const sumList = [2,5,3];
const productEmptyList = [];
const productList = [2,5,3];

testEvalToBe(`Number.floor(${num})`, "5");
testEvalToBe(`Number.ceil(${num})`, "6");
testEvalToBe(`floor(${num})`, "5");
testEvalToBe(`ceil(${num})`, "6");
testEvalToBe(`Number.abs(${num})`, "5.5");
testEvalToBe(`Number.abs(${negativeNum})`, "5.5");
testEvalToBe("Number.abs(0)", "0");
testEvalToBe("abs(5.5)", "5.5");
testEvalToBe("Number.exp(10)", "22026.465794806718");
testEvalToBe("Number.log10(10)", "1");
testEvalToBe("Number.log2(10)", "3.321928094887362");
testEvalToBe("Number.sum([])", "0");
testEvalToBe("Number.sum([2,5,3])", "10");
testEvalToBe("sum([])", "0");
testEvalToBe("sum([2,5,3])", "10");
testEvalToBe("Number.product([])", "1");
testEvalToBe("Number.product([2,5,3])", "30");
testEvalToBe(`abs(${num})`, "5.5");
testEvalToBe(`Number.exp(${expNum})`, "22026.465794806718");
testEvalToBe(`Number.log10(${expNum})`, "1");
testEvalToBe(`Number.log2(${expNum})`, "3.321928094887362");
testEvalToBe(`Number.sum(${sumEmptyList})`, "0");
testEvalToBe(`Number.sum(${sumList})`, "10");
testEvalToBe(`sum(${sumEmptyList})`, "0");
testEvalToBe(`sum(${sumList})`, "10");
testEvalToBe(`Number.product(${productEmptyList})`, "1");
testEvalToBe(`Number.product(${productList})`, "30");
testEvalToBe("Number.min([2,5,3])", "2");
testEvalToBe("Number.max([2,5,3])", "5");
testEvalToBe("Number.mean([0,5,10])", "5");
testEvalToBe("Number.geomean([1,5,18])", "4.481404746557164");
testEvalToBe("Number.stdev([0,5,10,15])", "5.5901699437494745");
testEvalToBe("Number.variance([0,5,10,15])", "31.25");
testEvalToBe("Number.sort([])", "[]");
testEvalToBe("Number.sort([10,0,15,5])", "[0,5,10,15]");
testEvalToBe("Number.cumsum([])", "[]");
testEvalToBe("Number.cumsum([1,5,3])", "[1,6,9]");
testEvalToBe("Number.cumprod([])", "[]");
testEvalToBe("Number.cumprod([1,5,3])", "[1,5,15]");
const sortEmptyList = [];
const sortList = [10,0,15,5];
const cumsumEmptyList = [];
const cumsumList = [1,5,3];
const cumprodEmptyList = [];
const cumprodList = [1,5,3];

testEvalToBe(`Number.sort(${sortEmptyList})`, "[]");
testEvalToBe(`Number.sort(${sortList})`, "[0,5,10,15]");
testEvalToBe(`Number.cumsum(${cumsumEmptyList})`, "[]");
testEvalToBe(`Number.cumsum(${cumsumList})`, "[1,6,9]");
testEvalToBe(`Number.cumprod(${cumprodEmptyList})`, "[]");
testEvalToBe(`Number.cumprod(${cumprodList})`, "[1,5,15]");
testEvalToBe("Number.diff([1])", "[]");
testEvalToBe("Number.diff([1,5,3])", "[4,-2]");
});

0 comments on commit d876c36

Please sign in to comment.