def generate_cuds(self): pset1 = create_particles_with_id(restrict=[CUBA.VELOCITY]) for p in pset1: p.data[CUBA.MATERIAL_TYPE] = 1 pset2 = create_particles_with_id(restrict=[CUBA.VELOCITY]) for p in pset2: p.data[CUBA.MATERIAL_TYPE] = 1 ps1 = Particles('ps1') ps2 = Particles('ps2') ps1.add(pset1) ps2.add(pset2) c = CUDS() c.add([ps2]) mat = api.Material() mat.data[CUBA.MASS] = 1.0 c.add([mat]) box = api.Box() c.add([box]) return c
def test_compare_particles_datasets_not_equal(self): # given particles = Particles(name="test") reference = Particles(name="test_ref") particle_list = create_particles_with_id() bond_list = create_bonds() data = create_data_container() particles.add_particles(particle_list) reference.add_particles(particle_list) particles.add_bonds(bond_list) reference.add_bonds(bond_list) particles.data = data reference.data = data # when/then with self.assertRaises(AssertionError): compare_particles_datasets(particles, reference, testcase=self) # given test_particles = create_particles_with_id() particles = Particles(name=reference.name) particles.add_particles(test_particles) particles.add_bonds(bond_list) particles.data = data # when/then with self.assertRaises(AssertionError): compare_particles_datasets(particles, reference, testcase=self) # given test_bonds = create_bonds() particles = Particles(name=reference.name) particles.add_particles(particle_list) particles.add_bonds(test_bonds) particles.data = data # when/then with self.assertRaises(AssertionError): compare_particles_datasets(particles, reference, testcase=self) # given test_data = DataContainer() particles = Particles(name=reference.name) particles.add_particles(particle_list) particles.add_bonds(bond_list) particles.data = test_data # when/then with self.assertRaises(AssertionError): compare_particles_datasets(particles, reference, testcase=self)
def test_compare_particles_datasets_not_equal(self): # given particles = Particles(name="test") reference = Particles(name="test_ref") particle_list = create_particles_with_id() bond_list = create_bonds() data = create_data_container() particles.add(particle_list) reference.add(particle_list) particles.add(bond_list) reference.add(bond_list) particles.data = data reference.data = data # when/then with self.assertRaises(AssertionError): compare_particles_datasets(particles, reference, testcase=self) # given test_particles = create_particles_with_id() particles = Particles(name=reference.name) particles.add(test_particles) particles.add(bond_list) particles.data = data # when/then with self.assertRaises(AssertionError): compare_particles_datasets(particles, reference, testcase=self) # given test_bonds = create_bonds() particles = Particles(name=reference.name) particles.add(particle_list) particles.add(test_bonds) particles.data = data # when/then with self.assertRaises(AssertionError): compare_particles_datasets(particles, reference, testcase=self) # given test_data = DataContainer() particles = Particles(name=reference.name) particles.add(particle_list) particles.add(bond_list) particles.data = test_data # when/then with self.assertRaises(AssertionError): compare_particles_datasets(particles, reference, testcase=self)
def test_compare_mesh_datasets_equal(self): # given mesh = Mesh(name="test") reference = Mesh(name="test") point_list = create_particles_with_id() edge_list = create_edges() face_list = create_faces() cell_list = create_cells() data = DataContainer() mesh.add_points(point_list) mesh.add_edges(edge_list) mesh.add_faces(face_list) mesh.add_cells(cell_list) reference.add_points(point_list) reference.add_edges(edge_list) reference.add_faces(face_list) reference.add_cells(cell_list) mesh.data = data reference.data = data # this should pass without problems compare_mesh_datasets(mesh, reference, testcase=self)
def test_create_particles_with_id(self): particles = create_particles_with_id(n=9) self.assertEqual(len(particles), 9) for index, particle in enumerate(particles): self.assertIsInstance(particle, Particle) self.assertIsNotNone(particle.uid) self.assertEqual( particle.coordinates, (index, index*10, index*100)) compare_data_containers( particle.data, create_data_container(), testcase=self)
def test_create_particles_with_id(self): particles = create_particles_with_id(n=9) self.assertEqual(len(particles), 9) for index, particle in enumerate(particles): self.assertIsInstance(particle, Particle) self.assertIsNotNone(particle.uid) self.assertEqual(particle.coordinates, (index, index * 10, index * 100)) compare_data_containers(particle.data, create_data_container(), testcase=self)
def test_add_multiple_particles_with_id(self): # given container = self.container particles = create_particles_with_id(restrict=self.supported_cuba()) # when uids = container.add_particles(particles) # then for particle in particles: uid = particle.uid self.assertIn(uid, uids) self.assertTrue(container.has_particle(uid)) self.assertEqual(container.get_particle(uid), particle)
def test_exception_when_removing_multiple_particles_with_bad_id(self): # given container = self.container particles = create_particles_with_id() uids = [p.uid for p in particles] # then with self.assertRaises(KeyError): # when container.remove_particles(uids) # then with self.assertRaises(KeyError): # when container.remove_particles([None])
def test_exception_when_update_multiple_particles_when_wrong_id(self): # given container = self.container particles = create_particles() # then with self.assertRaises(ValueError): # when container.update_particles(particles) # given particles = create_particles_with_id() # then with self.assertRaises(ValueError): # when container.update_particles(particles)
def test_compare_particles_datasets_equal(self): # given particles = Particles(name="test") reference = Particles(name="test") particle_list = create_particles_with_id() bond_list = create_bonds() data = DataContainer() particles.add_particles(particle_list) reference.add_particles(particle_list) particles.add_bonds(bond_list) reference.add_bonds(bond_list) particles.data = data reference.data = data # this should pass without problems compare_particles_datasets(particles, reference, testcase=self)
def test_compare_particles_datasets_equal(self): # given particles = Particles(name="test") reference = Particles(name="test") particle_list = create_particles_with_id() bond_list = create_bonds() data = DataContainer() particles.add(particle_list) reference.add(particle_list) particles.add(bond_list) reference.add(bond_list) particles.data = data reference.data = data # this should pass without problems compare_particles_datasets(particles, reference, testcase=self)
def test_add_multiple_particles_with_id(self): # given container = self.container particles = create_particles_with_id(restrict=self.supported_cuba()) # TODO. This ia fix so particles have the right attributes # for lammps (MD) material = self.configurator.materials[0] for p in particles: p.data[CUBA.MATERIAL_TYPE] = material.uid # when uids = container.add(particles) # then for particle in particles: uid = particle.uid self.assertIn(uid, uids) self.assertTrue(container.has(uid)) self.assertEqual(container.get(uid), particle)
def test_compare_mesh_datasets_not_equal(self): # given mesh = Mesh(name="test") reference = Mesh(name="test_ref") point_list = create_particles_with_id() edge_list = create_edges() face_list = create_faces() cell_list = create_cells() data = create_data_container() mesh.add_points(point_list) mesh.add_edges(edge_list) mesh.add_faces(face_list) mesh.add_cells(cell_list) reference.add_points(point_list) reference.add_edges(edge_list) reference.add_faces(face_list) reference.add_cells(cell_list) mesh.data = data reference.data = data # when/then with self.assertRaises(AssertionError): compare_mesh_datasets(mesh, reference, testcase=self) # given test_points = create_points_with_id() mesh = Mesh(name=reference.name) mesh.add_points(test_points) mesh.add_edges(edge_list) mesh.add_faces(face_list) mesh.add_cells(cell_list) mesh.data = data # when/then with self.assertRaises(AssertionError): compare_mesh_datasets(mesh, reference, testcase=self) # given test_edges = create_edges() mesh = Mesh(name=reference.name) mesh.add_points(point_list) mesh.add_edges(test_edges) mesh.add_faces(face_list) mesh.add_cells(cell_list) mesh.data = data # when/then with self.assertRaises(AssertionError): compare_mesh_datasets(mesh, reference, testcase=self) # given test_faces = create_faces() mesh = Mesh(name=reference.name) mesh.add_points(point_list) mesh.add_edges(edge_list) mesh.add_faces(test_faces) mesh.add_cells(cell_list) mesh.data = data # when/then with self.assertRaises(AssertionError): compare_mesh_datasets(mesh, reference, testcase=self) # given test_cells = create_cells() mesh = Mesh(name=reference.name) mesh.add_points(point_list) mesh.add_edges(edge_list) mesh.add_faces(face_list) mesh.add_cells(test_cells) mesh.data = data # when/then with self.assertRaises(AssertionError): compare_mesh_datasets(mesh, reference, testcase=self) # given test_data = DataContainer() mesh = Mesh(name=reference.name) mesh.add_points(point_list) mesh.add_edges(edge_list) mesh.add_faces(face_list) mesh.add_cells(cell_list) mesh.data = test_data # when/then with self.assertRaises(AssertionError): compare_mesh_datasets(mesh, reference, testcase=self)