def test_no_match(self): blank = np.zeros((100, 100)) template = np.array([[0, 1], [1, 0]]) expected = [] actual = best_convolution(template, blank) self.assertEquals(expected, actual)
def test_match(self): image = np.array([[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]) template = np.array([[0, 1], [1, 0]]) expected = [(1, 5), (5, 2), (2, 4)] actual = best_convolution(template, image) self.assertEquals(sorted(expected), sorted(actual))
def test_template_too_big(self): template = np.array([[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]) image = np.array([[0, 1], [1, 0]]) expected = [] actual = best_convolution(template, image) self.assertEquals(sorted(expected), sorted(actual))