Beispiel #1
0
    def test_has_variable(self):
        from libcellml import Component, Variable

        # bool hasVariable(const VariablePtr &variable)
        c = Component()
        v = Variable("second")
        self.assertFalse(c.hasVariable(v))
        c.addVariable(v)
        self.assertTrue(c.hasVariable(v))
        self.assertFalse(c.hasVariable(Variable()))
        del [c, v]

        # bool hasVariable(const std::string &name)
        c = Component()
        self.assertFalse(c.hasVariable(''))
        v1 = Variable()
        c.addVariable(v1)
        self.assertFalse(c.hasVariable('blue'))
        self.assertTrue(c.hasVariable(''))
        name = 'yellow'
        v2 = Variable()
        v2.setName(name)
        v1.setName('orange')
        c.addVariable(v2)
        self.assertTrue(c.hasVariable(name))

        vTaken = c.takeVariable(0)
        self.assertEqual('orange', vTaken.name())
        self.assertTrue(c.variableCount() == 1)
        del [c, v1, v2, vTaken, name]
Beispiel #2
0
    def test_create_destroy(self):
        from libcellml import Variable

        x = Variable()
        del (x)
        y = Variable()
        z = Variable(y)
        del (y, z)
Beispiel #3
0
    def test_add_equivalence(self):
        from libcellml import Variable

        # static void addEquivalence(const VariablePtr &variable1,
        #   const VariablePtr &variable2)
        v1 = Variable()
        v2 = Variable()
        Variable.addEquivalence(v1, v2)
Beispiel #4
0
    def test_variable_pair_coverage(self):
        from libcellml import Variable, VariablePair

        v1 = Variable("ray")
        v2 = Variable("charles")
        vp = VariablePair(v1, v2)

        self.assertTrue(vp.isValid())
Beispiel #5
0
    def test_create_destroy(self):
        from libcellml import Variable

        x = Variable()
        del x

        y = Variable("nice")
        self.assertEqual("nice", y.name())
        del y
Beispiel #6
0
    def test_clone(self):
        from libcellml import Units, Variable

        v = Variable("sodium")
        u = Units("kg_per_ml")

        v.setUnits(u)

        vCloned = v.clone()
        self.assertEqual("sodium", vCloned.name())
        self.assertEqual("kg_per_ml", vCloned.units().name())
Beispiel #7
0
    def test_variable(self):
        from libcellml import Issue, Variable

        e = Issue()
        self.assertIsNone(e.variable())
        name = 'var'
        v = Variable()
        v.setName(name)
        e.setVariable(v)
        self.assertIsInstance(e.variable(), Variable)
        self.assertEqual(e.variable().name(), name)
Beispiel #8
0
    def test_get_variable(self):
        from libcellml import Error, Variable

        # VariablePtr getVariable()
        e = Error()
        self.assertIsNone(e.getVariable())
        name = 'var'
        v = Variable()
        v.setName(name)
        e.setVariable(v)
        self.assertIsInstance(e.getVariable(), Variable)
        self.assertEqual(e.getVariable().getName(), name)
Beispiel #9
0
    def test_connection(self):
        from libcellml import Issue, Variable, VariablePair

        e = Issue()
        self.assertIsNone(e.connection())
        v1 = Variable("v1")
        v2 = Variable("v2")
        e.setConnection(VariablePair(v1, v2))
        p = e.connection()
        self.assertIsInstance(p.variable1(), Variable)
        self.assertEqual(p.variable1().name(), "v1")
        self.assertEqual(p.variable2().name(), "v2")
Beispiel #10
0
    def test_map_variables(self):
        from libcellml import Issue, Variable, VariablePair

        e = Issue()
        self.assertIsNone(e.mapVariables())
        v1 = Variable("v1")
        v2 = Variable("v2")

        e.setMapVariables(VariablePair(v1, v2))
        p = e.mapVariables()
        self.assertIsInstance(p.variable1(), Variable)
        self.assertEqual(p.variable1().name(), "v1")
        self.assertEqual(p.variable2().name(), "v2")
Beispiel #11
0
    def test_set_get_test_variable(self):
        from libcellml import Reset
        from libcellml import Variable

        r = Reset()
        v = Variable()
        v.setName("glucose")

        self.assertEqual(None, r.testVariable())

        r.setTestVariable(v)

        self.assertEqual("glucose", r.testVariable().name())
