Skip to content

Commit

Permalink
Updated our JavaScript bindings.
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Aug 7, 2024
1 parent cb2f075 commit 5628b66
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 41 deletions.
9 changes: 6 additions & 3 deletions src/bindings/javascript/analyserequation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ EMSCRIPTEN_BINDINGS(libcellml_analyserequation)
.function("nlaSiblings", &libcellml::AnalyserEquation::nlaSiblings)
.function("nlaSibling", &libcellml::AnalyserEquation::nlaSibling)
.function("isStateRateBased", &libcellml::AnalyserEquation::isStateRateBased)
.function("variableCount", &libcellml::AnalyserEquation::variableCount)
.function("variables", &libcellml::AnalyserEquation::variables)
.function("variable", &libcellml::AnalyserEquation::variable)
.function("computedConstantCount", &libcellml::AnalyserEquation::computedConstantCount)
.function("computedConstants", &libcellml::AnalyserEquation::computedConstants)
.function("computedConstant", &libcellml::AnalyserEquation::computedConstant)
.function("algebraicCount", &libcellml::AnalyserEquation::algebraicCount)
.function("algebraicVariables", select_overload<std::vector<libcellml::AnalyserVariablePtr>() const>(&libcellml::AnalyserEquation::algebraic))
.function("algebraicVariable", select_overload<libcellml::AnalyserVariablePtr(size_t) const>(&libcellml::AnalyserEquation::algebraic))
;

