Fixed isInvertible and isIntegrable not working nested correctly

This commit is contained in:
thepaperpilot 2023-04-30 11:08:43 -05:00
parent ff16397cc7
commit bffc27344a
2 changed files with 29 additions and 6 deletions

View file

@ -124,11 +124,14 @@ export abstract class InternalFormula<T extends [FormulaSource] | FormulaSource[
const innermostVariable = numVariables === 1 ? variable?.innermostVariable : undefined;
const invertible = variable?.isInvertible() ?? false;
const integrable = variable?.isIntegrable() ?? false;
return {
inputs,
internalEvaluate: evaluate,
internalInvert: invert,
internalIntegrate: integrate,
internalInvert: invertible ? invert : undefined,
internalIntegrate: integrable ? integrate : undefined,
internalIntegrateInner: integrateInner,
applySubstitution,
innermostVariable,

View file

@ -491,10 +491,17 @@ describe("Inverting", () => {
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", () => {