Skip to content

Commit 896f894

Browse files
committed
Added unit test for grayscale image determination function
1 parent 08ea808 commit 896f894

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

tests/util/test_clem_array_functions.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
flatten_image,
1616
get_dtype_info,
1717
get_valid_dtypes,
18+
is_grayscale_image,
1819
is_image_stack,
1920
merge_images,
2021
preprocess_img_stk,
@@ -751,6 +752,57 @@ def gaussian_2d(
751752
)
752753

753754

755+
is_grayscale_image_test_matrix = (
756+
# Shape | Result
757+
# These should pass
758+
((64, 64), True),
759+
((1, 64, 64), True),
760+
((5, 64, 64), True),
761+
# These should fail without erroring
762+
((64, 64, 3), False),
763+
((64, 64, 4), False),
764+
((1, 64, 64, 3), False),
765+
((5, 64, 64, 3), False),
766+
((1, 64, 64, 4), False),
767+
((5, 64, 64, 4), False),
768+
)
769+
770+
771+
@pytest.mark.parametrize("test_params", is_grayscale_image_test_matrix)
772+
def test_is_grayscale_image(test_params: tuple[tuple[int, ...], bool]):
773+
# Unpack test params
774+
shape, result = test_params
775+
776+
# Construct array
777+
array = np.zeros(shape)
778+
779+
# Check that the result is as expected
780+
assert is_grayscale_image(array) is result
781+
782+
783+
is_grayscale_image_error_cases = (
784+
# Shape
785+
# These should all error
786+
((64,),),
787+
((5, 5, 64, 64),),
788+
((5, 64, 64, 5),),
789+
((5, 5, 5, 64, 64),),
790+
((5, 5, 64, 64, 5),),
791+
)
792+
793+
794+
@pytest.mark.parametrize("test_params", is_grayscale_image_error_cases)
795+
def test_is_grayscale_image_errors(test_params: tuple[tuple[int, ...]]):
796+
# Unpack test params
797+
(shape,) = test_params
798+
799+
# Create array
800+
array = np.zeros(shape)
801+
802+
with pytest.raises(ValueError):
803+
is_grayscale_image(array)
804+
805+
754806
image_coloring_test_matrix = (
755807
# Colour | dtype | frames
756808
# 0

0 commit comments

Comments
 (0)