Added basic unit tests of non-integrated functions

This commit is contained in:
Joel Collins 2020-11-25 15:25:17 +00:00
parent f54684b460
commit 5137d1b9dc
7 changed files with 228 additions and 46 deletions

View file

@ -0,0 +1,59 @@
from pprint import pprint
from openflexure_microscope.api.default_extensions import scan
def test_construct_grid_raster():
grid = scan.construct_grid((0, 0), (100, 100), (3, 3), style="raster")
assert grid == [
[(0, 0), (0, 100), (0, 200)],
[(100, 0), (100, 100), (100, 200)],
[(200, 0), (200, 100), (200, 200)],
]
def test_construct_grid_snake():
grid = scan.construct_grid((0, 0), (100, 100), (3, 3), style="snake")
assert grid == [
[(0, 0), (0, 100), (0, 200)],
[(100, 200), (100, 100), (100, 0)],
[(200, 0), (200, 100), (200, 200)],
]
def test_construct_grid_spiral():
grid = scan.construct_grid((0, 0), (100, 100), (3, 0), style="spiral")
assert grid == [
[(0, 0)],
[
(0, 100),
(100, 100),
(100, 0),
(100, -100),
(0, -100),
(-100, -100),
(-100, 0),
(-100, 100),
],
[
(-100, 200),
(0, 200),
(100, 200),
(200, 200),
(200, 100),
(200, 0),
(200, -100),
(200, -200),
(100, -200),
(0, -200),
(-100, -200),
(-200, -200),
(-200, -100),
(-200, 0),
(-200, 100),
(-200, 200),
],
]
# Ensure second n_steps value makes no difference
assert grid == scan.construct_grid((0, 0), (100, 100), (3, 3), style="spiral")

31
tests/test_utilities.py Normal file
View file

@ -0,0 +1,31 @@
import numpy as np
from openflexure_microscope import utilities
def test_serialise_array_b64():
shape_in = (3, 2)
arr_in = np.random.randint(100, size=shape_in, dtype=np.int)
b64_string, dtype, shape = utilities.serialise_array_b64(arr_in)
assert b64_string
assert dtype == "int32"
assert shape == shape_in
arr_out = utilities.deserialise_array_b64(b64_string, dtype, shape)
assert np.array_equal(arr_out, arr_in)
def test_ndarray_to_json():
shape_in = (3, 2)
arr_in = np.random.randint(100, size=shape_in, dtype=np.int)
json_out = utilities.ndarray_to_json(arr_in)
arr_out = utilities.json_to_ndarray(json_out)
assert np.array_equal(arr_out, arr_in)
def test_axes_to_array():
dict_in = {"x": 1, "y": 2, "z": 3}
assert utilities.axes_to_array(dict_in) == [1, 2, 3]