Beispiel #12
0
    def test_auto_ids(self):
        from libcellml import Annotator, Parser, Variable

        annotator = Annotator()
        parser = Parser()
        model_string = file_contents("annotator/unique_ids.cellml")

        model = parser.parseModel(model_string)
        annotator.setModel(model)

        annotator.clearAllIds()
        annotator.assignAllIds()

        self.assertEqual("b4da55", model.id())
        self.assertEqual("b4da56", model.importSource(0).id())
        self.assertEqual("b4da57", model.importSource(1).id())
        self.assertEqual("b4da58", model.units(0).id())
        self.assertEqual("b4da59", model.units(1).id())
        self.assertEqual("b4da5a", model.units(2).id())
        self.assertEqual("b4da5b", model.units(3).id())
        self.assertEqual("b4da5c", model.units(1).unitId(0))
        self.assertEqual("b4da5d", model.component(0).id())
        self.assertEqual("b4da5e", model.component(1).id())
        self.assertEqual("b4da5f", model.component(1).component(0).id())
        self.assertEqual("b4da60", model.component(1).variable(0).id())
        self.assertEqual("b4da61", model.component(1).variable(1).id())
        self.assertEqual("b4da62",
                         model.component(1).component(0).variable(0).id())
        self.assertEqual("b4da63",
                         model.component(1).component(0).variable(1).id())

        self.assertEqual("b4da64", model.component(1).reset(0).id())
        self.assertEqual("b4da65", model.component(1).reset(0).resetValueId())
        self.assertEqual("b4da66", model.component(1).reset(0).testValueId())

        c2v1 = model.component("component2").variable("variable1")
        c2v2 = model.component("component2").variable("variable2")
        c3v1 = model.component("component3").variable("variable1")
        c3v2 = model.component("component3").variable("variable2")

        self.assertEqual("b4da67",
                         Variable.equivalenceConnectionId(c2v1, c3v1))
        self.assertEqual("b4da67",
                         Variable.equivalenceConnectionId(c2v2, c3v2))
        self.assertEqual("b4da68", Variable.equivalenceMappingId(c2v1, c3v1))
        self.assertEqual("b4da69", Variable.equivalenceMappingId(c2v2, c3v2))
        self.assertEqual("b4da6a",
                         model.component("component2").encapsulationId())
        self.assertEqual("b4da6b",
                         model.component("component3").encapsulationId())
        self.assertEqual("b4da6c", model.encapsulationId())
Beispiel #13
0
    def test_remove_all_variables(self):
        from libcellml import Component, Variable

        # void removeAllVariables()
        c = Component()
        v1 = Variable()
        v2 = Variable()
        c.addVariable(v1)
        c.addVariable(v2)
        self.assertTrue(c.hasVariable(v1))
        self.assertTrue(c.hasVariable(v2))
        c.removeAllVariables()
        self.assertFalse(c.hasVariable(v1))
        self.assertFalse(c.hasVariable(v2))
Beispiel #14
0
    def test_variable(self):
        from libcellml import Component, Variable

        # VariablePtr variable(size_t index)
        c = Component()
        v = Variable()
        name = 'green'
        v.setName(name)
        self.assertIsNone(c.variable(0))
        self.assertIsNone(c.variable(1))
        self.assertIsNone(c.variable(-1))
        c.addVariable(v)
        self.assertIsNone(c.variable(1))
        self.assertIsNone(c.variable(-1))
        self.assertIsNotNone(c.variable(0))
        self.assertEqual(c.variable(0).name(), name)
        del [c, v, name]

        # VariablePtr variable(const std::string &name)
        c = Component()
        v = Variable()
        name = 'green'
        v.setName(name)
        self.assertIsNone(c.variable(name))
        c.addVariable(v)
        self.assertIsNone(c.variable('red'))
        self.assertIsNotNone(c.variable(name))
        self.assertEqual(c.variable(name).name(), name)
Beispiel #15
0
    def test_variable_count(self):
        from libcellml import Component, Variable

        # size_t variableCount()
        c = Component()
        self.assertEqual(c.variableCount(), 0)
        c.addVariable(Variable())
        self.assertEqual(c.variableCount(), 1)
        c.addVariable(Variable())
        self.assertEqual(c.variableCount(), 2)
        c.removeVariable('')
        self.assertEqual(c.variableCount(), 1)
        c.removeVariable('')
        self.assertEqual(c.variableCount(), 0)
Beispiel #16
0
    def test_units(self):
        from libcellml import Variable

        # std::string units()
        name = 'testo'
        v = Variable()
        self.assertEqual(v.units(), None)
        v.setUnits(name)
        self.assertEqual(v.units().name(), name)
        v.setUnits('')
        self.assertEqual(v.units().name(), '')
