Exemplo n.º 1
0
 def init_field(self):
     ce = Cell()
     ce.set_free()
     self.field = [[ce for x in xrange(self.map_width)]
                   for x in xrange(self.map_width)]
     self.segmented_field = [[
         self.SEGMENT_MAP_NOT_COLORED for x in xrange(self.map_width)
     ] for x in xrange(self.map_width)]
Exemplo n.º 2
0
    def test1(self):
        c = Cell()
        self.assertTrue(c.is_unknown())
        self.assertFalse(c.is_object())
        self.assertFalse(c.is_obstacle())
        self.assertFalse(c.is_marked())
        self.assertFalse(c.is_free())

        c.set_obstacle()
        self.assertFalse(c.is_unknown())
        self.assertFalse(c.is_object())
        self.assertTrue(c.is_obstacle())
        self.assertFalse(c.is_marked())
        self.assertFalse(c.is_free())
        self.assertFalse(c.is_blue())
        self.assertFalse(c.is_red())
        self.assertTrue(c.is_undef(), c.get_color_id())
        self.assertTrue(c.get_color() == c.UNDEF)

        c.set_blue()
        self.assertFalse(c.is_unknown())
        self.assertFalse(c.is_object())
        self.assertTrue(c.is_obstacle())
        self.assertFalse(c.is_marked())
        self.assertFalse(c.is_free())
        self.assertTrue(c.is_blue())
        self.assertFalse(c.is_red())
        self.assertFalse(c.is_undef())

        c.set_free()
        self.assertFalse(c.is_unknown())
        self.assertFalse(c.is_object())
        self.assertFalse(c.is_obstacle())
        self.assertFalse(c.is_marked())
        self.assertTrue(c.is_free())
        self.assertFalse(c.is_blue())
        self.assertFalse(c.is_red())

        c.set_object()
        self.assertFalse(c.is_unknown())
        self.assertTrue(c.is_object())
        self.assertFalse(c.is_obstacle())
        self.assertFalse(c.is_marked())
        self.assertFalse(c.is_free())
        self.assertTrue(c.is_blue())
        self.assertFalse(c.is_red())
        self.assertFalse(c.is_undef())

        c.set_mark()
        self.assertFalse(c.is_unknown())
        self.assertTrue(c.is_object())
        self.assertFalse(c.is_obstacle())
        self.assertTrue(c.is_marked())
        self.assertFalse(c.is_free())
        self.assertTrue(c.is_blue())
        self.assertFalse(c.is_red())
Exemplo n.º 3
0
    def test1(self):
        c = Cell()
        self.assertTrue(c.is_unknown())
        self.assertFalse(c.is_object())
        self.assertFalse(c.is_obstacle())
        self.assertFalse(c.is_marked())
        self.assertFalse(c.is_free())

        c.set_obstacle()
        self.assertFalse(c.is_unknown())
        self.assertFalse(c.is_object())
        self.assertTrue(c.is_obstacle())
        self.assertFalse(c.is_marked())
        self.assertFalse(c.is_free())
        self.assertFalse(c.is_blue())
        self.assertFalse(c.is_red())
        self.assertTrue(c.is_undef(), c.get_color_id())
        self.assertTrue(c.get_color() == c.UNDEF)

        c.set_blue()
        self.assertFalse(c.is_unknown())
        self.assertFalse(c.is_object())
        self.assertTrue(c.is_obstacle())
        self.assertFalse(c.is_marked())
        self.assertFalse(c.is_free())
        self.assertTrue(c.is_blue())
        self.assertFalse(c.is_red())
        self.assertFalse(c.is_undef())

        c.set_free()
        self.assertFalse(c.is_unknown())
        self.assertFalse(c.is_object())
        self.assertFalse(c.is_obstacle())
        self.assertFalse(c.is_marked())
        self.assertTrue(c.is_free())
        self.assertFalse(c.is_blue())
        self.assertFalse(c.is_red())

        c.set_object()
        self.assertFalse(c.is_unknown())
        self.assertTrue(c.is_object())
        self.assertFalse(c.is_obstacle())
        self.assertFalse(c.is_marked())
        self.assertFalse(c.is_free())
        self.assertTrue(c.is_blue())
        self.assertFalse(c.is_red())
        self.assertFalse(c.is_undef())

        c.set_mark()
        self.assertFalse(c.is_unknown())
        self.assertTrue(c.is_object())
        self.assertFalse(c.is_obstacle())
        self.assertTrue(c.is_marked())
        self.assertFalse(c.is_free())
        self.assertTrue(c.is_blue())
        self.assertFalse(c.is_red())
