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 dd95804
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 17 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
21 changes: 15 additions & 6 deletions tests/bindings/javascript/analyserequation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,23 @@ describe("Analyser Equation tests", () => {
test('Checking Analyser Equation nlaSibling.', () => {
expect(eqn.nlaSibling(0)).toBe(null)
});
test('Checking Analyser Equation variableCount.', () => {
expect(eqn.variableCount()).toBe(1)
test('Checking Analyser Equation computedConstantCount.', () => {
expect(eqn.computedConstantCount()).toBe(1)
});
test('Checking Analyser Equation variables.', () => {
expect(eqn.variables().size()).toBe(1)
test('Checking Analyser Equation computedConstants.', () => {
expect(eqn.computedConstants().size()).toBe(1)
});
test('Checking Analyser Equation variable.', () => {
expect(eqn.variable(0).variable().name()).toBe("x")
test('Checking Analyser Equation computedConstant.', () => {
expect(eqn.computedConstant(0).variable().name()).toBe("x")
});
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
18 changes: 14 additions & 4 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(18)
expect(am.constants().size()).toBe(18)
expect(am.constant(2).variable().name()).toBe("i_K")
});
test('Checking Analyser Model computed constants related API.', () => {
expect(am.computedConstantCount()).toBe(18)
expect(am.computedConstants().size()).toBe(18)
expect(am.computedConstant(2).variable().name()).toBe("i_K")
});
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
4 changes: 3 additions & 1 deletion tests/bindings/javascript/analyservariable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ describe("Analyser Variable tests", () => {

am = a.model()

expect(am.variableCount()).toBe(18)
expect(am.constantCount()).toBe(18)
expect(am.computedConstantCount()).toBe(18)
expect(am.algebraicCount()).toBe(18)
});
test('Checking Analyser Variable type.', () => {
const av = am.variable(0)
Expand Down

0 comments on commit dd95804

Please sign in to comment.