Beispiel #17
0
    def test_get_units(self):
        from libcellml import Variable

        # std::string getUnits()
        name = 'testo'
        v = Variable()
        self.assertEqual(v.getUnits(), '')
        v.setUnits(name)
        self.assertEqual(v.getUnits(), name)
        v.setUnits('')
        self.assertEqual(v.getUnits(), '')
        del (v, name)
Beispiel #18
0
    def test_clean(self):

        from libcellml import Component, Model, Units, Variable, Printer

        model = Model()
        c1 = Component('c1')
        c2 = Component()
        c2.setId('c2')
        c3 = Component()
        c4 = Component()
        u1 = Units('used')
        u2 = Units()
        u2.setId('u2')
        u3 = Units()
        v = Variable('x')

        model.addComponent(c1)
        model.addComponent(c2)
        model.addComponent(c3)
        model.addComponent(c4)
        model.addUnits(u1)
        model.addUnits(u2)
        model.addUnits(u3)

        c3.addVariable(v)

        self.assertEqual(4, model.componentCount())
        self.assertEqual(3, model.unitsCount())

        # Call the Model.clean() function to remove the empty items (c4 and u3).
        model.clean()

        self.assertEqual(3, model.componentCount())
        self.assertEqual(2, model.unitsCount())
Beispiel #19
0
    def test_create_destroy(self):
        from libcellml import Component
        from libcellml import Issue
        from libcellml import ImportSource
        from libcellml import Model
        from libcellml import Reset
        from libcellml import Units
        from libcellml import Variable

        e1 = Issue()
        del (e1)

        c = Component()
        e2 = Issue(c)
        del (e2)

        i = ImportSource()
        e3 = Issue(i)
        del (e3)

        m = Model()
        e4 = Issue(m)
        del (e4)

        r = Reset()
        e5 = Issue(r)
        del (e5)

        u = Units()
        e6 = Issue(u)
        del (e6)

        v = Variable()
        e7 = Issue(v)
        del (e7)
Beispiel #20
0
    def test_create_destroy(self):
        from libcellml import Component
        from libcellml import Issue
        from libcellml import ImportSource
        from libcellml import Model
        from libcellml import Reset
        from libcellml import Unit
        from libcellml import Units
        from libcellml import Variable
        from libcellml import VariablePair

        e1 = Issue()
        del e1

        c = Component()
        e2 = Issue(c)
        del e2

        i = ImportSource()
        e3 = Issue(i)
        del e3

        m = Model()
        e4 = Issue(m)
        del e4

        r = Reset()
        e5 = Issue(r)
        del e5

        u = Units()
        e6 = Issue(u)
        del e6

        v = Variable()
        e7 = Issue(v)
        del e7

        v1 = Variable("v1")
        v2 = Variable("v2")
        vp = VariablePair(v1, v2)
        e8 = Issue(vp)
        del e8

        ui = Unit(u, 0)
        e9 = Issue(ui)
        del e9
Beispiel #21
0
    def test_item_bad_input(self):
        from libcellml import Issue, Variable, CellmlElementType

        i = Issue()
        self.assertRaises(TypeError, i.setItem, CellmlElementType.COMPONENT_REF, Variable("v1"))
        cItem = i.item()
        self.assertEqual(CellmlElementType.UNDEFINED, cItem[0])
        self.assertIsNone(cItem[1])
Beispiel #22
0
    def test_has_variable(self):
        from libcellml import Component, Variable

        # bool hasVariable(const VariablePtr &variable)
        c = Component()
        v = Variable()
        self.assertFalse(c.hasVariable(v))
        c.addVariable(v)
        self.assertTrue(c.hasVariable(v))
        self.assertFalse(c.hasVariable(Variable()))
        del(c, v)

        # bool hasVariable(const std::string &name)
        c = Component()
        self.assertFalse(c.hasVariable(''))
        v1 = Variable()
        c.addVariable(v1)
        self.assertFalse(c.hasVariable('blue'))
        self.assertTrue(c.hasVariable(''))
        name = 'yellow'
        v2 = Variable()
        v2.setName(name)
        c.addVariable(v2)
        self.assertTrue(c.hasVariable(name))
        del(c, v1, v2, name)
Beispiel #23
0
    def test_link_units(self):
        from libcellml import Component, Model, Units, Variable

        m = Model()
        c = Component()
        v = Variable()
        u = Units("orange")

        self.assertFalse(m.hasUnlinkedUnits())

        m.addUnits(u)
        v.setUnits("orange")
        c.addVariable(v)
        m.addComponent(c)

        self.assertTrue(m.hasUnlinkedUnits())

        m.linkUnits()

        self.assertFalse(m.hasUnlinkedUnits())
