Esempio n. 1
0
 def test_unparseable(self):
     with self.assertRaises(ValueError) as e:
         L.WholeMove('xyzzy')
     self.assertEqual(str(e.exception), "text did not parse as a move")
     with self.assertRaises(ValueError) as e:
         L.WholeMove('pass; xyzzy')
     self.assertEqual(str(e.exception), "text did not parse as a move")
Esempio n. 2
0
 def test_nonmutating_apply_exceptions(self):
     s = L.GameState('Foo (0,b3r1) g3-\n' + 'Bar(1,b3y2) -r1y2')
     with self.assertRaises(TypeError) as e:
         s.copyApply()
     self.assertEqual(str(e.exception), "function takes exactly 2 arguments (0 given)")
     with self.assertRaises(TypeError) as e:
         s.copyApply(0, 'pass')
     self.assertEqual(str(e.exception), "argument 2 must be libannotate.WholeMove, not str")
     with self.assertRaises(TypeError) as e:
         s.copyApply(L.WholeMove('pass'), 0)
     self.assertEqual(str(e.exception), "an integer is required (got type libannotate.WholeMove)")
     with self.assertRaises(ValueError) as e:
         s.copyApply(2, L.WholeMove('pass'))
     self.assertEqual(str(e.exception), "attacker must be 0 or 1")
Esempio n. 3
0
 def test_nonmutating_apply(self):
     s1 = L.GameState('Foo (0,b3r1) g3-\n' + 'Bar(1,b3y2) -r1y2')
     self.assertEqual(s1.toString(), 'Foo (0, r1b3) g3-\nBar (1, y2b3) -r1y2\n')
     m = L.WholeMove('build g1')
     s2 = s1.copyApply(0, m)
     self.assertEqual(s1.toString(), 'Foo (0, r1b3) g3-\nBar (1, y2b3) -r1y2\n')
     self.assertEqual(s2.toString(), 'Foo (0, r1b3) g1g3-\nBar (1, y2b3) -r1y2\n')
Esempio n. 4
0
 def test_in_universe_exceptions(self):
     s = L.GameState('Foo (0,b3r1) g3-\n' + 'Bar(1,b3y2) -g1y2')
     with self.assertRaises(ValueError) as e:
         s.apply(0, L.WholeMove('sac g3 at Foo'))
     self.assertEqual(str(e.exception), "The move as parsed was disallowed by the rule against self-destruction.")
     with self.assertRaises(ValueError) as e:
         s.apply(0, L.WholeMove('build y1 at Nonexistent'))
     self.assertEqual(str(e.exception), "The move as parsed referred to a nonexistent star system.")
     with self.assertRaises(ValueError) as e:
         s.apply(1, L.WholeMove('move g1 from Bar to Foo (b1)'))
     self.assertEqual(str(e.exception), "The move as parsed tried to create a new star system with the same name as an existing one.")
     with self.assertRaises(ValueError) as e:
         s.apply(1, L.WholeMove('build at Bar'))
     self.assertEqual(str(e.exception), "The move as parsed was incomplete or ambiguous.")
     with self.assertRaises(ValueError) as e:
         s.apply(0, L.WholeMove('build y1 at Foo'))
     self.assertEqual(str(e.exception), "The move as parsed was disallowed by the rules.")
Esempio n. 5
0
 def test_gameIsOver(self):
     s = L.GameState("""
         Player1 (0, g3y2) g3-
         Blueberry (b3) y1y1g1-
         Timbuktu (g2) -r1g1
         Player2 (1, y2b1) r3-y2y1
     """)
     m = L.WholeMove('move y1 from Blueberry to Player2; catastrophe yellow at Player2')
     self.assertEqual(s.gameIsOver(), False)
     s.apply(0, m)
     self.assertEqual(s.gameIsOver(), True)
Esempio n. 6
0
 def test_missing_pieces(self):
     m = L.WholeMove('catastrophe green at Widget; sac y3; move y1r2 from Alpha to Beta')
     self.assertEqual(m.toString(), 'catastrophe green at Widget; sacrifice y3; move y1 from Alpha to Beta; move r2 from Alpha to Beta')
     with self.assertRaises(ValueError) as e:
         m.toSDGString()
     self.assertEqual(str(e.exception), "move with missing information cannot be stringified into SDG format")
Esempio n. 7
0
 def test_discover(self):
     m = L.WholeMove('move y1 from Alpha to Beta (b2)')
     self.assertEqual(m.toString(), 'move y1 from Alpha to Beta (b2)')
     self.assertEqual(m.toSDGString(), 'discover y1 Alpha b2 Beta')
     self.assertEqual(repr(m), "libannotate.WholeMove('move y1 from Alpha to Beta (b2)')")
Esempio n. 8
0
 def test_unused_sacrifice_actions(self):
     m = L.WholeMove('sac y3 at Alpha; move y1 from Alpha to Beta; catastrophe yellow at Beta')
     self.assertEqual(str(m), 'sacrifice y3 at Alpha; move y1 from Alpha to Beta; catastrophe yellow at Beta')
     self.assertEqual(m.toString(), 'sacrifice y3 at Alpha; move y1 from Alpha to Beta; catastrophe yellow at Beta')
     self.assertEqual(m.toSDGString(), 'sacrifice y3 Alpha; move y1 Alpha Beta; catastrophe Beta yellow; pass; pass')
     self.assertEqual(repr(m), "libannotate.WholeMove('sacrifice y3 at Alpha; move y1 from Alpha to Beta; catastrophe yellow at Beta')")
Esempio n. 9
0
 def test_catastrophe(self):
     m = L.WholeMove('move y1 from Alpha to Beta; catastrophe yellow at Beta')
     self.assertEqual(str(m), 'move y1 from Alpha to Beta; catastrophe yellow at Beta')
     self.assertEqual(m.toString(), 'move y1 from Alpha to Beta; catastrophe yellow at Beta')
     self.assertEqual(m.toSDGString(), 'move y1 Alpha Beta; catastrophe Beta yellow')
     self.assertEqual(repr(m), "libannotate.WholeMove('move y1 from Alpha to Beta; catastrophe yellow at Beta')")
Esempio n. 10
0
 def test_trivial(self):
     m = L.WholeMove('pass')
     self.assertEqual(str(m), 'pass')
     self.assertEqual(m.toString(), 'pass')
     self.assertEqual(m.toSDGString(), 'pass')
     self.assertEqual(repr(m), "libannotate.WholeMove('pass')")
Esempio n. 11
0
 def test_lack_of_default_constructor(self):
     with self.assertRaises(TypeError) as e:
         L.WholeMove()
     self.assertEqual(str(e.exception), "function takes exactly 1 argument (0 given)")
Esempio n. 12
0
 def test_mutating_apply(self):
     s = L.GameState('Foo (0,b3r1) g3-\n' + 'Bar(1,b3y2) -r1y2')
     m = L.WholeMove('build g1')
     result = s.apply(0, m)
     self.assertEqual(result, None)
     self.assertEqual(s.toString(), 'Foo (0, r1b3) g1g3-\nBar (1, y2b3) -r1y2\n')