diff --git a/coverage-report.pdf b/coverage-report.pdf new file mode 100644 index 0000000..83960e4 Binary files /dev/null and b/coverage-report.pdf differ diff --git a/diffusion2d.py b/diffusion2d.py index 51a07f2..6c9133c 100644 --- a/diffusion2d.py +++ b/diffusion2d.py @@ -38,6 +38,10 @@ def __init__(self): self.dt = None def initialize_domain(self, w=10., h=10., dx=0.1, dy=0.1): + assert type(w) == float + assert type(h) == float + assert type(dx) == float + assert type(dy) == float self.w = w self.h = h self.dx = dx @@ -45,7 +49,10 @@ def initialize_domain(self, w=10., h=10., dx=0.1, dy=0.1): self.nx = int(w / dx) self.ny = int(h / dy) - def initialize_physical_parameters(self, d=4., T_cold=300, T_hot=700): + def initialize_physical_parameters(self, d=4., T_cold=300., T_hot=700.): + assert type(d) == float + assert type(T_cold) == float + assert type(T_hot) == float self.D = d self.T_cold = T_cold self.T_hot = T_hot diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d8ab3c2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +numpy +matplotlib +pytest +coverage \ No newline at end of file diff --git a/tests/integration/test_diffusion2d.py b/tests/integration/test_diffusion2d.py index fd026b4..1a4ccd9 100644 --- a/tests/integration/test_diffusion2d.py +++ b/tests/integration/test_diffusion2d.py @@ -3,6 +3,7 @@ """ from diffusion2d import SolveDiffusion2D +import numpy as np def test_initialize_physical_parameters(): @@ -11,9 +12,39 @@ def test_initialize_physical_parameters(): """ solver = SolveDiffusion2D() + w = 10. + h = 10. + dx = 0.5 + dy = 0.5 + solver.initialize_domain(w=w, h=h, dx=dx, dy=dy) + + d = 2. + T_cold = 150. + T_hot = 350. + solver.initialize_physical_parameters(d=d, T_cold=T_cold, T_hot=T_hot) + expected_result = 0.03125 + + assert solver.dt == expected_result + def test_set_initial_condition(): """ Checks function SolveDiffusion2D.get_initial_function """ + # compute a similar `u` array for defined parameters + w = 12. + h = 18. + dx = 2. + dy = 6. + T_cold = 6. + nx = int(w / dx) + ny = int(h / dy) solver = SolveDiffusion2D() + solver.initialize_domain(w=w, h=h, dx=dx, dy=dy) + solver.initialize_physical_parameters(T_cold=T_cold) + solver.cx = 4 + solver.cy = 2 + expected_u = solver.T_cold * np.ones((nx, ny)).copy() + + computed_u = solver.set_initial_condition() + assert computed_u.all() == expected_u.all() diff --git a/tests/unit/test_diffusion2d_functions.py b/tests/unit/test_diffusion2d_functions.py index c4277ff..3adac82 100644 --- a/tests/unit/test_diffusion2d_functions.py +++ b/tests/unit/test_diffusion2d_functions.py @@ -3,24 +3,53 @@ """ from diffusion2d import SolveDiffusion2D +import numpy as np def test_initialize_domain(): """ Check function SolveDiffusion2D.initialize_domain """ + w = 100. + h = 120. + dx = 0.5 + dy = 0.5 + expected_nx = 200. + expected_ny = 240. solver = SolveDiffusion2D() + solver.initialize_domain(w=w, h=h, dx=dx, dy=dy) + assert solver.nx == expected_nx + assert solver.ny == expected_ny def test_initialize_physical_parameters(): """ Checks function SolveDiffusion2D.initialize_domain """ + d = 2. + T_cold = 150. + T_hot = 350. solver = SolveDiffusion2D() + solver.dx = 0.5 + solver.dy = 0.5 + expected_dt = 0.03125 + solver.initialize_physical_parameters(d=d, T_cold=T_cold, T_hot=T_hot) + assert solver.dt == expected_dt def test_set_initial_condition(): """ Checks function SolveDiffusion2D.get_initial_function """ solver = SolveDiffusion2D() + solver.T_cold = 6 + solver.nx = 6 + solver.ny = 3 + solver.dx = 9 + solver.dy = 3 + solver.cx = 4 + solver.cy = 2 + expected_result = solver.T_cold * np.ones((solver.nx, solver.ny)).copy() + + actual_result = solver.set_initial_condition() + assert actual_result.all() == expected_result.all() diff --git a/tox.toml b/tox.toml new file mode 100644 index 0000000..4f7089a --- /dev/null +++ b/tox.toml @@ -0,0 +1,7 @@ +requires = ["tox>=4"] +env_list = ["pytest_testing"] + +[env.pytest_testing] +description = "Run pytest" +deps = ["-rrequirements.txt"] +commands = [["python3", "-m", "pytest"]] \ No newline at end of file