forked from bdhammel/ising-model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
49 lines (39 loc) · 1.82 KB
/
test.py
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
47
48
49
from unittest import mock
import numpy as np
import pytest
from ising import IsingLattice
@pytest.mark.parametrize('i, t', [
(100, 0), # a value at 100 wraps around to 0 # noqa
(99, 99), # a value at 99 is in the lattice # noqa
(0, 0), # a value at 0 is in the lattice # noqa
(-1, 99) # a value at -1 wraps around to 99 # noqa
])
def test_boundary_conditions(i, t):
mock_self = mock.Mock()
mock_self.size = 100
r = IsingLattice._bc(mock_self, i)
assert r == t # is the returned value the true value # noqa
@pytest.mark.parametrize('i, system, e', [
((1, 1), np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]]), -8), # most probable state # noqa
((1, 1), np.array([[-1, -1, -1], [-1, -1, -1], [-1, -1, -1]]), -8), # most probable state # noqa
((1, 1), np.array([[-1, -1, -1], [-1, 1, -1], [-1, -1, -1]]), 8), # least probable state # noqa
((1, 1), np.array([[1, -1, 1], [-1, 1, 1], [1, 1, 1]]), 0), # 50/50 state # noqa
])
def test_energy_calculation_is_correct(i, system, e):
lattice = IsingLattice(temperature=1, initial_state='u', size=3)
lattice.system = system
_e = lattice.energy(*i)
assert _e == e # is the returned value the true value
@pytest.mark.skip("TODO")
def check_internel_energy_is_correct():
pass
@pytest.mark.parametrize('system, m', [
(np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]]), 1), # uniform magnetization # noqa
(np.array([[-1, -1, -1], [-1, -1, -1], [-1, -1, -1]]), 1), # uniform magnetization # noqa
(np.array([[-1, -1, -1], [-1, -1, 1], [1, 1, 1]]), 1/9), # net magnetization (i.e. sum of system) 1/9 # noqa
])
def test_magnitization_correct(system, m):
lattice = IsingLattice(temperature=1, initial_state='u', size=3)
lattice.system = system
_m = lattice.magnetization
assert _m == m