示例#1
0
 def test_allows_rest_of_arm_line(self):
     p = self.pclass()
     feed_input(p, 0, 2, "O\n")
     feed_input(p, 1, 0, "z-|-")
     p.test(main.CurrentChar(1, 4, "a", core.M_OCCUPIED))
     p.test(main.CurrentChar(1, 5, "q", core.M_OCCUPIED))
     p.test(main.CurrentChar(1, 6, "\n", core.M_OCCUPIED))
示例#2
0
 def do_render(self, row, col, char):
     p = self.pclass()
     p.test(main.CurrentChar(row, col, char, core.M_NONE))
     try:
         p.test(main.CurrentChar(row, col + 1, "b", core.M_NONE))
     except StopIteration:
         pass
     return p.render()
示例#3
0
 def test_expects_left_leg_forwardslash(self):
     p = self.pclass()
     feed_input(p, 0, 3, "O\n")
     feed_input(p, 1, 0, "  -|-\n")
     feed_input(p, 2, 0, "ab")
     with self.assertRaises(core.PatternRejected):
         p.test(main.CurrentChar(2, 2, "g", core.M_NONE))
示例#4
0
 def test_accepts_stick_man(self):
     p = self.pclass()
     feed_input(p, 0, 1, "O  \n")
     feed_input(p, 1, 0, "-|- \n")
     feed_input(p, 2, 0, "/ \\")
     with self.assertRaises(StopIteration):
         p.test(main.CurrentChar(2, 3, " ", core.M_NONE))
示例#5
0
 def test_expects_space_between_legs_unoccupied(self):
     p = self.pclass()
     feed_input(p, 0, 3, "O\n")
     feed_input(p, 1, 0, "  -|-\n")
     feed_input(p, 2, 0, "  /")
     with self.assertRaises(core.PatternRejected):
         p.test(main.CurrentChar(2, 3, " ", core.M_OCCUPIED))
示例#6
0
 def test_expects_right_leg_backslash_unoccupied(self):
     p = self.pclass()
     feed_input(p, 0, 3, "O\n")
     feed_input(p, 1, 0, "  -|-\n")
     feed_input(p, 2, 0, "  / ")
     with self.assertRaises(core.PatternRejected):
         p.test(main.CurrentChar(2, 4, "\\", core.M_OCCUPIED))
示例#7
0
 def do_render(self, x, y):
     p = self.pclass()
     feed_input(p, y, x, "O\n")
     feed_input(p, y + 1, x - 1, "-|-\n")
     feed_input(p, y + 2, x - 1, "/ \\")
     try:
         p.test(main.CurrentChar(y + 2, x + 2, " ", core.M_NONE))
     except StopIteration:
         pass
     return p.render()
示例#8
0
 def test_sets_correct_meta_flags(self):
     p = self.pclass()
     input = (
         (
             3,
             "O   \n",
         ),
         (
             0,
             "  -|-  \n",
         ),
         (
             0,
             "  / \\",
         ),
     )
     o = core.M_OCCUPIED
     n = core.M_NONE
     meta = (
         (
             o,
             n,
             n,
             n,
             n,
         ),
         (
             n,
             n,
             o,
             o,
             o,
             n,
             n,
             n,
         ),
         (
             n,
             n,
             o,
             o,
             o,
         ),
     )
     for j, (startcol, line) in enumerate(input):
         for i, char in enumerate(line):
             m = p.test(main.CurrentChar(j, startcol + i, char,
                                         core.M_NONE))
             self.assertEquals(meta[j][i], m)
示例#9
0
 def test_accepts_other_meta(self):
     p = self.pclass()
     p.test(main.CurrentChar(2, 3, "a", core.M_BOX_START_E))
示例#10
0
 def test_rejects_if_occupied(self):
     p = self.pclass()
     with self.assertRaises(core.PatternRejected):
         p.test(main.CurrentChar(2, 2, "a", core.M_OCCUPIED))
示例#11
0
 def test_rejects_if_whitespace(self):
     p = self.pclass()
     with self.assertRaises(core.PatternRejected):
         p.test(main.CurrentChar(2, 2, " ", core.M_NONE))
