Skip to content
Snippets Groups Projects
Commit d236804b authored by Alán Muñoz's avatar Alán Muñoz
Browse files

fix tests after threshold modification

parent 6fc3b713
No related branches found
No related tags found
No related merge requests found
......@@ -6,15 +6,70 @@ from aliby.tile.traps import identify_trap_locations
class TestCase(unittest.TestCase):
def setUp(self):
self.data = np.pad(np.ones((5, 5)), 10, mode="constant")
self.template = np.pad(np.ones((5, 5)), 2, mode="constant")
self.trap_size = 5
self.tile_size = 9
assert self.trap_size % 2
assert self.tile_size % 2
self.img_size = 16
self.data = np.pad(
np.ones((self.trap_size, self.trap_size)),
(self.img_size - self.tile_size) // 2,
mode="constant",
)
self.template = np.pad(
np.ones((self.trap_size, self.trap_size)),
(self.tile_size - self.trap_size) // 2,
mode="constant",
)
self.expected_location = int(
(np.ceil((self.img_size - self.tile_size + self.trap_size) / 2) - 1)
)
def test_identify_trap_locations(self):
coords = identify_trap_locations(
self.data, self.template, optimize_scale=False, downscale=1
self.data,
self.template,
optimize_scale=False,
downscale=1,
)
self.assertEqual(len(coords), 1)
self.assertEqual(coords[0].tolist(), [12, 12])
self.assertEqual(
coords[0].tolist(),
[self.expected_location, self.expected_location],
)
class TestMultipleCase(TestCase):
def setUp(self):
self.nrows = 4
self.ncols = 4
super().setUp()
row = np.concatenate([self.data for i in range(self.ncols)])
self.data = np.concatenate([row for i in range(self.nrows)], axis=1)
def test_identify_trap_locations(self):
coords = identify_trap_locations(
self.data,
self.template,
optimize_scale=False,
downscale=1,
)
self.expected_locations = set(
[
(
self.expected_location + i * (self.img_size - self.trap_size),
self.expected_location + j * (self.img_size - self.trap_size),
)
for i in range(self.nrows)
for j in range(self.ncols)
]
)
ntraps = self.nrows * self.ncols
self.assertEqual(len(coords), ntraps)
self.assertEqual(
ntraps,
len(self.expected_locations.intersection([tuple(x) for x in coords])),
)
if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment