Skip to content

Commit 874f4a6

Browse files
committed
Updated our JavaScript bindings.
1 parent cb2f075 commit 874f4a6

11 files changed

+100
-46
lines changed

src/bindings/javascript/analyserequation.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ EMSCRIPTEN_BINDINGS(libcellml_analyserequation)
4545
.function("nlaSiblings", &libcellml::AnalyserEquation::nlaSiblings)
4646
.function("nlaSibling", &libcellml::AnalyserEquation::nlaSibling)
4747
.function("isStateRateBased", &libcellml::AnalyserEquation::isStateRateBased)
48-
.function("variableCount", &libcellml::AnalyserEquation::variableCount)
49-
.function("variables", &libcellml::AnalyserEquation::variables)
50-
.function("variable", &libcellml::AnalyserEquation::variable)
48+
.function("computedConstantCount", &libcellml::AnalyserEquation::computedConstantCount)
49+
.function("computedConstants", &libcellml::AnalyserEquation::computedConstants)
50+
.function("computedConstant", &libcellml::AnalyserEquation::computedConstant)
51+
.function("algebraicCount", &libcellml::AnalyserEquation::algebraicCount)
52+
.function("algebraicVariables", select_overload<std::vector<libcellml::AnalyserVariablePtr>() const>(&libcellml::AnalyserEquation::algebraic))
53+
.function("algebraicVariable", select_overload<libcellml::AnalyserVariablePtr(size_t) const>(&libcellml::AnalyserEquation::algebraic))
5154
;
5255