Beispiel #24
0
    def test_inheritance(self):
        import libcellml
        from libcellml import Variable

        x = Variable()
        self.assertIsInstance(x, libcellml.namedentity.NamedEntity)
        self.assertIsInstance(x, libcellml.entity.Entity)

        # Test access to inherited methods
        x = Variable()
        idx = 'test'
        self.assertEqual(x.id(), '')
        x.setId(idx)
        self.assertEqual(x.id(), idx)
Beispiel #25
0
    def test_clone(self):
        from libcellml import Component, Model, Units, Variable

        m = Model()
        c1 = Component("c1")
        c2 = Component("c2")
        v = Variable("v1")
        u = Units("apple")

        m.addComponent(c1)
        m.addComponent(c2)
        c1.addVariable(v)
        v.setUnits(u)
        m.addUnits(u)

        mCloned = m.clone()

        self.assertEqual(2, mCloned.componentCount())
        self.assertEqual(1, mCloned.unitsCount())
        self.assertEqual(1, mCloned.component(0).variableCount())
        self.assertEqual("apple",
                         mCloned.component(0).variable(0).units().name())
Beispiel #26
0
    def test_clear(self):
        from libcellml import Issue, Variable, CellmlElementType

        i = Issue()
        i.clear()
        self.assertEqual(CellmlElementType.UNDEFINED, i.cellmlElementType())

        v1 = Variable("v1")
        i.setVariable(v1)

        self.assertEqual(CellmlElementType.VARIABLE, i.cellmlElementType())

        i.clear()
        self.assertEqual(CellmlElementType.UNDEFINED, i.cellmlElementType())
Beispiel #27
0
    def test_initial_value(self):
        from libcellml import Variable

        # std::string initialValue()
        value = '5 + x'
        v = Variable()
        self.assertEqual(v.initialValue(), '')
        v.setInitialValue(value)
        self.assertEqual(v.initialValue(), value)
Beispiel #28
0
    def test_variable_interfaces(self):
        from libcellml import Component, Model, Variable

        m = Model()
        c1 = Component("c1")
        c2 = Component("c2")
        v1 = Variable("v1")
        v2 = Variable("v2")

        c1.addVariable(v1)
        c2.addVariable(v2)

        m.addComponent(c1)
        m.addComponent(c2)

        Variable.addEquivalence(v1, v2)

        m.fixVariableInterfaces()

        self.assertEqual("public", v1.interfaceType())
        self.assertEqual("public", v2.interfaceType())
Beispiel #29
0
    def test_remove_variable(self):
        from libcellml import Component, Variable

        # bool removeVariable(size_t index)
        c = Component()
        self.assertFalse(c.removeVariable(0))
        self.assertFalse(c.removeVariable(-1))
        self.assertFalse(c.removeVariable(1))
        c.addVariable(Variable())
        self.assertFalse(c.removeVariable(-1))
        self.assertFalse(c.removeVariable(1))
        self.assertTrue(c.removeVariable(0))
        self.assertFalse(c.removeVariable(0))
        del c

        # bool removeVariable(const std::string &name)
        c = Component()
        self.assertFalse(c.removeVariable(''))
        v1 = Variable()
        c.addVariable(v1)
        self.assertTrue(c.removeVariable(''))
        self.assertFalse(c.removeVariable(''))
        name = 'blue'
        v1.setName(name)
        self.assertFalse(c.removeVariable(name))
        c.addVariable(v1)
        self.assertTrue(c.removeVariable(name))
        self.assertFalse(c.removeVariable(name))
        del [c, v1, name]

        # bool removeVariable(const VariablePtr &variable)
        c = Component()
        v1 = Variable("second")
        v2 = Variable("meter")
        self.assertFalse(c.removeVariable(v1))
        c.addVariable(v1)
        self.assertFalse(c.removeVariable(v2))
        self.assertTrue(c.removeVariable(v1))
        self.assertFalse(c.removeVariable(v1))
Beispiel #30
0
    def test_remove_equivalence(self):
        from libcellml import Variable

        # static bool removeEquivalence(const VariablePtr &variable1,
        #   const VariablePtr &variable2)
        v1 = Variable()
        v2 = Variable()
        v3 = Variable()
        self.assertFalse(Variable.removeEquivalence(v1, v2))
        Variable.addEquivalence(v1, v2)
        self.assertFalse(Variable.removeEquivalence(v1, v3))
        self.assertFalse(Variable.removeEquivalence(v3, v2))
        self.assertTrue(Variable.removeEquivalence(v1, v2))
        self.assertFalse(Variable.removeEquivalence(v1, v2))
        Variable.addEquivalence(v1, v2)
        self.assertTrue(Variable.removeEquivalence(v2, v1))