def test_exception_when_adding_multiple_invalid_bonds(self): # new test for adding bonds with particles that are # not part of the container # (proposed to throw ValueError, see wiki) # given container = self.container bonds = create_bonds_with_id() with self.assertRaises(ValueError): container.add(bonds)
def test_create_bonds_with_id(self): n = 9 bonds = create_bonds_with_id(n=n) self.assertEqual(len(bonds), n) uids = set() for index, bond in enumerate(bonds): self.assertIsInstance(bond, Bond) self.assertIsNotNone(bond.uid) compare_data_containers( bond.data, create_data_container(constant=index), testcase=self) self.assertEqual(len(bond.particles), n) uids.update(bond.particles) self.assertEqual(len(uids), n*n)
def test_create_bonds_with_id(self): n = 9 bonds = create_bonds_with_id(n=n) self.assertEqual(len(bonds), n) uids = set() for index, bond in enumerate(bonds): self.assertIsInstance(bond, Bond) self.assertIsNotNone(bond.uid) compare_data_containers(bond.data, create_data_container(constant=index), testcase=self) self.assertEqual(len(bond.particles), n) uids.update(bond.particles) self.assertEqual(len(uids), n * n)
def test_add_multiple_bonds_with_id(self): # given container = self.container uid = uuid.uuid4() bonds = create_bonds_with_id() # when uids = container.add_bonds(bonds) # then for bond in bonds: uid = bond.uid self.assertIn(uid, uids) self.assertTrue(container.has_bond(uid)) self.assertEqual(container.get_bond(uid), bond)
def test_create_bonds_with_ids_and_particles(self): n = 9 particles = create_particles(n=100) for particle in particles: particle.uid = uuid.uuid4() bonds = create_bonds_with_id(n=n, particles=particles) uids = set() self.assertEqual(len(bonds), n) for index, bond in enumerate(bonds): self.assertIsInstance(bond, Bond) self.assertIsNotNone(bond.uid) compare_data_containers( bond.data, create_data_container(constant=index), testcase=self) self.assertEqual(len(bond.particles), n) uids.update(bond.particles) self.assertLessEqual(len(uids), n**2)
def test_create_bonds_with_ids_and_particles(self): n = 9 particles = create_particles(n=100) for particle in particles: particle.uid = uuid.uuid4() bonds = create_bonds_with_id(n=n, particles=particles) uids = set() self.assertEqual(len(bonds), n) for index, bond in enumerate(bonds): self.assertIsInstance(bond, Bond) self.assertIsNotNone(bond.uid) compare_data_containers(bond.data, create_data_container(constant=index), testcase=self) self.assertEqual(len(bond.particles), n) uids.update(bond.particles) self.assertLessEqual(len(uids), n**2)
def test_add_multiple_bonds_with_id(self): # for simphony-common 0.2.1 when Bond can be added # even if it contains particles that are not part of # the container (proposed to throw ValueError, see wiki) # given container = self.container bonds = create_bonds_with_id(particles=self.particle_list, restrict=supported_cuba()) # when uids = container.add(bonds) # then for bond in bonds: uid = bond.uid self.assertIn(uid, uids) self.assertTrue(container.has(uid)) self.assertEqual(container.get(uid), bond)