def test_define_lattice_from_file(self): with patch('lattice_mc.init_lattice.lattice_from_sites_file' ) as mock_lattice_from_file: mock_lattice_from_file.return_value = 'foo' simulation = Simulation() cell_lengths = np.array([1.0, 2.0, 3.0]) simulation.define_lattice_from_file('filename', cell_lengths) self.assertEqual(simulation.lattice, 'foo') mock_lattice_from_file.assert_called_with( 'filename', cell_lengths=cell_lengths)
def test_set_number_of_atoms_with_specific_sites(self): simulation = Simulation() simulation.lattice = Mock(spec=Lattice) mock_atoms = [Mock(spec=Atom), Mock(spec=Atom)] simulation.lattice.populate_sites = Mock(return_value=mock_atoms) with patch('lattice_mc.species.Species') as mock_Species: mock_Species.return_value = 'some atoms' simulation.set_number_of_atoms(3, selected_sites=['A']) self.assertEqual( simulation.lattice.populate_sites.call_args[1] ['selected_sites'], ['A'])
def test_set_number_of_atoms(self): simulation = Simulation() simulation.lattice = Mock(spec=Lattice) mock_atoms = [Mock(spec=Atom), Mock(spec=Atom)] simulation.lattice.populate_sites = Mock(return_value=mock_atoms) with patch('lattice_mc.species.Species') as mock_Species: mock_Species.return_value = 'some atoms' simulation.set_number_of_atoms(3) self.assertEqual(simulation.number_of_atoms, 3) self.assertEqual(simulation.atoms, 'some atoms') mock_Species.assert_called_with(mock_atoms)
def test_run_with_equilibration_steps(self): simulation = Simulation() simulation.is_initialised = Mock(return_value=(True, None)) simulation.atoms = 'a' simulation.lattice = Mock(spec=Lattice) simulation.lattice.jump = Mock() simulation.reset = Mock() simulation.number_of_equilibration_jumps = 20 simulation.number_of_jumps = 30 simulation.run() self.assertEqual(simulation.lattice.jump.call_count, 20 + 30) self.assertEqual(simulation.reset.call_count, 1)
def test_is_initialised_fails_with_no_lattice(self): simulation = Simulation() simulation.atoms = 'foo' simulation.number_of_jumps = 'bar' simulation.lattice = None with self.assertRaises(AttributeError): simulation.is_initialised()
def test_simulation_is_initialised(self): simulation = Simulation() self.assertEqual(simulation.lattice, None) self.assertEqual(simulation.number_of_atoms, None) self.assertEqual(simulation.number_of_equilibration_jumps, 0) self.assertEqual(simulation.number_of_jumps, None) self.assertEqual(simulation.for_time, None) self.assertEqual(simulation.number_of_atoms, None) self.assertEqual(simulation.has_run, False)
def test_reset(self): simulation = Simulation() simulation.lattice = Mock(spec=Lattice) simulation.atoms = Mock(spec=Species) simulation.atoms.atoms = [Mock(spec=Atom), Mock(spec=Atom)] simulation.reset() self.assertEqual(simulation.lattice.reset.call_count, 1) self.assertEqual(simulation.atoms.atoms[0].reset.call_count, 1) self.assertEqual(simulation.atoms.atoms[1].reset.call_count, 1)
def test_run_for_time(self): simulation = Simulation() simulation.is_initialised = Mock(return_value=(True, None)) simulation.atoms = 'a' simulation.lattice = Mock(spec=Lattice) simulation.lattice.time = 0.0 def fake_jump_method(): simulation.lattice.time += 1.0 simulation.lattice.jump = fake_jump_method simulation.run(for_time=10.0) self.assertEqual(simulation.lattice.time, 10.0) self.assertEqual(simulation.number_of_jumps, 10)
def test_collective_correlation(self): s = Simulation() self.assertEqual(s.collective_correlation, None)
def test_set_site_energies(self): simulation = Simulation() simulation.lattice = Mock(spec=Lattice) simulation.lattice.set_site_energies = Mock() simulation.set_site_energies('foo') simulation.lattice.set_site_energies.assert_called_with('foo')
def test_set_nn_energy(self): simulation = Simulation() simulation.lattice = Mock(spec=Lattice) simulation.lattice.set_nn_energy = Mock() simulation.set_nn_energy('foo') simulation.lattice.set_nn_energy.assert_called_with('foo')
def test_set_number_of_equilibration_jumps(self): simulation = Simulation() simulation.set_number_of_equilibration_jumps(32) self.assertEqual(simulation.number_of_equilibration_jumps, 32)
def setUp(self): self.simulation = Simulation() self.simulation.has_run = True
def test_collective_diffusion_coefficient_per_atom(self): s = Simulation() self.assertEqual(s.collective_diffusion_coefficient_per_atom, None)
def test_run_raises_error_if_not_initialised(self): simulation = Simulation() simulation.is_initialised = Mock(side_effect=AttributeError('test')) with self.assertRaises(AttributeError) as context: simulation.run()
def test_tracer_diffusion_coefficient(self): s = Simulation() self.assertEqual(s.tracer_diffusion_coefficient, None)
def test_tracer_correlation(self): s = Simulation() self.assertEqual(s.tracer_correlation, None)