aboutsummaryrefslogtreecommitdiff
path: root/test/test_graphic.py
blob: 0fa264074989a36b975794e3cc71cc89b5a52741 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'''
Test solutions by comparing with results known to be correct
'''

import pytest
import numpy as np

from schroedinger import (
    Config, build_potential, solve_schroedinger
)

POTENTIAL = {}
ENERGIES = {}
WAVEFUNCS = {}

FORMS = ['asymmetric', 'double_linear', 'double_cubic', 'harmonic', 'finite']

@pytest.mark.parametrize('form', FORMS)
def test_potential(form: str) -> None:
    '''Compare potential with stored result'''
    potential_prec = np.loadtxt(f'test/{form}/potential.dat')
    assert np.allclose(POTENTIAL[form], potential_prec, rtol=1e-2, atol=1e-2)


@pytest.mark.parametrize('form', FORMS)
def test_energy(form: str) -> None:
    '''Compare energy with stored result'''
    e_prec = np.loadtxt(f'test/{form}/energies.dat')
    assert np.allclose(ENERGIES[form], e_prec, rtol=1e-2, atol=1e-2)


@pytest.mark.parametrize('form', FORMS)
def test_wavefunc(form: str) -> None:
    '''Compare wave functions with stored result'''
    v_prec = np.loadtxt(f'test/{form}/wavefuncs.dat')[:, 1:]
    assert np.allclose(WAVEFUNCS[form], v_prec, rtol=1e-2, atol=1e-2)


def setup_module():
    '''Set up global variables for tests to run'''

    for form in FORMS:
        conf = Config(f'test/{form}.inp')
        POTENTIAL[form], delta = build_potential(conf)
        ENERGIES[form], WAVEFUNCS[form] = solve_schroedinger(
            conf.mass, POTENTIAL[form][:, 1], delta, conf.eig_interval)