Add some more tests for step-wise and conditional formulas

This commit is contained in:
thepaperpilot 2023-03-23 20:00:06 -05:00
parent 3b4c098f9e
commit f94c0c1f68

View file

@ -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", () => {