Add some more tests for nested formulas
This commit is contained in:
parent
aebf318f83
commit
4e9a0f6cb5
2 changed files with 17 additions and 0 deletions
|
@ -875,6 +875,8 @@ export default class Formula<T extends [FormulaSource] | FormulaSource[]> {
|
||||||
}
|
}
|
||||||
|
|
||||||
invertIntegral(value: DecimalSource): DecimalSource {
|
invertIntegral(value: DecimalSource): DecimalSource {
|
||||||
|
// This is nearly completely non-functional
|
||||||
|
// Proper nesting will require somehow using integration by substitution or integration by parts
|
||||||
return this.internalInvertIntegral?.call(this, value, ...this.inputs) ?? value;
|
return this.internalInvertIntegral?.call(this, value, ...this.inputs) ?? value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -563,6 +563,11 @@ describe("Inverting", () => {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("Inverting nested formulas", () => {
|
||||||
|
const formula = Formula.add(variable, constant).times(constant);
|
||||||
|
expect(formula.invert(100)).compare_tolerance(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Integrating", () => {
|
describe("Integrating", () => {
|
||||||
|
@ -643,6 +648,11 @@ describe("Integrating", () => {
|
||||||
|
|
||||||
// TODO I think these tests will require writing at least one known example for every function
|
// TODO I think these tests will require writing at least one known example for every function
|
||||||
describe.todo("Integrable formulas integrate correctly");
|
describe.todo("Integrable formulas integrate correctly");
|
||||||
|
|
||||||
|
test("Integrating nested formulas", () => {
|
||||||
|
const formula = Formula.add(variable, constant).times(constant);
|
||||||
|
expect(formula.evaluateIntegral()).compare_tolerance(1500);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Inverting integrals", () => {
|
describe("Inverting integrals", () => {
|
||||||
|
@ -721,6 +731,11 @@ describe("Inverting integrals", () => {
|
||||||
|
|
||||||
// TODO I think these tests will require writing at least one known example for every function
|
// TODO I think these tests will require writing at least one known example for every function
|
||||||
describe.todo("Invertible Integral formulas invert correctly");
|
describe.todo("Invertible Integral formulas invert correctly");
|
||||||
|
|
||||||
|
test("Inverting integral of nested formulas", () => {
|
||||||
|
const formula = Formula.add(variable, constant).times(constant);
|
||||||
|
expect(formula.invertIntegral(1500)).compare_tolerance(10);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Step-wise", () => {
|
describe("Step-wise", () => {
|
||||||
|
|
Loading…
Reference in a new issue