def test_increment_from_node(self):
     node = Patch(0, [self.bac_original, self.bac_new, self.mac_original, self.mac_new])
     self.assertEqual(self.event_no_change.increment_state_variable_from_node(node, None), 0)
     node.update_subpopulation(self.bac_original, 13)
     self.assertEqual(self.event_no_change.increment_state_variable_from_node(node, None), 0)
     node.update_subpopulation(self.mac_original, 5)
     self.assertEqual(self.event_no_change.increment_state_variable_from_node(node, None), 13 * 5)
Exemple #2
0
 def test_increment_from_node(self):
     node = Patch(0, [self.compartment])
     self.assertEqual(
         self.event.increment_state_variable_from_node(node, None), 0)
     node.update_subpopulation(self.compartment, 12)
     self.assertEqual(
         self.event.increment_state_variable_from_node(node, None), 12)
 def test_increment_from_node(self):
     node = Patch(0, [self.comp_from, self.comp_to] + self.inf_comps)
     self.assertEqual(
         self.event.increment_state_variable_from_node(node, None), 0)
     node.update_subpopulation(self.comp_from, 10)
     self.assertEqual(
         self.event.increment_state_variable_from_node(node, None), 0)
     node.update_subpopulation(self.inf_comps[0], 3)
     self.assertEqual(
         self.event.increment_state_variable_from_node(node, None),
         10.0 * 3.0 / 13.0)