示例#12
0
 def test_accepts_only_single_non_whitespace(self):
     p = self.pclass()
     p.test(main.CurrentChar(3, 2, "a", core.M_NONE))
     with self.assertRaises(StopIteration):
         p.test(main.CurrentChar(3, 3, "a", core.M_NONE))
示例#13
0
 def test_expects_left_arm_hyphen(self):
     p = self.pclass()
     feed_input(p, 0, 2, "O\n")
     feed_input(p, 1, 0, "z")
     with self.assertRaises(core.PatternRejected):
         p.test(main.CurrentChar(1, 1, "?", core.M_NONE))
示例#14
0
 def test_expects_head(self):
     p = self.pclass()
     with self.assertRaises(core.PatternRejected):
         p.test(main.CurrentChar(0, 1, " ", core.M_NONE))
示例#15
0
 def test_expects_head_unoccupied(self):
     p = self.pclass()
     with self.assertRaises(core.PatternRejected):
         p.test(main.CurrentChar(0, 1, "O", core.M_OCCUPIED))
示例#16
0
 def test_allows_zero_as_head(self):
     p = self.pclass()
     p.test(main.CurrentChar(0, 1, "0", core.M_NONE))
示例#17
0
 def test_allows_start_of_leg_line(self):
     p = self.pclass()
     feed_input(p, 0, 3, "O\n")
     feed_input(p, 1, 0, "  -|-\n")
     p.test(main.CurrentChar(2, 0, "y", core.M_OCCUPIED))
     p.test(main.CurrentChar(2, 1, "&", core.M_OCCUPIED))
示例#18
0
 def test_expects_right_arm_hyphen_unoccupied(self):
     p = self.pclass()
     feed_input(p, 0, 2, "O\n")
     feed_input(p, 1, 0, "z-|")
     with self.assertRaises(core.PatternRejected):
         p.test(main.CurrentChar(1, 3, "-", core.M_OCCUPIED))
示例#19
0
 def test_expects_body_pipe_unoccupied(self):
     p = self.pclass()
     feed_input(p, 0, 2, "O\n")
     feed_input(p, 1, 0, "z-")
     with self.assertRaises(core.PatternRejected):
         p.test(main.CurrentChar(1, 2, "|", core.M_OCCUPIED))
示例#20
0
 def test_expects_body_pipe(self):
     p = self.pclass()
     feed_input(p, 0, 2, "O\n")
     feed_input(p, 1, 0, "z-")
     with self.assertRaises(core.PatternRejected):
         p.test(main.CurrentChar(1, 2, "X", core.M_NONE))
示例#21
0
 def test_rejects_if_start_of_input(self):
     p = self.pclass()
     with self.assertRaises(core.PatternRejected):
         p.test(main.CurrentChar(-1, 0, core.START_OF_INPUT, core.M_NONE))
示例#22
0
 def test_allows_rest_of_head_line(self):
     p = self.pclass()
     feed_input(p, 0, 1, "O")
     p.test(main.CurrentChar(0, 2, "a", core.M_OCCUPIED))
     p.test(main.CurrentChar(0, 3, "b", core.M_OCCUPIED))
     p.test(main.CurrentChar(0, 4, "\n", core.M_OCCUPIED))
示例#23
0
 def test_rejects_if_end_of_input(self):
     p = self.pclass()
     with self.assertRaises(core.PatternRejected):
         p.test(main.CurrentChar(1, 2, core.END_OF_INPUT, core.M_NONE))
示例#24
0
 def test_allows_start_of_arms_line(self):
     p = self.pclass()
     feed_input(p, 0, 3, "Oab\n")
     p.test(main.CurrentChar(1, 0, "c", core.M_OCCUPIED))
     p.test(main.CurrentChar(1, 1, "d", core.M_OCCUPIED))
示例#25
0
def feed_input(pattern, row, col, characters):
    for char in characters:
        pattern.test(main.CurrentChar(row, col, char, core.M_NONE))
        col += 1
示例#26
0
 def test_allows_lowercase_oh_as_head(self):
     p = self.pclass()
     p.test(main.CurrentChar(0, 1, "o", core.M_NONE))