Skip to content

Commit

Permalink
Add tests for solver module
Browse files Browse the repository at this point in the history
  • Loading branch information
mdpiper committed Sep 5, 2023
1 parent 2496a4f commit f8450af
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lessons/python/ivy-diffusion/tests/test_solver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Test the solver module."""
import math
import numpy as np

from ivy_diffusion.solver import (calculate_time_step, set_initial_profile, solve1d)

DOMAIN_SIZE = 100
GRID_SPACING = 1.0
DIFFUSIVITY = 1.0
TIME_STEP = 0.475
TOLERANCE = 0.01
ZMAX = 500.0


def test_time_step():
time_step = calculate_time_step(GRID_SPACING, DIFFUSIVITY)
assert type(time_step) == float
assert math.isclose(time_step, TIME_STEP, rel_tol=TOLERANCE)


def test_initial_profile_defaults():
z = set_initial_profile()
assert type(z) == np.ndarray
assert len(z) == DOMAIN_SIZE
assert math.isclose(z.max(), ZMAX, rel_tol=TOLERANCE)


def test_solve1d():
z = np.zeros(DOMAIN_SIZE)
z[DOMAIN_SIZE//2] = ZMAX
solve1d(z, time_step=TIME_STEP)
assert type(z) == np.ndarray
assert len(z) == DOMAIN_SIZE
assert z.max() < ZMAX
assert z.sum() == ZMAX

0 comments on commit f8450af

Please sign in to comment.