-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathtest_diffusion2d_functions.py
More file actions
69 lines (57 loc) · 1.73 KB
/
test_diffusion2d_functions.py
File metadata and controls
69 lines (57 loc) · 1.73 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
Tests for functions in class SolveDiffusion2D
"""
from unittest.mock import MagicMock
from diffusion2d import SolveDiffusion2D
import pytest
import numpy
@pytest.mark.parametrize(("width", "height", "dx", "dy", "expected_dx", "expected_dy"),
[(11.0,12.0,0.5,0.3, 22, 40)]
)
def test_initialize_domain(width, height, dx, dy, expected_dx, expected_dy):
"""
Check function SolveDiffusion2D.initialize_domain
"""
solver = SolveDiffusion2D()
solver.initialize_domain(width, height, dx, dy)
assert solver.nx == expected_dx
assert solver.ny == expected_dy
@pytest.mark.parametrize(
("d", "T_cold", "T_hot", "expected_dt"),
[(5.0, 321.0, 723.0, 0.0005)]
)
def test_initialize_physical_parameters(d, T_cold, T_hot, expected_dt):
"""
Checks function SolveDiffusion2D.initialize_domain
"""
solver = SolveDiffusion2D()
solver.w = 10.0
solver.h = 10.0
solver.dx = 0.1
solver.dy = 0.1
solver.nx = 100
solver.ny = 100
dt = solver.initialize_physical_parameters(d, T_cold, T_hot)
solver.dt == pytest.approx(expected_dt, rel=1e-4)
@pytest.mark.parametrize(("T_cold", "T_hot"),
[(302.0, 700.0)])
def test_set_initial_condition(T_cold, T_hot):
"""
Checks function SolveDiffusion2D.get_initial_function
"""
solver = SolveDiffusion2D()
solver.T_cold = T_cold
solver.T_hot = T_hot
solver.w = 10.0
solver.h = 10.0
solver.dx = 0.1
solver.dy = 0.1
solver.nx = 100
solver.ny = 100
u = solver.set_initial_condition()
assert u.shape == (solver.nx, solver.ny)
assert numpy.all(u >= T_cold)
assert numpy.all(u <= T_hot)
assert u[50, 50] == T_hot
def test_time_step():
assert True