From f94c0c1f68a9e1a7be92ed7312136b8ba10f922b Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Thu, 23 Mar 2023 20:00:06 -0500 Subject: [PATCH] Add some more tests for step-wise and conditional formulas --- tests/game/formulas.test.ts | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/game/formulas.test.ts b/tests/game/formulas.test.ts index 967080d..13a6e53 100644 --- a/tests/game/formulas.test.ts +++ b/tests/game/formulas.test.ts @@ -759,6 +759,17 @@ describe("Step-wise", () => { ).compare_tolerance(10)); }); + describe("Pass-through at boundary", () => { + test("Evaluates correctly", () => + expect( + Formula.step(constant, 10, value => Formula.sqrt(value)).evaluate() + ).compare_tolerance(10)); + test("Inverts correctly with variable in input", () => + expect( + Formula.step(variable, 10, value => Formula.sqrt(value)).invert(10) + ).compare_tolerance(10)); + }); + describe("Evaluates correctly beyond start", () => { test("Evaluates correctly", () => expect( @@ -769,6 +780,23 @@ describe("Step-wise", () => { Formula.step(variable, 8, value => Formula.add(value, 2)).invert(12) ).compare_tolerance(10)); }); + + describe("Evaluates correctly when nested", () => { + test("Evaluates correctly", () => + expect( + Formula.add(variable, constant) + .step(10, value => Formula.mul(value, 2)) + .sub(10) + .evaluate() + ).compare_tolerance(20)); + test("Inverts correctly", () => + expect( + Formula.add(variable, constant) + .step(10, value => Formula.mul(value, 2)) + .sub(10) + .invert(30) + ).compare_tolerance(15)); + }); }); describe("Conditionals", () => { @@ -842,6 +870,23 @@ describe("Conditionals", () => { Formula.if(variable, true, value => Formula.add(value, 2)).invert(12) ).compare_tolerance(10)); }); + + describe("Evaluates correctly when nested", () => { + test("Evaluates correctly", () => + expect( + Formula.add(variable, constant) + .if(true, value => Formula.add(value, 2)) + .div(2) + .evaluate() + ).compare_tolerance(11)); + test("Inverts correctly", () => + expect( + Formula.add(variable, constant) + .if(true, value => Formula.add(value, 2)) + .div(2) + .invert(12) + ).compare_tolerance(12)); + }); }); describe("Custom Formulas", () => {