From bffc27344a435818c6ab935a3304984bf8f2b7e1 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sun, 30 Apr 2023 11:08:43 -0500 Subject: [PATCH] Fixed isInvertible and isIntegrable not working nested correctly --- src/game/formulas/formulas.ts | 7 +++++-- tests/game/formulas.test.ts | 28 ++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/game/formulas/formulas.ts b/src/game/formulas/formulas.ts index bf989b1..79adfce 100644 --- a/src/game/formulas/formulas.ts +++ b/src/game/formulas/formulas.ts @@ -124,11 +124,14 @@ export abstract class InternalFormula { expect(formula.invert(100)).compare_tolerance(0); }); - test("Inverting with non-invertible sections", () => { - const formula = Formula.add(variable, constant.ceil()); - expect(formula.isInvertible()).toBe(true); - expect(formula.invert(10)).compare_tolerance(0); + describe("Inverting with non-invertible sections", () => { + test("Non-invertible constant", () => { + const formula = Formula.add(variable, constant.ceil()); + expect(formula.isInvertible()).toBe(true); + expect(() => formula.invert(10)).not.toThrow(); + }); + test("Non-invertible variable", () => { + const formula = Formula.add(variable.ceil(), constant); + expect(formula.isInvertible()).toBe(false); + expect(() => formula.invert(10)).toThrow(); + }); }); }); @@ -619,6 +626,19 @@ describe("Integrating", () => { const formula = Formula.pow(1.05, variable).times(100).pow(0.5); expect(() => formula.evaluateIntegral()).toThrow(); }); + + describe("Integrating with non-integrable sections", () => { + test("Non-integrable constant", () => { + const formula = Formula.add(variable, constant.ceil()); + expect(formula.isIntegrable()).toBe(true); + expect(() => formula.evaluateIntegral()).not.toThrow(); + }); + test("Non-integrable variable", () => { + const formula = Formula.add(variable.ceil(), constant); + expect(formula.isIntegrable()).toBe(false); + expect(() => formula.evaluateIntegral()).toThrow(); + }); + }); }); describe("Inverting integrals", () => {