def test_is_irreducible_satisfies_non_logic(self): """ IsIrreducible.satisfies is not implemented for non-LogicNetworks """ constraint = IsIrreducible() with self.assertRaises(NotImplementedError): constraint.satisfies(s_pombe)
def test_is_irreducible_satisfies(self): """ IsIrreducible.satisfies correctly identifies networks that are irreducible. """ constraint = IsIrreducible() self.assertTrue(constraint.satisfies(myeloid)) reducible = LogicNetwork([((0,), {'0', '1'})]) self.assertFalse(constraint.satisfies(reducible)) reducible = LogicNetwork([((0, 1), {'01', '11'}), ((0, 1), {'00', '01', '11'})]) self.assertFalse(constraint.satisfies(reducible)) reducible = LogicNetwork([((1,), {'0'}), ((0, 1), {'01', '11'})]) self.assertFalse(constraint.satisfies(reducible)) irreducible = LogicNetwork([((0,), {'0'})]) self.assertTrue(constraint.satisfies(irreducible)) irreducible = LogicNetwork([((0, 1), {'01'}), ((0, 1), {'00', '01', '11'})]) self.assertTrue(constraint.satisfies(irreducible)) irreducible = LogicNetwork([((1,), {'0'}), ((0, 1), {'01', '11', '10'})]) self.assertTrue(constraint.satisfies(irreducible))
def test_fixed_topology_set_constraints(self): """ Ensure that the randomizer correctly instantiates the constraints """ c1 = IsConnected() rand = FixedTopology(s_pombe) rand.constraints = [c1] self.assertEqual(rand.constraints, [c1]) c2 = lambda _: True # noqa rand.constraints = [c2] self.assertEqual(len(rand.constraints), 1) self.assertIsInstance(rand.constraints[0], GenericTopological) self.assertEqual(rand.constraints[0].test, c2) rand.constraints = {c1} self.assertEqual(rand.constraints, [c1]) rand.constraints = (c1, ) self.assertEqual(rand.constraints, [c1]) with self.assertRaises(ConstraintError): rand.constraints = [lambda _: False] with self.assertRaises(TypeError): rand.constraints = [IsIrreducible()]
def test_fixed_topology_constraints(self): """ Ensure that the randomizer correctly instantiates the constraints """ c1 = IsConnected() rand = FixedTopology(s_pombe, constraints=[c1]) self.assertEqual(rand.network, s_pombe) self.assertTrue(nx.is_isomorphic(rand.graph, s_pombe.network_graph())) self.assertEqual(rand.timeout, 1000) self.assertEqual(rand.constraints, [c1]) c2 = lambda _: True # noqa rand = FixedTopology(s_pombe, constraints=[c2]) self.assertEqual(rand.network, s_pombe) self.assertTrue(nx.is_isomorphic(rand.graph, s_pombe.network_graph())) self.assertEqual(rand.timeout, 1000) self.assertEqual(len(rand.constraints), 1) self.assertIsInstance(rand.constraints[0], GenericTopological) self.assertEqual(rand.constraints[0].test, c2) with self.assertRaises(ConstraintError): FixedTopology(s_pombe, constraints=[lambda _: False]) with self.assertRaises(TypeError): FixedTopology(s_pombe, constraints=[IsIrreducible()])
def test_network_randomizer_add_constraints(self): """ Ensure that the randomizer correctly adds the constraints """ c1, c2, c3 = IsIrreducible(), (lambda _: False), IsConnected() rand = MockNetworkRandomizer(s_pombe) rand.add_constraint(c1) self.assertEqual(rand.constraints, [c1]) self.assertEqual(rand.trand.constraints, []) rand.add_constraint(c2) self.assertEqual(len(rand.constraints), 2) self.assertEqual(rand.constraints[0], c1) self.assertIsInstance(rand.constraints[1], GenericDynamical) self.assertEqual(rand.constraints[1].test, c2) self.assertEqual(rand.trand.constraints, []) rand.add_constraint(c3) self.assertEqual(len(rand.constraints), 2) self.assertEqual(rand.constraints[0], c1) self.assertIsInstance(rand.constraints[1], GenericDynamical) self.assertEqual(rand.constraints[1].test, c2) self.assertEqual(rand.trand.constraints, [c3]) with self.assertRaises(TypeError): rand.add_constraint(5)
def test_generic_dynamical_raises(self): """ GenericDynamical raises a TypeError if it's instantiated with anything that is not callable. """ with self.assertRaises(TypeError): GenericDynamical(5) with self.assertRaises(TypeError): GenericDynamical(IsIrreducible())
def test_randomizer_add_constraints(self): """ Ensure that we can add constraints after initialization """ c1, c2 = IsIrreducible(), IsConnected() rand = MockRandomizer(s_pombe, constraints=[c1]) rand.add_constraint(c2) self.assertEqual(rand.constraints, [c1, c2]) with self.assertRaises(TypeError): rand.add_constraint(lambda _: True)
def test_randomizer_init_constraints(self): """ Ensure that the randomizer correctly instantiates the constraints """ constraint = IsIrreducible() rand = MockRandomizer(s_pombe, constraints=[constraint]) self.assertEqual(rand.network, s_pombe) self.assertTrue(nx.is_isomorphic(rand.graph, s_pombe.network_graph())) self.assertEqual(rand.timeout, 1000) self.assertEqual(rand.constraints, [constraint]) with self.assertRaises(TypeError): MockRandomizer(s_pombe, constraints=[lambda n: False])
def test_is_irreducible_raises(self): """ IsIrreducible.satisfies raises an error if the argument is not a Neet network. """ constraint = IsIrreducible() with self.assertRaises(TypeError): constraint.satisfies(nx.DiGraph()) with self.assertRaises(TypeError): constraint.satisfies(nx.Graph())
def test_randomizer_set_constraints(self): """ Ensure that we can set the constraints after initialization """ constraint = IsIrreducible() rand = MockRandomizer(s_pombe, constraints=[IsConnected()]) rand.constraints = [constraint] self.assertEqual(rand.constraints, [constraint]) rand.constraints = {constraint} self.assertEqual(rand.constraints, [constraint]) rand.constraints = (constraint, ) self.assertEqual(rand.constraints, [constraint]) with self.assertRaises(TypeError): rand.constraints = [lambda _: True]
def test_topology_randomizer_add_constraints(self): """ Ensure that we can add constraints after initialization """ c1, c2 = IsConnected(), (lambda _: False) rand = MockTopologyRandomizer(s_pombe) rand.add_constraint(c1) self.assertEqual(len(rand.constraints), 1) self.assertEqual(rand.constraints, [c1]) rand.add_constraint(c2) self.assertEqual(len(rand.constraints), 2) self.assertEqual(rand.constraints[0], c1) self.assertIsInstance(rand.constraints[1], GenericTopological) self.assertEqual(rand.constraints[1].test, c2) with self.assertRaises(TypeError): rand.add_constraint(IsIrreducible())
def test_network_randomizer_constraints(self): """ Ensure that the randomizer correctly instantiates the constraints """ c1, c2, c3 = IsIrreducible(), (lambda _: False), IsConnected() rand = MockNetworkRandomizer(s_pombe, constraints=[c1]) self.assertEqual(rand.network, s_pombe) self.assertTrue(nx.is_isomorphic(rand.graph, s_pombe.network_graph())) self.assertEqual(rand.timeout, 1000) self.assertEqual(rand.constraints, [c1]) self.assertEqual(rand.trand.constraints, []) rand = MockNetworkRandomizer(s_pombe, constraints=[c2]) self.assertEqual(rand.network, s_pombe) self.assertTrue(nx.is_isomorphic(rand.graph, s_pombe.network_graph())) self.assertEqual(rand.timeout, 1000) self.assertEqual(len(rand.constraints), 1) self.assertIsInstance(rand.constraints[0], GenericDynamical) self.assertEqual(rand.constraints[0].test, c2) self.assertEqual(rand.trand.constraints, []) rand = MockNetworkRandomizer(s_pombe, constraints=[c3]) self.assertEqual(rand.network, s_pombe) self.assertTrue(nx.is_isomorphic(rand.graph, s_pombe.network_graph())) self.assertEqual(rand.timeout, 1000) self.assertEqual(rand.constraints, []) self.assertEqual(rand.trand.constraints, [c3]) rand = MockNetworkRandomizer(s_pombe, constraints=[c1, c3, c2]) self.assertEqual(rand.network, s_pombe) self.assertTrue(nx.is_isomorphic(rand.graph, s_pombe.network_graph())) self.assertEqual(rand.timeout, 1000) self.assertEqual(len(rand.constraints), 2) self.assertEqual(rand.constraints[0], c1) self.assertIsInstance(rand.constraints[1], GenericDynamical) self.assertEqual(rand.constraints[1].test, c2) self.assertEqual(rand.trand.constraints, [c3]) with self.assertRaises(TypeError): MockNetworkRandomizer(s_pombe, constraints=[5])