def test_格子点集合に含まれる格子点の数を取得できる(self):
        p00 = GridPoint(0, 0)
        p11 = GridPoint(1, 1)
        p22 = GridPoint(2, 2)
        p33 = GridPoint(3, 3)

        self.assertEqual(4, FourGridPoints(p00, p11, p22, p33).count())
    def test_格子点が同じ座標を持つかどうか判定できる(self):
        with self.subTest("(4,7) と (4,7) は 同じ座標"):
            self.assertTrue(
                GridPoint(4, 7).has_same_coordinates_with(GridPoint(4, 7)))

        with self.subTest("(4,7) と (3,8) は 違う座標"):
            self.assertFalse(
                GridPoint(4, 7).has_same_coordinates_with(GridPoint(3, 8)))
Exemplo n.º 3
0
    def test_格子点集合が指定した格子点を含むか判定できる(self):
        p00 = GridPoint(0, 0)
        p11 = GridPoint(1, 1)
        p22 = GridPoint(2, 2)

        with self.subTest("含む"):
            self.assertTrue(TwoGridPoints(p00, p11).contains(p11))

        with self.subTest("含まない"):
            self.assertFalse(TwoGridPoints(p00, p11).contains(p22))
Exemplo n.º 4
0
    def test_格子点集合の連結してるか判定できる(self):
        p10 = GridPoint(1, 0)
        p00 = GridPoint(0, 0)
        p11 = GridPoint(1, 1)

        with self.subTest("連結している場合"):
            self.assertTrue(TwoGridPoints(p00, p10).is_connected())

        with self.subTest("連結していない場合"):
            self.assertFalse(TwoGridPoints(p00, p11).is_connected())
    def test_格子点集合が指定した格子点を含むか判定できる(self):
        p00 = GridPoint(0, 0)
        p11 = GridPoint(1, 1)
        p22 = GridPoint(2, 2)
        p33 = GridPoint(3, 3)
        p44 = GridPoint(4, 4)

        with self.subTest("含む"):
            self.assertTrue(FourGridPoints(p00, p11, p22, p33).contains(p33))

        with self.subTest("含まない"):
            self.assertFalse(FourGridPoints(p00, p11, p22, p33).contains(p44))
    def test_格子点が隣り合っているかどうか判定できる(self):
        p00 = GridPoint(0, 0)

        with self.subTest("(1, 0) は (0, 0) と 隣り合う"):
            self.assertTrue(GridPoint(1, 0).is_neighbor_of(p00))

        with self.subTest("(-1, 0) は (0, 0) と 隣り合う"):
            self.assertTrue(GridPoint(-1, 0).is_neighbor_of(p00))

        with self.subTest("(0, 1) は (0, 0) と 隣り合う"):
            self.assertTrue(GridPoint(0, 1).is_neighbor_of(p00))

        with self.subTest("(0, -1) は (0, 0) と 隣り合う"):
            self.assertTrue(GridPoint(0, -1).is_neighbor_of(p00))
    def test_格子点集合の連結している場合(self):
        p00 = GridPoint(0, 0)
        p01 = GridPoint(0, 1)
        p02 = GridPoint(0, 2)
        p10 = GridPoint(1, 0)
        p11 = GridPoint(1, 1)
        p20 = GridPoint(2, 0)
        p22 = GridPoint(2, 2)

        with self.subTest("連結である_左右に並ぶ"):
            self.assertTrue(ThreeGridPoints(p00, p10, p20).is_connected())

        with self.subTest("連結である_上下に並ぶ"):
            self.assertTrue(ThreeGridPoints(p00, p01, p02).is_connected())

        with self.subTest("連結である_L字に並ぶ"):
            self.assertTrue(ThreeGridPoints(p00, p01, p11).is_connected())

        with self.subTest("連結でない_どの格子点も隣り合っていない"):
            self.assertFalse(ThreeGridPoints(p00, p11, p22).is_connected())

        with self.subTest("連結でない_3つの格子点のうち、2点だけ隣り合う"):
            self.assertFalse(ThreeGridPoints(p00, p10, p22).is_connected())
Exemplo n.º 8
0
    def test_格子点集合に含まれる格子点の数を取得できる(self):
        p00 = GridPoint(0, 0)
        p11 = GridPoint(1, 1)

        self.assertEqual(2, TwoGridPoints(p00, p11).count())
    def test_座標の値は整数であること(self):
        with self.subTest("x=1.5 -> Error"):
            self.assertRaises(TypeError, lambda: GridPoint(1.5, 7))

        with self.subTest("y=1.5 -> Error"):
            self.assertRaises(TypeError, lambda: GridPoint(7, 1.5))
Exemplo n.º 10
0
 def test_格子点の文字列表記(self):
     self.assertEqual("(4,7)", str(GridPoint(4, 7)))
    def test_格子点集合に含まれる格子点の数を取得できる(self):
        p00 = GridPoint(0, 0)
        p11 = GridPoint(1, 1)
        p22 = GridPoint(2, 2)

        self.assertEqual(3, ThreeGridPoints(p00, p11, p22).count())
    def test_格子点集合の連結かどうかを判定できる(self):
        p01 = GridPoint(0, 1)
        p02 = GridPoint(0, 2)
        p03 = GridPoint(0, 3)
        p30 = GridPoint(3, 0)
        p20 = GridPoint(2, 0)
        p21 = GridPoint(2, 1)
        p00 = GridPoint(0, 0)
        p10 = GridPoint(1, 0)
        p11 = GridPoint(1, 1)
        p22 = GridPoint(2, 2)
        p33 = GridPoint(3, 3)

        with self.subTest("連結である_横に一直線"):
            self.assertTrue(FourGridPoints(p00, p01, p02, p03).is_connected())

        with self.subTest("連結である_縦に一直線"):
            self.assertTrue(FourGridPoints(p00, p10, p20, p30).is_connected())

        with self.subTest("連結である_L字"):
            self.assertTrue(FourGridPoints(p00, p10, p20, p21).is_connected())

        with self.subTest("連結である_T字"):
            self.assertTrue(FourGridPoints(p00, p10, p11, p20).is_connected())

        with self.subTest("連結でない_どの格子点も隣り合っていない"):
            self.assertFalse(FourGridPoints(p00, p11, p22, p33).is_connected())

        with self.subTest("連結でない_2点が隣り合う"):
            self.assertFalse(FourGridPoints(p00, p10, p22, p33).is_connected())

        with self.subTest("連結でない_3点が隣り合う"):
            self.assertFalse(FourGridPoints(p00, p10, p11, p30).is_connected())
Exemplo n.º 13
0
def test_隣り合っている格子点の判定ができること(this, other, result):
    this_grid = GridPoint(this[0], this[1])
    other_grid = GridPoint(other[0], other[1])
    assert this_grid.is_neighbor(other_grid) == result
Exemplo n.º 14
0
 def test_格子点x_yの値は更新不可である(self):
     grid_point = GridPoint(0, 0)
     with pytest.raises(AttributeError):
         grid_point.x = 1
     with pytest.raises(AttributeError):
         grid_point.y = 1