class PatchTestCase(unittest.TestCase):
    def setUp(self):
        self.node_id = 90
        self.compartments = ['a', 'b', 'c']
        self.position = (6, 7)
        self.patch = Patch(self.node_id, self.compartments, self.position)

    def test_initialise(self):
        self.assertItemsEqual(self.patch.subpopulations.keys(),
                              self.compartments)
        for key in self.patch.subpopulations:
            self.assertEqual(self.patch.subpopulations[key], 0)
        self.assertSequenceEqual(self.patch.position, self.position)
        self.assertEqual(self.patch.node_id, self.node_id)

    def test_update_subpopulation(self):
        self.patch.update_subpopulation(self.compartments[0], 1)
        self.assertEqual(self.patch.subpopulations[self.compartments[0]], 1)

        # Fail wrong key
        with self.assertRaises(AssertionError) as context:
            self.patch.update_subpopulation('FAIL', 1)
        self.assertEqual('Invalid compartment FAIL for update',
                         str(context.exception))

    def test_compartment_per_compartment(self):
        self.patch.update_subpopulation(self.compartments[0], 10)
        self.patch.update_subpopulation(self.compartments[1], 3)
        self.assertEqual(
            self.patch.compartment_per_compartment(self.compartments[0],
                                                   self.compartments[1]), 3)
 def test_increment_from_node(self):
     node = Patch(0, [self.mac_heal, self.mac_inf, self.bac])
     self.assertEqual(self.event.increment_state_variable_from_node(node, None), 0)
     node.update_subpopulation(self.bac, 4)
     self.assertEqual(self.event.increment_state_variable_from_node(node, None), 0)
     node.update_subpopulation(self.mac_inf, 5)
     node.update_subpopulation(self.bac, -4)
     self.assertEqual(self.event.increment_state_variable_from_node(node, None), 0)
     node.update_subpopulation(self.bac, 4)
     self.assertEqual(self.event.increment_state_variable_from_node(node, None), 5)
    def test_update_node(self):
        node = Patch(0, [self.mac_heal, self.mac_inf, self.bac])
        node.update_subpopulation(self.bac, 20)
        node.update_subpopulation(self.mac_inf, 4)
        self.event.update_node(node, None)
        self.assertEqual(node.subpopulations[self.mac_inf], 4)
        self.assertEqual(node.subpopulations[self.bac], 19)
        self.assertEqual(node.subpopulations[self.mac_heal], 0)

        node = Patch(0, [self.mac_heal, self.mac_inf, self.bac])
        node.update_subpopulation(self.bac, 4)
        node.update_subpopulation(self.mac_inf, 4)
        self.event.update_node(node, None)
        self.assertEqual(node.subpopulations[self.mac_inf], 3)
        self.assertEqual(node.subpopulations[self.bac], 3)
        self.assertEqual(node.subpopulations[self.mac_heal], 1)
 def test_increment_from_node(self):
     node = Patch(0, [self.comp_from, self.comp_to] + self.externals)
     self.assertEqual(
         self.event.increment_state_variable_from_node(node, None), 0)
     node.update_subpopulation(self.comp_from, 10)
     self.assertEqual(
         self.event.increment_state_variable_from_node(node, None), 0)
     node.update_subpopulation(self.externals[0], 1)
     self.assertEqual(
         self.event.increment_state_variable_from_node(node, None), 10 * 1)
     node.update_subpopulation(self.externals[1], 2)
     self.assertEqual(
         self.event.increment_state_variable_from_node(node, None),
         10 * (1 + 2))
    def test_update_node(self):
        node = Patch(0, [self.bac_original, self.bac_new, self.mac_original, self.mac_new])
        node.update_subpopulation(self.bac_original, 2)
        node.update_subpopulation(self.mac_original, 2)
        self.event_no_change.update_node(node, None)
        self.assertEqual(node.subpopulations[self.bac_original], 1)
        self.assertEqual(node.subpopulations[self.mac_original], 2)
        self.assertEqual(node.subpopulations[self.bac_new], 0)
        self.assertEqual(node.subpopulations[self.mac_new], 0)

        node = Patch(0, [self.bac_original, self.bac_new, self.mac_original, self.mac_new])
        node.update_subpopulation(self.bac_original, 2)
        node.update_subpopulation(self.mac_original, 2)
        self.event_bac_change.update_node(node, None)
        self.assertEqual(node.subpopulations[self.bac_original], 1)
        self.assertEqual(node.subpopulations[self.mac_original], 2)
        self.assertEqual(node.subpopulations[self.bac_new], 1)
        self.assertEqual(node.subpopulations[self.mac_new], 0)

        node = Patch(0, [self.bac_original, self.bac_new, self.mac_original, self.mac_new])
        node.update_subpopulation(self.bac_original, 2)
        node.update_subpopulation(self.mac_original, 2)
        self.event_mac_change.update_node(node, None)
        self.assertEqual(node.subpopulations[self.bac_original], 1)
        self.assertEqual(node.subpopulations[self.mac_original], 1)
        self.assertEqual(node.subpopulations[self.bac_new], 0)
        self.assertEqual(node.subpopulations[self.mac_new], 1)

        node = Patch(0, [self.bac_original, self.bac_new, self.mac_original, self.mac_new])
        node.update_subpopulation(self.bac_original, 2)
        node.update_subpopulation(self.mac_original, 2)
        self.event_both_change.update_node(node, None)
        self.assertEqual(node.subpopulations[self.bac_original], 1)
        self.assertEqual(node.subpopulations[self.mac_original], 1)
        self.assertEqual(node.subpopulations[self.bac_new], 1)
        self.assertEqual(node.subpopulations[self.mac_new], 1)
    def test_update_node(self):
        node = Patch(0, [self.comp_from, self.comp_to, self.new_external] +
                     self.externals)
        node.update_subpopulation(self.comp_from, 10)
        node.update_subpopulation(self.externals[0], 5)
        node.update_subpopulation(self.externals[1], 3)
        self.event.update_node(node, None)
        self.assertEqual(node.subpopulations[self.comp_from], 9)
        self.assertEqual(node.subpopulations[self.comp_to], 1)
        self.assertEqual(node.subpopulations[self.externals[0]], 5)
        self.assertEqual(node.subpopulations[self.externals[1]], 3)
        self.assertEqual(node.subpopulations[self.new_external], 0)

        node = Patch(0, [self.comp_from, self.comp_to, self.new_external] +
                     self.externals)
        node.update_subpopulation(self.comp_from, 10)
        node.update_subpopulation(self.externals[0], 5)
        node.update_subpopulation(self.externals[1], 3)
        self.event_change_internals.update_node(node, None)
        self.assertEqual(node.subpopulations[self.comp_from], 9)
        self.assertEqual(node.subpopulations[self.comp_to], 1)
        self.assertEqual(node.subpopulations[self.externals[0]], 4)
        self.assertEqual(node.subpopulations[self.externals[1]], 3)
        self.assertEqual(node.subpopulations[self.new_external], 1)
    def test_update_node(self):
        node = Patch(0, [self.comp_from, self.comp_to])
        node.update_subpopulation(self.comp_from, 6)
        self.event.update_node(node, None)
        self.assertEqual(node.subpopulations[self.comp_from], 5)
        self.assertEqual(node.subpopulations[self.comp_to], 1)

        node = Patch(0, [
            self.comp_from, self.comp_to, self.internal_comps[0],
            self.internal_comps[1]
        ])
        node.update_subpopulation(self.comp_from, 6)
        node.update_subpopulation(self.internal_comps[0], 12)
        node.update_subpopulation(self.internal_comps[1], 33)
        self.event_with_internals.update_node(node, None)
        self.assertEqual(node.subpopulations[self.comp_from], 5)
        self.assertEqual(node.subpopulations[self.comp_to], 1)
        self.assertEqual(node.subpopulations[self.internal_comps[0]], 10)
        self.assertEqual(node.subpopulations[self.internal_comps[1]], 28)
    def test_update_node(self):
        node = Patch(0, [
            self.compartment, self.internal_comp_destroy,
            self.internal_comp_from, self.internal_comp_to
        ])
        node.update_subpopulation(self.compartment, 5)
        node.update_subpopulation(self.internal_comp_destroy, 10)
        node.update_subpopulation(self.internal_comp_from, 18)
        node.update_subpopulation(self.internal_comp_to, 0)
        self.event.update_node(node, None)
        self.assertEqual(node.subpopulations[self.compartment], 4)
        self.assertEqual(node.subpopulations[self.internal_comp_destroy], 10)
        self.assertEqual(node.subpopulations[self.internal_comp_from], 18)
        self.assertEqual(node.subpopulations[self.internal_comp_to], 0)

        node = Patch(0, [
            self.compartment, self.internal_comp_destroy,
            self.internal_comp_from, self.internal_comp_to
        ])
        node.update_subpopulation(self.compartment, 5)
        node.update_subpopulation(self.internal_comp_destroy, 10)
        node.update_subpopulation(self.internal_comp_from, 18)
        node.update_subpopulation(self.internal_comp_to, 0)
        self.event_with_internals_destroyed.update_node(node, None)
        self.assertEqual(node.subpopulations[self.compartment], 4)
        self.assertEqual(node.subpopulations[self.internal_comp_destroy], 8)
        self.assertEqual(node.subpopulations[self.internal_comp_from], 18)
        self.assertEqual(node.subpopulations[self.internal_comp_to], 0)

        node = Patch(0, [
            self.compartment, self.internal_comp_destroy,
            self.internal_comp_from, self.internal_comp_to
        ])
        node.update_subpopulation(self.compartment, 5)
        node.update_subpopulation(self.internal_comp_destroy, 10)
        node.update_subpopulation(self.internal_comp_from, 18)
        node.update_subpopulation(self.internal_comp_to, 0)
        self.event_with_internals_changed.update_node(node, None)
        self.assertEqual(node.subpopulations[self.compartment], 4)
        self.assertEqual(node.subpopulations[self.internal_comp_destroy], 10)
        self.assertEqual(node.subpopulations[self.internal_comp_from], 15)
        self.assertEqual(node.subpopulations[self.internal_comp_to], 3)