Пример #1
0
    def test_one_col_image(self):
        width = 1
        height = 100
        resolution = 100
        pi = 40
        row = math.floor(pi / width)

        n4 = mtlib.get_4_neighbors(width, height, resolution, pi, row)
        n8 = mtlib.get_8_neighbors(width, height, resolution, pi, row)

        self.assertEqual(2, len(n4))
        self.assertEqual(39, n4[0])
        self.assertEqual(41, n4[1])
        self.assertEqual(n4, n8)
Пример #2
0
    def test_lower_left_corner(self):
        width = 20
        height = 10
        resolution = 200
        pi = 199
        row = 9

        n4 = mtlib.get_4_neighbors(width, height, resolution, pi, row)
        n8 = mtlib.get_8_neighbors(width, height, resolution, pi, row)

        self.assertEqual(2, len(n4))
        self.assertTrue(198 in n4)
        self.assertTrue(179 in n4)

        self.assertEqual(3, len(n8))
        self.assertTrue(all(pi in n8 for pi in n4))
        self.assertTrue(178 in n8)
Пример #3
0
    def test_upper_right_corner(self):
        width = 20
        height = 10
        resolution = 200
        pi = 19
        row = 0

        n4 = mtlib.get_4_neighbors(width, height, resolution, pi, row)
        n8 = mtlib.get_8_neighbors(width, height, resolution, pi, row)

        self.assertEqual(2, len(n4))
        self.assertTrue(18 in n4)
        self.assertTrue(39 in n4)

        self.assertEqual(3, len(n8))
        self.assertTrue(all(pi in n8 for pi in n4))
        self.assertTrue(38 in n8)
Пример #4
0
    def test_fetch_inside(self):
        width = 20
        height = 10
        resolution = 200
        pi = 50
        row = math.floor(pi / width)

        n4 = mtlib.get_4_neighbors(width, height, resolution, pi, row)
        n8 = mtlib.get_8_neighbors(width, height, resolution, pi, row)

        self.assertEqual(4, len(n4))
        self.assertTrue(49 in n4)
        self.assertTrue(51 in n4)
        self.assertTrue(30 in n4)
        self.assertTrue(70 in n4)

        self.assertEqual(8, len(n8))
        self.assertTrue(71 in n8)
        self.assertTrue(69 in n8)
        self.assertTrue(29 in n8)
        self.assertTrue(31 in n8)
        self.assertTrue(all(pi in n8 for pi in n4))
Пример #5
0
    def test_fetch_empty_image(self):
        with self.assertRaises(ZeroDivisionError):
            mtlib.get_4_neighbors(0, 0, 0, 0, 0)

        with self.assertRaises(ZeroDivisionError):
            mtlib.get_8_neighbors(0, 0, 0, 0, 0)