Exemplo n.º 4
0
def test_field1():
    c = Cell()
    c.set_free()
    field = [[c for x in xrange(15)] for x in xrange(15)]

    field[0][6] = Cell()
    field[0][6].set_unknown()
    field[0][7] = Cell()
    field[0][7].set_unknown()
    field[0][8] = Cell()
    field[0][8].set_unknown()
    field[2][6] = Cell()
    field[2][6].set_unknown()
    field[2][7] = Cell()
    field[2][7].set_unknown()
    field[2][8] = Cell()
    field[2][8].set_unknown()
    return field
Exemplo n.º 5
0
def test_field1():
    c = Cell()
    c.set_free()
    field = [[c for x in xrange(15)] for x in xrange(15)]

    field[0][6] = Cell()
    field[0][6].set_unknown()
    field[0][7] = Cell()
    field[0][7].set_unknown()
    field[0][8] = Cell()
    field[0][8].set_unknown()
    field[2][6] = Cell()
    field[2][6].set_unknown()
    field[2][7] = Cell()
    field[2][7].set_unknown()
    field[2][8] = Cell()
    field[2][8].set_unknown()
    return field
Exemplo n.º 6
0
    def test_region_merge(self):
        r = Region(1)
        r2 = Region(2)
        r_c1 = Cell()
        r_c1.set_free()
        r.cells.append(r_c1)
        r.cell_coords.append([0,0])
        r.min_x = 0
        r.min_y = 0
        r.max_x = 0
        r.max_y = 0


        r2_c1 = Cell()
        r2_c1.set_unknown()
        r2.cells.append(r2_c1)
        r2.cell_coords.append([1,1])
        r2.min_x = 0
        r2.min_y = 0
        r2.max_x = 1
        r2.max_y = 1

        r.merge_region(r2)

        # Check the size of cell lists
        self.assertTrue(len(r.cells) == 2)
        self.assertTrue(len(r.cell_coords) == 2)

        # Check the actual cells
        self.assertTrue(r2_c1 in r.cells)
        self.assertTrue(r_c1 in r.cells)

        self.assertTrue([0,0] in r.cell_coords)
        self.assertTrue([1,1] in r.cell_coords)

        self.assertEqual(r.min_x,0)
        self.assertEqual(r.min_y,0)
        self.assertEqual(r.max_x,1)
        self.assertEqual(r.max_y,1)
Exemplo n.º 7
0
    def test_region_merge(self):
        r = Region(1)
        r2 = Region(2)
        r_c1 = Cell()
        r_c1.set_free()
        r.cells.append(r_c1)
        r.cell_coords.append([0, 0])
        r.min_x = 0
        r.min_y = 0
        r.max_x = 0
        r.max_y = 0

        r2_c1 = Cell()
        r2_c1.set_unknown()
        r2.cells.append(r2_c1)
        r2.cell_coords.append([1, 1])
        r2.min_x = 0
        r2.min_y = 0
        r2.max_x = 1
        r2.max_y = 1

        r.merge_region(r2)

        # Check the size of cell lists
        self.assertTrue(len(r.cells) == 2)
        self.assertTrue(len(r.cell_coords) == 2)

        # Check the actual cells
        self.assertTrue(r2_c1 in r.cells)
        self.assertTrue(r_c1 in r.cells)

        self.assertTrue([0, 0] in r.cell_coords)
        self.assertTrue([1, 1] in r.cell_coords)

        self.assertEqual(r.min_x, 0)
        self.assertEqual(r.min_y, 0)
        self.assertEqual(r.max_x, 1)
        self.assertEqual(r.max_y, 1)
Exemplo n.º 8
0
 def make_free_map(self):
     c = Cell()
     c.set_free()
     test_field = [[deepcopy(c) for x in xrange(15)] for y in xrange(15)]
     return test_field
Exemplo n.º 9
0
 def init_field(self):
     ce = Cell()
     ce.set_free()
     self.field = [[ce for x in xrange(self.map_width)] for x in xrange(self.map_width)]
     self.segmented_field = [[self.SEGMENT_MAP_NOT_COLORED for x in xrange(self.map_width)] for x in
                             xrange(self.map_width)]
Exemplo n.º 10
0
 def make_free_map(self):
     c = Cell()
     c.set_free()
     test_field = [[deepcopy(c) for x in xrange(15)] for y in xrange(15)]
     return test_field