Example #1
0
 def test_xml(self):
     """ write the organ type parameter as xml, and rereads it """
     plant = rb.Organism()
     otp = rb.OrganRandomParameter(plant)
     otp.name = "the great organ"
     otp.organType = 1  # seed
     otp.subType = 2
     otp.writeXML("organ.xml")
     otp2 = rb.OrganRandomParameter(plant)
     otp2.readXML("organ.xml")
     self.assertEqual(otp2.name, otp.name, "xml: value unexpected")
     self.assertEqual(otp2.organType, otp.organType, "xml: value unexpected")
     self.assertEqual(otp2.subType, otp.subType, "xml: value unexpected")
Example #2
0
 def test_realize(self):
     """ calls realize """
     otp = rb.OrganRandomParameter(rb.Organism())
     otp.subType = 2
     p = otp.realize();
     self.assertEqual(p.__class__.__name__, "OrganSpecificParameter", "realize: unexpected class type")
     self.assertEqual(p.subType, 2, "realize: unexpected sub type")
Example #3
0
 def test_toString(self):
     """ tests __str__ output """
     otp = rb.OrganRandomParameter(rb.Organism())
     otp.name = "the great organ"
     otp.organType = 1
     otp.subType = 2
     self.assertEqual(otp.__str__(False), "Name: the great organ, organType: 1, subType, 2", "toString: value unexpected")
Example #4
0
 def test_parameter(self):
     """ tests getParameter() """
     otp = rb.OrganRandomParameter(rb.Organism())
     otp.organType = 1
     otp.subType = 2
     ot = otp.getParameter("organType")
     st = otp.getParameter("subType")
     self.assertEqual(ot, 1., "getParameter: value unexpected")
     self.assertEqual(st, 2., "getParameter: value unexpected")
Example #5
0
 def hand_example(self):
     """ an example used in the tests below, a hand with two fingers """
     self.human1 = rb.Organism()  # same example as in test_constructor ...
     otp = rb.OrganRandomParameter(self.human1)
     self.human1.setOrganRandomParameter(otp)
     op = otp.realize()
     self.hand = rb.Organ(self.human1.getOrganIndex(), op, True, True, 0, 15., False, 0)
     self.hand.setOrganism(self.human1)
     self.thumb = rb.Organ(self.human1, self.hand, 0, 0, 4)  # delayedfor 4 days
     self.little_finger = rb.Organ(self.human1, self.hand, 0, 0, 3)  # delayed for 3 days
     self.hand.addChild(self.thumb)
     self.hand.addChild(self.little_finger)
Example #6
0
 def test_constructors(self):
     """ tests constructor and copy """
     plant = rb.Organism()
     otp = rb.OrganRandomParameter(plant)
     self.assertEqual(otp.name, "organ", "copy: default value unexpected")
     self.assertEqual(otp.organType, 0, "copy: default value unexpected")
     self.assertEqual(otp.subType, 0, "copy: default value unexpected")
     otp2 = otp.copy(plant)
     self.assertIsNot(otp, otp2, "copy: organ type parameter set is not copied")
     self.assertEqual(otp2.name, otp.name, "copy: value unexpected")
     self.assertEqual(otp2.organType, otp.organType, "copy: value unexpected")
     self.assertEqual(otp2.subType, otp.subType, "copy: value unexpected")
Example #7
0
 def test_organ_type_parameters(self):
     """ test ability to set, get, read, and write type parameters """
     human1 = rb.Organism()  # same example as in test_constructor ...
     otp1 = rb.OrganRandomParameter(human1)
     otp1.name = "nose"
     otp1.subType = 1
     otp2 = rb.OrganRandomParameter(human1)
     otp2.subType = 2
     otp2.name = "eye"
     human1.setOrganRandomParameter(otp1)  # set
     human1.setOrganRandomParameter(otp2)
     otps = human1.getOrganRandomParameter(rb.OrganTypes.organ)
     self.assertEqual(otps[0].name, "nose", "otp: name not expected ")
     self.assertEqual(otps[1].name, "eye", "otp: name not expected ")
     otp3 = rb.OrganRandomParameter(human1)
     otp3.organType = rb.OrganTypes.root
     otp3.subType = 1
     otp3.name = "rootyhand"
     human1.setOrganRandomParameter(otp3)
     human1.writeParameters("human.xml")
     human2 = rb.Organism()  # read again
     prototype1 = rb.OrganRandomParameter(human2)
     prototype1.organType = rb.OrganTypes.organ
     prototype2 = rb.OrganRandomParameter(human2)
     prototype2.organType = rb.OrganTypes.root
     human2.setOrganRandomParameter(
         prototype1
     )  # set prototypes for reading, subTypes are overwritten if equal
     human2.setOrganRandomParameter(prototype2)
     human2.readParameters("human.xml")
     otp1 = human2.getOrganRandomParameter(rb.OrganTypes.organ, 1)
     otp2 = human2.getOrganRandomParameter(rb.OrganTypes.organ, 2)
     self.assertEqual(otp1.name, "nose", "otp: name not expected ")
     self.assertEqual(otp2.name, "eye", "otp: name not expected ")
     self.assertEqual(otp1.subType, 1, "otp: subType not expected ")
     self.assertEqual(otp2.subType, 2, "otp: subType not expected ")
     rtp = human2.getOrganRandomParameter(rb.OrganTypes.root, 1)
     self.assertEqual(rtp.name, "rootyhand", "otp: name not expected ")
     self.assertEqual(rtp.subType, 1, "otp: subType not expected ")
Example #8
0
 def test_constructors(self):
     """ tests three different kinds of constructors """
     human1 = rb.Organism()
     otp = rb.OrganRandomParameter(human1)
     human1.setOrganRandomParameter(otp)
     op = otp.realize()
     # 1. constructor from scratch
     hand = rb.Organ(human1.getOrganIndex(), op, True, True, 0, 15., False, 0)
     hand.setOrganism(human1)
     # 2. used in simulation (must have parent, since there is no nullptr in Pyhton)
     thumb = rb.Organ(human1, hand, 0, 0, 4)
     little_finger = rb.Organ(human1, hand, 0, 0, 3)
     hand.addChild(thumb)
     hand.addChild(little_finger)
     # 3. deep copy (with a factory function)
     human2 = rb.Organism()
     hand2 = hand.copy(human2)
     self.assertEqual(str(hand), str(hand2), "deep copy: the organs shold be equal")
     self.assertIsNot(hand.getParam(), hand2.getParam(), "deep copy: organs have same parameter set")