def test_copy(self): model = MC(['a', 'b'], [2, 2], [State('a', 0), State('b', 1)]) model.add_transition_model('a', {0: {0: 0.1, 1: 0.9}, 1: {0: 0.2, 1: 0.8}}) model.add_transition_model('b', {0: {0: 0.3, 1: 0.7}, 1: {0: 0.4, 1: 0.6}}) copy = model.copy() self.assertIsInstance(copy, MC) self.assertEqual(sorted(model.variables), sorted(copy.variables)) self.assertEqual(model.cardinalities, copy.cardinalities) self.assertEqual(model.transition_models, copy.transition_models) self.assertEqual(model.state, copy.state) model.add_variable('p', 1) model.set_start_state([State('a', 0), State('b', 1), State('p', 0)]) model.add_transition_model('p', {0: {0: 1}}) self.assertNotEqual(sorted(model.variables), sorted(copy.variables)) self.assertEqual(sorted(['a', 'b']), sorted(copy.variables)) self.assertNotEqual(model.cardinalities, copy.cardinalities) self.assertEqual({'a': 2, 'b': 2}, copy.cardinalities) self.assertNotEqual(model.state, copy.state) self.assertEqual([State('a', 0), State('b', 1)], copy.state) self.assertNotEqual(model.transition_models, copy.transition_models) self.assertEqual(len(copy.transition_models), 2) self.assertEqual(copy.transition_models['a'], {0: {0: 0.1, 1: 0.9}, 1: {0: 0.2, 1: 0.8}}) self.assertEqual(copy.transition_models['b'], {0: {0: 0.3, 1: 0.7}, 1: {0: 0.4, 1: 0.6}})
def test_add_variable_existing(self, warn): model = MC(['p'], [2]) model.add_variable('p', 3) self.assertEqual(warn.call_count, 1)
def test_copy(self): model = MC(['a', 'b'], [2, 2], [State('a', 0), State('b', 1)]) model.add_transition_model('a', { 0: { 0: 0.1, 1: 0.9 }, 1: { 0: 0.2, 1: 0.8 } }) model.add_transition_model('b', { 0: { 0: 0.3, 1: 0.7 }, 1: { 0: 0.4, 1: 0.6 } }) copy = model.copy() self.assertIsInstance(copy, MC) self.assertEqual(sorted(model.variables), sorted(copy.variables)) self.assertEqual(model.cardinalities, copy.cardinalities) self.assertEqual(model.transition_models, copy.transition_models) self.assertEqual(model.state, copy.state) model.add_variable('p', 1) model.set_start_state([State('a', 0), State('b', 1), State('p', 0)]) model.add_transition_model('p', {0: {0: 1}}) self.assertNotEqual(sorted(model.variables), sorted(copy.variables)) self.assertEqual(sorted(['a', 'b']), sorted(copy.variables)) self.assertNotEqual(model.cardinalities, copy.cardinalities) self.assertEqual({'a': 2, 'b': 2}, copy.cardinalities) self.assertNotEqual(model.state, copy.state) self.assertEqual([State('a', 0), State('b', 1)], copy.state) self.assertNotEqual(model.transition_models, copy.transition_models) self.assertEqual(len(copy.transition_models), 2) self.assertEqual(copy.transition_models['a'], { 0: { 0: 0.1, 1: 0.9 }, 1: { 0: 0.2, 1: 0.8 } }) self.assertEqual(copy.transition_models['b'], { 0: { 0: 0.3, 1: 0.7 }, 1: { 0: 0.4, 1: 0.6 } })
def test_add_variable_new(self): model = MC(['a'], [2]) model.add_variable('p', 3) self.assertIn('p', model.variables) self.assertEqual(model.cardinalities['p'], 3) self.assertDictEqual(model.transition_models['p'], {})