Skip to content

Commit

Permalink
Interpreter tests: make sure that all our arrays are initialised with…
Browse files Browse the repository at this point in the history
… NaNs.
  • Loading branch information
agarny committed Apr 9, 2024
1 parent 412d8d4 commit 1ec290b
Show file tree
Hide file tree
Showing 5 changed files with 1,171 additions and 6 deletions.
23 changes: 20 additions & 3 deletions tests/bindings/javascript/interpreter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ describe("Interpreter tests", () => {
beforeAll(async () => {
libcellml = await loadLibCellML()
})

function expectArray(expectedValues, values) {
expect(expectedValues.length).toBe(values.size())

for (let i = 0; i < expectedValues.length; ++i) {
if (Number.isNaN(expectedValues[i])) {
expect(Number.isNaN(values.get(i))).toBe(true)
} else {
expect(expectedValues[i]).toBe(values.get(i))
}
}
}

test('Checking Interpreter model manipulation.', () => {
const i = new libcellml.Interpreter()
const p = new libcellml.Parser(true)
Expand All @@ -40,13 +53,17 @@ describe("Interpreter tests", () => {

expect(i.voi()).toBe(0.0)

expect(i.states().size()).toBe(4)
expect(i.rates().size()).toBe(4)
expect(i.variables().size()).toBe(18)
expectArray([Number.NaN, Number.NaN, Number.NaN, Number.NaN], i.states())
expectArray([Number.NaN, Number.NaN, Number.NaN, Number.NaN], i.rates())
expectArray([Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN], i.variables())

i.initialiseVariables()
i.computeComputedConstants()
i.computeRates()
i.computeVariables()

expectArray([Number.NaN, Number.NaN, Number.NaN, Number.NaN], i.states())
expectArray([Number.NaN, Number.NaN, Number.NaN, Number.NaN], i.rates())
expectArray([Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN], i.variables())
})
})
20 changes: 17 additions & 3 deletions tests/bindings/python/test_interpreter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Tests the Interpreter class bindings
#
import math
import unittest


Expand All @@ -12,6 +13,15 @@ def test_create_destroy(self):
x = Interpreter()
del x

def assert_array_equal(self, expected_values, values):
self.assertEqual(len(expected_values), len(values))

for i in range(len(expected_values)):
if math.isnan(expected_values[i]):
self.assertTrue(math.isnan(values[i]))
else:
self.assertEqual(expected_values[i], values[i])

def test_hodgkin_huxley_squid_axon_model_1952(self):
from libcellml import Analyser
from libcellml import AnalyserModel
Expand Down Expand Up @@ -39,15 +49,19 @@ def test_hodgkin_huxley_squid_axon_model_1952(self):

self.assertEqual(0.0, i.voi())

self.assertEqual(4, len(i.states()))
self.assertEqual(4, len(i.rates()))
self.assertEqual(18, len(i.variables()))
self.assert_array_equal([math.nan, math.nan, math.nan, math.nan], i.states())
self.assert_array_equal([math.nan, math.nan, math.nan, math.nan], i.rates())
self.assert_array_equal([math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan], i.variables())

i.initialiseVariables()
i.computeComputedConstants()
i.computeRates()
i.computeVariables()

self.assert_array_equal([math.nan, math.nan, math.nan, math.nan], i.states())
self.assert_array_equal([math.nan, math.nan, math.nan, math.nan], i.rates())
self.assert_array_equal([math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan, math.nan], i.variables())


if __name__ == '__main__':
unittest.main()
Loading

0 comments on commit 1ec290b

Please sign in to comment.