示例#1
0
 def test_make_qpainter(self) -> None:
     p1 = PPainter(-1, -1, -1, 1)
     p2 = PPainter(-1, -1, 1, 1)
     qp1 = QPainter((1, 8), p1)
     qp2 = QPainter((2, 8), p2)
     qpt1 = QPainterTemplate(('x', 'y'), p1)
     qpt2 = QPainterTemplate((('x', '+', 1), 'y'), p2)
     got = qpt2.make_qpainter(qpt1.make_env(qp1))  # type: ignore[arg-type]
     self.assertEqual(got, qp2)
示例#2
0
 def test_ppainter_multi_from_canvas(self) -> None:
     c = Canvas.from_data(two_cs)
     c.blank_all_but([(1, 8), (2, 8), (3, 8), (1, 7), (2, 7)])
     self.assertCountEqual(PPainter.multi_from_canvas(c, (1, 8)),
                           [P('OOOX')])
     self.assertCountEqual(PPainter.multi_from_canvas(c, (2, 8)),
                           [P('OOXO'), P('OOXX')])
     self.assertCountEqual(PPainter.multi_from_canvas(
         c, (1, 7)), [P('OXOO'), P('OXOX'),
                      P('OXXO'), P('OXXX')])
     self.assertCountEqual(PPainter.multi_from_canvas(c, (4, 4)), [])
示例#3
0
 def test_match_qpainter(self) -> None:
     p1 = PPainter(-1, -1, -1, +1)
     p2 = PPainter(-1, -1, +1, +1)
     p3 = PPainter(-1, -1, +1, -1)
     qp1 = QPainter((1, 8), p1)
     qp2 = QPainter((2, 8), p2)
     qp3 = QPainter((1, 8), p3)
     qpt1 = QPainterTemplate(('x', 'y'), p1)
     qpt2 = QPainterTemplate((('x', '+', 1), 'y'), p2)
     rp = RPainter((qpt1, qpt2))
     self.assertTrue(rp.is_match(qp1))
     self.assertTrue(rp.is_match(qp2))
     self.assertFalse(rp.is_match(qp3))
示例#4
0
 def test_qpainter(self) -> None:
     c = Canvas.empty()
     p = QPainter((1, 8), PPainter(1, 1, -1, -1))
     p.paint(c)
     self.assertEqual(c[1, 8], 1)
     self.assertEqual(c[2, 8], 1)
     self.assertEqual(c[1, 7], -1)
     self.assertEqual(c[2, 7], -1)
示例#5
0
    def test_ppainter(self) -> None:
        c = Canvas.empty()
        p = PPainter(1, -1, 1, -1)

        self.assertEqual(p.as_xos(), 'XOXO')
        self.assertCountEqual(p.values(), [1, -1, 1, -1])

        self.assertEqual(p.match_wt(c, (1, 8)), 4)

        p.paint(c, (1, 8))
        self.assertEqual(c[1, 8], 1)
        self.assertEqual(c[2, 8], -1)
        self.assertEqual(c[1, 7], 1)
        self.assertEqual(c[2, 7], -1)

        self.assertEqual(p.match_wt(c, (1, 8)), 20)
示例#6
0
    def test_make_qpainters(self) -> None:
        p1 = PPainter(-1, -1, -1, 1)
        p2 = PPainter(-1, -1, 1, 1)
        qp1 = QPainter((1, 8), p1)
        qp2 = QPainter((2, 8), p2)
        qpt1 = QPainterTemplate(('x', 'y'), p1)
        qpt2 = QPainterTemplate((('x', '+', 1), 'y'), p2)
        rp = RPainter((qpt1, qpt2))

        self.assertCountEqual(rp.make_qpainters(QPainter((1, 8), p1)),
                              [QPainter((2, 8), p2)])
        self.assertCountEqual(rp.make_qpainters(QPainter((2, 8), p1)),
                              [QPainter((3, 8), p2)])
        self.assertCountEqual(rp.make_qpainters(QPainter((7, 8), p1)), [])
        self.assertCountEqual(rp.make_qpainters(QPainter((8, 8), p1)), [])

        self.assertCountEqual(rp.make_qpainters(QPainter((1, 2), p1)),
                              [QPainter((2, 2), p2)])
        self.assertCountEqual(rp.make_qpainters(QPainter((1, 1), p1)), [])

        self.assertCountEqual(rp.make_qpainters(QPainter((2, 8), p2)),
                              [QPainter((1, 8), p1)])
        self.assertCountEqual(rp.make_qpainters(QPainter((1, 8), p2)), [])
示例#7
0
 def test_ppainter_from_canvas(self) -> None:
     c = Canvas.from_data(two_cs)
     p = PPainter.from_canvas(c, (1, 8))
     self.assertEqual(p, PPainter(-1, -1, -1, 1))