5356
EM_ASM(

src/bindings/javascript/analysermodel.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,15 @@ EMSCRIPTEN_BINDINGS(libcellml_analysermodel)
4545
.function("stateCount", &libcellml::AnalyserModel::stateCount)
4646
.function("states", &libcellml::AnalyserModel::states)
4747
.function("state", &libcellml::AnalyserModel::state)
48-
.function("variableCount", &libcellml::AnalyserModel::variableCount)
49-
.function("variables", &libcellml::AnalyserModel::variables)
50-
.function("variable", &libcellml::AnalyserModel::variable)
48+
.function("constantCount", &libcellml::AnalyserModel::constantCount)
49+
.function("constants", &libcellml::AnalyserModel::constants)
50+
.function("constant", &libcellml::AnalyserModel::constant)
51+
.function("computedConstantCount", &libcellml::AnalyserModel::computedConstantCount)
52+
.function("computedConstants", &libcellml::AnalyserModel::computedConstants)
53+
.function("computedConstant", &libcellml::AnalyserModel::computedConstant)
54+
.function("algebraicCount", &libcellml::AnalyserModel::algebraicCount)
55+
.function("algebraicVariables", select_overload<std::vector<libcellml::AnalyserVariablePtr>() const>(&libcellml::AnalyserModel::algebraic))
56+
.function("algebraicVariable", select_overload<libcellml::AnalyserVariablePtr(size_t) const>(&libcellml::AnalyserModel::algebraic))
5157
.function("equationCount", &libcellml::AnalyserModel::equationCount)
5258
.function("equations", &libcellml::AnalyserModel::equations)
5359
.function("equation", &libcellml::AnalyserModel::equation)

tests/bindings/javascript/analyserequation.test.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe("Analyser Equation tests", () => {
5656
expect(eqn.dependencies().size()).toBe(0)
5757
});
5858
test('Checking Analyser Equation dependency.', () => {
59-
expect(eqn.dependency(0)).toBe(null)
59+
expect(eqn.dependency(0)).toBeNull()
6060
});
6161
test('Checking Analyser Equation nlaSystemIndex.', () => {
6262
expect(eqn.nlaSystemIndex()).toBe(4294967295)
@@ -68,16 +68,25 @@ describe("Analyser Equation tests", () => {
6868
expect(eqn.nlaSiblings().size()).toBe(0)
6969
});
7070
test('Checking Analyser Equation nlaSibling.', () => {
71-
expect(eqn.nlaSibling(0)).toBe(null)
71+
expect(eqn.nlaSibling(0)).toBeNull()
7272
});
73-
test('Checking Analyser Equation variableCount.', () => {
74-
expect(eqn.variableCount()).toBe(1)
73+
test('Checking Analyser Equation computedConstantCount.', () => {
74+
expect(eqn.computedConstantCount()).toBe(0)
7575
});
76-
test('Checking Analyser Equation variables.', () => {
77-
expect(eqn.variables().size()).toBe(1)
76+
test('Checking Analyser Equation computedConstants.', () => {
77+
expect(eqn.computedConstants().size()).toBe(0)
7878
});
79-
test('Checking Analyser Equation variable.', () => {
80-
expect(eqn.variable(0).variable().name()).toBe("x")
79+
test('Checking Analyser Equation computedConstant.', () => {
80+
expect(eqn.computedConstant(0)).toBeNull()
81+
});
82+
test('Checking Analyser Equation algebraicCount.', () => {
83+
expect(eqn.algebraicCount()).toBe(1)
84+
});
85+
test('Checking Analyser Equation algebraicVariables.', () => {
86+
expect(eqn.algebraicVariables().size()).toBe(1)
87+
});
88+
test('Checking Analyser Equation algebraicVariable.', () => {
89+
expect(eqn.algebraicVariable(0).variable().name()).toBe("x")
8190
});
8291
test('Checking Analyser Equation AST.', () => {
8392
expect(eqn.ast().value()).toBe("")

tests/bindings/javascript/analysermodel.test.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,20 @@ describe("Analyser Model tests", () => {
6161
expect(am.states().size()).toBe(4)
6262
expect(am.state(2).variable().name()).toBe("m")
6363
});
64-
test('Checking Analyser Model variables related API.', () => {
65-
expect(am.variableCount()).toBe(18)
66-
expect(am.variables().size()).toBe(18)
67-
expect(am.variable(2).variable().name()).toBe("i_K")
64+
test('Checking Analyser Model constants related API.', () => {
65+
expect(am.constantCount()).toBe(0)
66+
expect(am.constants().size()).toBe(0)
67+
expect(am.constant(2)).toBeNull()
68+
});
69+
test('Checking Analyser Model computed constants related API.', () => {
70+
expect(am.computedConstantCount()).toBe(0)
71+
expect(am.computedConstants().size()).toBe(0)
72+
expect(am.computedConstant(2)).toBeNull()
73+
});
74+
test('Checking Analyser Model algebraic variables related API.', () => {
75+
expect(am.algebraicCount()).toBe(18)
76+
expect(am.algebraicVariables().size()).toBe(18)
77+
expect(am.algebraicVariable(2).variable().name()).toBe("i_K")
6878
});
6979
test('Checking Analyser Model need* API.', () => {
7080
expect(am.needEqFunction()).toBe(false)
@@ -93,6 +103,6 @@ describe("Analyser Model tests", () => {
93103
expect(am.needAcothFunction()).toBe(false)
94104
});
95105
test('Checking Analyser Model are equivalent variables.', () => {
96-
expect(am.areEquivalentVariables(am.variable(2).variable(), am.variable(7).variable())).toBe(false)
106+
expect(am.areEquivalentVariables(am.algebraicVariable(2).variable(), am.algebraicVariable(7).variable())).toBe(false)
97107
});
98108
})

tests/bindings/javascript/analyservariable.test.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,37 @@ describe("Analyser Variable tests", () => {
3737

3838
am = a.model()
3939

40-
expect(am.variableCount()).toBe(18)
40+
expect(am.constantCount()).toBe(0)
41+
expect(am.computedConstantCount()).toBe(0)
42+
expect(am.algebraicCount()).toBe(18)
4143
});
4244
test('Checking Analyser Variable type.', () => {
43-
const av = am.variable(0)
45+
const av = am.algebraicVariable(0)
4446
expect(av.type().value).toBe(libcellml.AnalyserVariable.Type.ALGEBRAIC.value)
4547
expect(libcellml.AnalyserVariable.typeAsString(av.type())).toBe("algebraic")
4648
});
4749
test('Checking Analyser Variable index.', () => {
48-
const av = am.variable(7)
50+
const av = am.algebraicVariable(7)
4951
expect(av.index()).toBe(7)
5052
});
5153
test('Checking Analyser Variable initialising variable.', () => {
52-
const av = am.variable(15)
54+
const av = am.algebraicVariable(15)
5355
expect(av.initialisingVariable().name()).toBe("g_K")
5456
});
5557
test('Checking Analyser Variable variable.', () => {
56-
const av = am.variable(10)
58+
const av = am.algebraicVariable(10)
5759
expect(av.variable().name()).toBe("alpha_m")
5860
});
5961
test('Checking Analyser Equation equationCount.', () => {
60-
const av = am.variable(14)
62+
const av = am.algebraicVariable(14)
6163
expect(av.equationCount()).toBe(1)
6264
});
6365
test('Checking Analyser Variable equations.', () => {
64-
const av = am.variable(14)
66+
const av = am.algebraicVariable(14)
6567
expect(av.equations().size()).toBe(1)
6668
});
6769
test('Checking Analyser Variable equation.', () => {
68-
const av = am.variable(14)
70+
const av = am.algebraicVariable(14)
6971
expect(av.equation(0).type().value).toBe(libcellml.AnalyserEquation.Type.VARIABLE_BASED_CONSTANT.value)
7072
});
7173
})

tests/bindings/javascript/generator.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe("Generator tests", () => {
4343

4444
a.analyseModel(m)
4545

46-
expect(g.model()).toBe(null)
46+
expect(g.model()).toBeNull()
4747

4848
g.setModel(a.model())
4949

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

6464
const interface_lines = g.interfaceCode().split('\n')
65-
expect(interface_lines.length).toBe(40)
65+
expect(interface_lines.length).toBe(42)
6666

6767
const implementation_lines = g.implementationCode().split('\n')
68-
expect(implementation_lines.length).toBe(67)
68+
expect(implementation_lines.length).toBe(69)
6969

7070
const equation_line_1 = libcellml.Generator.equationCode(a.model().equation(0).ast())
7171
expect(equation_line_1.length).toBe(14)

tests/bindings/javascript/generatorprofile.test.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -684,17 +684,41 @@ describe("GeneratorProfile tests", () => {
684684
x.setImplementationStateCountString("something")
685685
expect(x.implementationStateCountString()).toBe("something")
686686
});
687-
test("Checking GeneratorProfile.interfaceVariableCountString.", () => {
687+
test("Checking GeneratorProfile.interfaceConstantCountString.", () => {
688688
const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C)
689689

690-
x.setInterfaceVariableCountString("something")
691-
expect(x.interfaceVariableCountString()).toBe("something")
690+
x.setInterfaceConstantCountString("something")
691+
expect(x.interfaceConstantCountString()).toBe("something")
692692
});
693-
test("Checking GeneratorProfile.implementationVariableCountString.", () => {
693+
test("Checking GeneratorProfile.implementationConstantCountString.", () => {
694694
const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C)
695695

696-
x.setImplementationVariableCountString("something")
697-
expect(x.implementationVariableCountString()).toBe("something")
696+
x.setImplementationConstantCountString("something")
697+
expect(x.implementationConstantCountString()).toBe("something")
698+
});
699+
test("Checking GeneratorProfile.interfaceComputedConstantCountString.", () => {
700+
const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C)
701+
702+
x.setInterfaceComputedConstantCountString("something")
703+
expect(x.interfaceComputedConstantCountString()).toBe("something")
704+
});
705+
test("Checking GeneratorProfile.implementationComputedConstantCountString.", () => {
706+
const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C)
707+
708+
x.setImplementationComputedConstantCountString("something")
709+
expect(x.implementationComputedConstantCountString()).toBe("something")
710+
});
711+
test("Checking GeneratorProfile.interfaceAlgebraicCountString.", () => {
712+
const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C)
713+
714+
x.setInterfaceAlgebraicCountString("something")
715+
expect(x.interfaceAlgebraicCountString()).toBe("something")
716+
});
717+
test("Checking GeneratorProfile.implementationAlgebraicCountString.", () => {
718+
const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C)
719+
720+
x.setImplementationAlgebraicCountString("something")
721+
expect(x.implementationAlgebraicCountString()).toBe("something")
698722
});
699723
test("Checking GeneratorProfile.variableTypeObjectString.", () => {
700724
const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C)

tests/bindings/javascript/importsource.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("Import Source tests", () => {
3434
const iS = new libcellml.ImportSource()
3535
const m = new libcellml.Model()
3636

37-
expect(iS.model()).toBe(null)
37+
expect(iS.model()).toBeNull()
3838

3939
iS.setModel(m)
4040

tests/bindings/javascript/reset.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe("Reset tests", () => {
4141
const r = new libcellml.Reset()
4242
const v = new libcellml.Variable()
4343

44-
expect(r.variable()).toBe(null)
44+
expect(r.variable()).toBeNull()
4545

4646
r.setVariable(v)
4747
expect(r.variable()).toStrictEqual(v)
@@ -50,7 +50,7 @@ describe("Reset tests", () => {
5050
const r = new libcellml.Reset()
5151
const v = new libcellml.Variable()
5252

53-
expect(r.testVariable()).toBe(null)
53+
expect(r.testVariable()).toBeNull()
5454

5555
r.setTestVariable(v)
5656
expect(r.testVariable()).toStrictEqual(v)

tests/bindings/javascript/variable.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe("Variable tests", () => {
7070
const v = new libcellml.Variable("V")
7171
const u = new libcellml.Units("mV")
7272

73-
expect(v.units()).toBe(null)
73+
expect(v.units()).toBeNull()
7474

7575
v.setUnitsByName("A")
7676

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

8383
v.removeUnits()
8484

85-
expect(v.units()).toBe(null)
85+
expect(v.units()).toBeNull()
8686

8787
v.delete()
8888
u.delete()

tests/bindings/python/test_analyser.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ def test_coverage(self):
122122
self.assertIsNotNone(am.computedConstants())
123123
self.assertIsNone(am.computedConstant(3))
124124
self.assertEqual(17, am.algebraicCount())
125-
self.assertIsNotNone(am.algebraic())
126-
self.assertIsNotNone(am.algebraic(3))
125+
self.assertIsNotNone(am.algebraicVariable())
126+
self.assertIsNotNone(am.algebraicVariable(3))
127127

128128
self.assertEqual(16, am.equationCount())
129129
self.assertIsNotNone(am.equations())
@@ -158,7 +158,7 @@ def test_coverage(self):
158158

159159
# Ensure coverage for AnalyserVariable.
160160

161-
av = am.algebraic(3)
161+
av = am.algebraicVariable(3)
162162

163163
self.assertEqual(AnalyserVariable.Type.CONSTANT, av.type())
164164
self.assertEqual("constant", AnalyserVariable.typeAsString(av.type()))
@@ -190,8 +190,8 @@ def test_coverage(self):
190190
self.assertIsNotNone(ae.computedConstants())
191191
self.assertIsNone(ae.computedConstant(0))
192192
self.assertEqual(1, ae.algebraicCount())
193-
self.assertIsNotNone(ae.algebraic())
194-
self.assertIsNotNone(ae.algebraic(0))
193+
self.assertIsNotNone(ae.algebraicVariable())
194+
self.assertIsNotNone(ae.algebraicVariable(0))
195195

196196
# Check Analyser Equation type with invalid values.
197197

0 commit comments

Comments
 (0)