--- title: Tests keywords: fastai sidebar: home_sidebar nb_path: "notebooks/utils/infection.ipynb" ---
import numpy as np
%%time
def test_that_infect_does_not_disinfect():
n, m, k = 10, 8, 2
start_points = torch.tensor(np.random.rand(n, m, k).round(), dtype=bool)
infectable = torch.tensor(np.random.rand(n, m, k).round(), dtype=bool) | start_points
infected = infect(start_points, infectable)
assert infected[start_points].all()
for _ in range(10):
test_that_infect_does_not_disinfect()
%%time
def test_that_only_infectable_parts_are_infected():
n, m, k = 10, 4, 7
start_points = torch.tensor(np.random.rand(n, m, k).round(), dtype=bool)
infectable = torch.tensor(np.random.rand(n, m, k).round(), dtype=bool)
infected = infect(start_points, infectable)
assert not infected[~infectable].any()
for _ in range(10):
test_that_only_infectable_parts_are_infected()
%%time
def test_example0():
n, m, k = 7, 3, 10
start_points = torch.zeros(n, m, k, dtype=bool)
start_points[0, 0, 0] = True
infectable = torch.zeros(n, m, k, dtype=bool)
infectable[0, 0, :] = True
infected = infect(start_points, infectable)
assert infected[0, 0, :].all()
assert not infected[1:, 1:, :].any()
test_example0()
%%time
def test_example1():
n, m, k = 7, 3, 10
start_points = torch.zeros(n, m, k, dtype=bool)
start_points[0, 0, 0] = True
start_points[2, 2, 0] = True
infectable = torch.zeros(n, m, k, dtype=bool)
infectable[0, 0, :] = True
infected = infect(start_points, infectable)
assert infected[0, 0, :].all()
assert not infected[1:, 1:, :].any()
test_example1()
%%time
def test_example2():
n, m, k = 7, 3, 10
start_points = torch.zeros(n, m, k, dtype=bool)
start_points[0, 0, 0] = True
start_points[2, 2, 0] = True
infectable = torch.zeros(n, m, k, dtype=bool)
infectable[0, 0, :] = True
infectable[2, 2, 0] = True
infected = infect(start_points, infectable)
assert infected[0, 0, :].all()
assert infected[2, 2, 0]
assert infected[1:, 1:, :].any()
test_example2()
%%time
def test_example3():
n, m, k = 8, 8, 8
start_points = torch.zeros(n, m, k, dtype=bool)
start_points[0, 1, 0] = True
infectable = torch.zeros(n, m, k, dtype=bool)
infectable[0, 0, :] = True
infected = infect(start_points, infectable)
assert not infected.any()
test_example3()