def test_solver_should_be_solved(self):
     solver = single_electron.EigenSolver(self.grids, self.potential_fn)
     # The solver is not solved.
     with self.assertRaisesRegexp(ValueError,
                                  r'Input solver is not solved.'):
         single_electron.solved_1dsolver_to_example(solver,
                                                    self.potential_params)
    def test_example_output(self):
        solver = single_electron.EigenSolver(self.grids, self.potential_fn)
        solver.solve_ground_state()

        example = single_electron.solved_1dsolver_to_example(
            solver, self.potential_params)

        self.assertLen(example.features.feature['density'].float_list.value,
                       10)
        self.assertLen(example.features.feature['potential'].float_list.value,
                       10)
        np.testing.assert_allclose(
            example.features.feature['kinetic_energy'].float_list.value,
            [0.82937312])
        np.testing.assert_allclose(
            example.features.feature['total_energy'].float_list.value,
            [0.07467839])
        np.testing.assert_allclose(
            example.features.feature['dx'].float_list.value,
            # dx = (1 + 1) / (10 - 1)
            [0.2222222222])
        np.testing.assert_allclose(
            example.features.feature['mu'].float_list.value,
            self.potential_params['mu'])
        np.testing.assert_allclose(
            example.features.feature['sigma'].float_list.value,
            self.potential_params['sigma'])
        np.testing.assert_allclose(
            example.features.feature['coeff'].float_list.value,
            self.potential_params['coeff'])