EM_ASM(
Expand Down
12 changes: 9 additions & 3 deletions src/bindings/javascript/analysermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ EMSCRIPTEN_BINDINGS(libcellml_analysermodel)
.function("stateCount", &libcellml::AnalyserModel::stateCount)
.function("states", &libcellml::AnalyserModel::states)
.function("state", &libcellml::AnalyserModel::state)
.function("variableCount", &libcellml::AnalyserModel::variableCount)
.function("variables", &libcellml::AnalyserModel::variables)
.function("variable", &libcellml::AnalyserModel::variable)
.function("constantCount", &libcellml::AnalyserModel::constantCount)
.function("constants", &libcellml::AnalyserModel::constants)
.function("constant", &libcellml::AnalyserModel::constant)
.function("computedConstantCount", &libcellml::AnalyserModel::computedConstantCount)
.function("computedConstants", &libcellml::AnalyserModel::computedConstants)
.function("computedConstant", &libcellml::AnalyserModel::computedConstant)
.function("algebraicCount", &libcellml::AnalyserModel::algebraicCount)
.function("algebraicVariables", select_overload<std::vector<libcellml::AnalyserVariablePtr>() const>(&libcellml::AnalyserModel::algebraic))
.function("algebraicVariable", select_overload<libcellml::AnalyserVariablePtr(size_t) const>(&libcellml::AnalyserModel::algebraic))
.function("equationCount", &libcellml::AnalyserModel::equationCount)
.function("equations", &libcellml::AnalyserModel::equations)
.function("equation", &libcellml::AnalyserModel::equation)
Expand Down
25 changes: 17 additions & 8 deletions tests/bindings/javascript/analyserequation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe("Analyser Equation tests", () => {
expect(eqn.dependencies().size()).toBe(0)
});
test('Checking Analyser Equation dependency.', () => {
expect(eqn.dependency(0)).toBe(null)
expect(eqn.dependency(0)).toBeNull()
});
test('Checking Analyser Equation nlaSystemIndex.', () => {
expect(eqn.nlaSystemIndex()).toBe(4294967295)
Expand All @@ -68,16 +68,25 @@ describe("Analyser Equation tests", () => {
expect(eqn.nlaSiblings().size()).toBe(0)
});
test('Checking Analyser Equation nlaSibling.', () => {
expect(eqn.nlaSibling(0)).toBe(null)
expect(eqn.nlaSibling(0)).toBeNull()
});
test('Checking Analyser Equation variableCount.', () => {
expect(eqn.variableCount()).toBe(1)
test('Checking Analyser Equation computedConstantCount.', () => {
expect(eqn.computedConstantCount()).toBe(0)
});
test('Checking Analyser Equation variables.', () => {
expect(eqn.variables().size()).toBe(1)
test('Checking Analyser Equation computedConstants.', () => {
expect(eqn.computedConstants().size()).toBe(0)
});
test('Checking Analyser Equation variable.', () => {
expect(eqn.variable(0).variable().name()).toBe("x")
test('Checking Analyser Equation computedConstant.', () => {
expect(eqn.computedConstant(0)).toBeNull()
});
test('Checking Analyser Equation algebraicCount.', () => {
expect(eqn.algebraicCount()).toBe(1)
});
test('Checking Analyser Equation algebraicVariables.', () => {
expect(eqn.algebraicVariables().size()).toBe(1)
});
test('Checking Analyser Equation algebraicVariable.', () => {
expect(eqn.algebraicVariable(0).variable().name()).toBe("x")
});
test('Checking Analyser Equation AST.', () => {
expect(eqn.ast().value()).toBe("")
Expand Down
20 changes: 15 additions & 5 deletions tests/bindings/javascript/analysermodel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,20 @@ describe("Analyser Model tests", () => {
expect(am.states().size()).toBe(4)
expect(am.state(2).variable().name()).toBe("m")
});
test('Checking Analyser Model variables related API.', () => {
expect(am.variableCount()).toBe(18)
expect(am.variables().size()).toBe(18)
expect(am.variable(2).variable().name()).toBe("i_K")
test('Checking Analyser Model constants related API.', () => {
expect(am.constantCount()).toBe(0)
expect(am.constants().size()).toBe(0)
expect(am.constant(2)).toBeNull()
});
test('Checking Analyser Model computed constants related API.', () => {
expect(am.computedConstantCount()).toBe(0)
expect(am.computedConstants().size()).toBe(0)
expect(am.computedConstant(2)).toBeNull()
});
test('Checking Analyser Model algebraic variables related API.', () => {
expect(am.algebraicCount()).toBe(18)
expect(am.algebraicVariables().size()).toBe(18)
expect(am.algebraicVariable(2).variable().name()).toBe("i_K")
});
test('Checking Analyser Model need* API.', () => {
expect(am.needEqFunction()).toBe(false)
Expand Down Expand Up @@ -93,6 +103,6 @@ describe("Analyser Model tests", () => {
expect(am.needAcothFunction()).toBe(false)
});
test('Checking Analyser Model are equivalent variables.', () => {
expect(am.areEquivalentVariables(am.variable(2).variable(), am.variable(7).variable())).toBe(false)
expect(am.areEquivalentVariables(am.algebraicVariable(2).variable(), am.algebraicVariable(7).variable())).toBe(false)
});
})
18 changes: 10 additions & 8 deletions tests/bindings/javascript/analyservariable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,37 @@ describe("Analyser Variable tests", () => {

am = a.model()

expect(am.variableCount()).toBe(18)
expect(am.constantCount()).toBe(0)
expect(am.computedConstantCount()).toBe(0)
expect(am.algebraicCount()).toBe(18)
});
test('Checking Analyser Variable type.', () => {
const av = am.variable(0)
const av = am.algebraicVariable(0)
expect(av.type().value).toBe(libcellml.AnalyserVariable.Type.ALGEBRAIC.value)
expect(libcellml.AnalyserVariable.typeAsString(av.type())).toBe("algebraic")
});
test('Checking Analyser Variable index.', () => {
const av = am.variable(7)
const av = am.algebraicVariable(7)
expect(av.index()).toBe(7)
});
test('Checking Analyser Variable initialising variable.', () => {
const av = am.variable(15)
const av = am.algebraicVariable(15)
expect(av.initialisingVariable().name()).toBe("g_K")
});
test('Checking Analyser Variable variable.', () => {
const av = am.variable(10)
const av = am.algebraicVariable(10)
expect(av.variable().name()).toBe("alpha_m")
});
test('Checking Analyser Equation equationCount.', () => {
const av = am.variable(14)
const av = am.algebraicVariable(14)
expect(av.equationCount()).toBe(1)
});
test('Checking Analyser Variable equations.', () => {
const av = am.variable(14)
const av = am.algebraicVariable(14)
expect(av.equations().size()).toBe(1)
});
test('Checking Analyser Variable equation.', () => {
const av = am.variable(14)
const av = am.algebraicVariable(14)
expect(av.equation(0).type().value).toBe(libcellml.AnalyserEquation.Type.VARIABLE_BASED_CONSTANT.value)
});
})
6 changes: 3 additions & 3 deletions tests/bindings/javascript/generator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe("Generator tests", () => {

a.analyseModel(m)

expect(g.model()).toBe(null)
expect(g.model()).toBeNull()

g.setModel(a.model())

Expand All @@ -62,10 +62,10 @@ describe("Generator tests", () => {
g.setModel(a.model())

const interface_lines = g.interfaceCode().split('\n')
expect(interface_lines.length).toBe(40)
expect(interface_lines.length).toBe(42)

const implementation_lines = g.implementationCode().split('\n')
expect(implementation_lines.length).toBe(67)
expect(implementation_lines.length).toBe(69)

const equation_line_1 = libcellml.Generator.equationCode(a.model().equation(0).ast())
expect(equation_line_1.length).toBe(14)
Expand Down
36 changes: 30 additions & 6 deletions tests/bindings/javascript/generatorprofile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,17 +684,41 @@ describe("GeneratorProfile tests", () => {
x.setImplementationStateCountString("something")
expect(x.implementationStateCountString()).toBe("something")
});
test("Checking GeneratorProfile.interfaceVariableCountString.", () => {
test("Checking GeneratorProfile.interfaceConstantCountString.", () => {
const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C)

x.setInterfaceVariableCountString("something")
expect(x.interfaceVariableCountString()).toBe("something")
x.setInterfaceConstantCountString("something")
expect(x.interfaceConstantCountString()).toBe("something")
});
test("Checking GeneratorProfile.implementationVariableCountString.", () => {
test("Checking GeneratorProfile.implementationConstantCountString.", () => {
const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C)

x.setImplementationVariableCountString("something")
expect(x.implementationVariableCountString()).toBe("something")
x.setImplementationConstantCountString("something")
expect(x.implementationConstantCountString()).toBe("something")
});
test("Checking GeneratorProfile.interfaceComputedConstantCountString.", () => {
const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C)

x.setInterfaceComputedConstantCountString("something")
expect(x.interfaceComputedConstantCountString()).toBe("something")
});
test("Checking GeneratorProfile.implementationComputedConstantCountString.", () => {
const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C)

x.setImplementationComputedConstantCountString("something")
expect(x.implementationComputedConstantCountString()).toBe("something")
});
test("Checking GeneratorProfile.interfaceAlgebraicCountString.", () => {
const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C)

x.setInterfaceAlgebraicCountString("something")
expect(x.interfaceAlgebraicCountString()).toBe("something")
});
test("Checking GeneratorProfile.implementationAlgebraicCountString.", () => {
const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C)

x.setImplementationAlgebraicCountString("something")
expect(x.implementationAlgebraicCountString()).toBe("something")
});
test("Checking GeneratorProfile.variableTypeObjectString.", () => {
const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C)
Expand Down
2 changes: 1 addition & 1 deletion tests/bindings/javascript/importsource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("Import Source tests", () => {
const iS = new libcellml.ImportSource()
const m = new libcellml.Model()

expect(iS.model()).toBe(null)
expect(iS.model()).toBeNull()

iS.setModel(m)

Expand Down
4 changes: 2 additions & 2 deletions tests/bindings/javascript/reset.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe("Reset tests", () => {
const r = new libcellml.Reset()
const v = new libcellml.Variable()

expect(r.variable()).toBe(null)
expect(r.variable()).toBeNull()

r.setVariable(v)
expect(r.variable()).toStrictEqual(v)
Expand All @@ -50,7 +50,7 @@ describe("Reset tests", () => {
const r = new libcellml.Reset()
const v = new libcellml.Variable()

expect(r.testVariable()).toBe(null)
expect(r.testVariable()).toBeNull()

r.setTestVariable(v)
expect(r.testVariable()).toStrictEqual(v)
Expand Down
4 changes: 2 additions & 2 deletions tests/bindings/javascript/variable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe("Variable tests", () => {
const v = new libcellml.Variable("V")
const u = new libcellml.Units("mV")

expect(v.units()).toBe(null)
expect(v.units()).toBeNull()

v.setUnitsByName("A")

Expand All @@ -82,7 +82,7 @@ describe("Variable tests", () => {

v.removeUnits()

expect(v.units()).toBe(null)
expect(v.units()).toBeNull()

v.delete()
u.delete()
Expand Down

0 comments on commit 5628b66

Please sign in to comment.