Ejemplo n.º 1
0
    def test_0506_action_acquerir_rejeter(self):
        from elements import decors
        from elements import objet
        from elements import element

        r = robot.Robot((4, 4, 4))
        w = decors.Wall((1,1,1),'W')
        o = objet.Key((2,2,2),'K')
        e = decors.Empty((3,3,3),'E')

        self.assertFalse(r.hasObject(objet.Key))

        self.assertRaises(element.ActionError, r.action_aquerir, w,'W')
        self.assertRaises(element.ActionError, r.action_aquerir, w,'K')
        elem = r.action_aquerir(o,'K')
        self.assertEqual(elem,decors.Empty)
        self.assertEqual(o.coordinate,None)

        self.assertTrue(r.hasObject(objet.Key))
        obj = r.useObject(objet.Key)
        self.assertTrue(isinstance(obj,objet.Key))
        self.assertEqual(obj,o)

        self.assertRaises(element.ActionError, r.action_rejeter, decors.Wall,'K')
        self.assertRaises(element.ActionError, r.action_rejeter, decors.Empty,'W')
        elem=r.action_rejeter(e,'K')
        self.assertTrue(isinstance(elem, objet.Objet))
        self.assertTrue(isinstance(elem, objet.Key))
        self.assertEqual(elem.coordinate,e.coordinate)
        self.assertNotEqual(elem.coordinate,r.coordinate)

        self.assertFalse(r.hasObject(objet.Key))
Ejemplo n.º 2
0
    def test_0507_actionObj(self):
        from elements import decors
        from elements import objet
        from elements import element

        r = robot.Robot((4, 4, 4))
        w = decors.Wall((1, 1, 1), 'W')
        o = objet.Key((2, 2, 2), 'K')
        e = decors.Empty((3, 3, 3), 'E')

        self.assertRaises(element.ActionError, r.actionObj, 'T', w, 'K')
        self.assertRaises(element.ActionError, r.actionObj, 'P', w, 'K')
        self.assertRaises(element.ActionError, r.actionObj, 'A', w, 'K')
        elemType = r.actionObj('A', o, 'K')
        self.assertTrue(elemType, decors.Empty)
Ejemplo n.º 3
0
    def test_0305_wall(self):
        e = decors.Wall((1, 1, 1), 'W')

        self.assertTrue(isinstance(e, decors.Wall))
        self.assertTrue(isinstance(e, decors.Decors))

        self.assertEqual(e.name, 'wall')
        self.assertEqual(e.symbol, 'W')
        self.assertFalse(e.reachable)

        self.assertEqual("", e.reach())
        self.assertFalse(e.actionNeedObject(''))

        coords = e.getCoordinateAround(1)
        self.assertEqual(9, len(coords))

        self.assertEqual(e.action_percer(), decors.OpenDoor)
        e.robustness = 2
        elem = e.action_percer()
        self.assertTrue(isinstance(elem, decors.Wall))
        elem = e.action_percer()
        self.assertEqual(elem, decors.OpenDoor)
Ejemplo n.º 4
0
    def test_0508_actionDir(self):
        from elements import decors
        from elements import objet
        from elements import element

        r = robot.Robot((4, 4, 4))
        w = decors.Wall((1, 1, 1), 'W')
        o = objet.Key((2, 2, 2), 'K')
        e = decors.Empty((3, 3, 3), 'E')
        d = decors.OpenDoor((5,5,5), '.')

        self.assertRaises(element.ActionError, r.actionDir, 'T', d)
        self.assertRaises(element.ActionError, r.actionDir, 'A', d)

        d1 = r.actionDir('P',w)
        self.assertEqual(d1,decors.OpenDoor)
        d1 = decors.OpenDoor((6,6,6),'.')
        d2 = r.actionDir('F',d1)
        self.assertEqual(d2,decors.CloseDoor)
        d2 = decors.CloseDoor((7,7,7),'.')
        self.assertRaises(element.ActionError, r.actionDir, 'L', d2)
        r.actionObj('A', o, 'K')
        d3 = r.actionDir('L',d2)
        self.assertEqual(d3, decors.LockDoor)
Ejemplo n.º 5
0
    def test_0309_door(self):
        from elements import objet
        e = decors.Door((1, 1, 1), 'D')

        self.assertTrue(isinstance(e, decors.Door))
        self.assertTrue(isinstance(e, decors.Decors))

        self.assertEqual(e.name, 'door')
        self.assertEqual(e.symbol, '.')
        self.assertTrue(e.reachable)
        self.assertTrue(e.isOpen)
        self.assertFalse(e.isLock)

        self.assertEqual("", e.reach())
        self.assertFalse(e.actionNeedObject(''))
        self.assertEqual(objet.Key, e.actionNeedObject('locker'))
        self.assertEqual(objet.Key, e.actionNeedObject('delocker'))

        coords = e.getCoordinateAround(1)
        self.assertEqual(9, len(coords))

        self.assertRaises(element.ActionError, e.action_ouvrir)
        self.assertRaises(element.ActionError, e.action_delocker)
        self.assertRaises(element.ActionError, e.action_locker)

        e._Door__close()
        self.assertEqual(e.symbol, '/')
        self.assertFalse(e.reachable)
        self.assertFalse(e.isOpen)
        self.assertFalse(e.isLock)

        self.assertRaises(element.ActionError, e.action_fermer)
        self.assertRaises(element.ActionError, e.action_delocker)
        self.assertRaises(element.ActionError, e.action_locker)

        e._Door__lock()
        self.assertEqual(e.symbol, '+')
        self.assertFalse(e.reachable)
        self.assertFalse(e.isOpen)
        self.assertTrue(e.isLock)

        self.assertRaises(element.ActionError, e.action_ouvrir)
        self.assertRaises(element.ActionError, e.action_delocker)
        self.assertRaises(element.ActionError, e.action_locker)

        e._Door__open()
        self.assertEqual(e.symbol, '.')
        self.assertTrue(e.reachable)
        self.assertTrue(e.isOpen)
        self.assertFalse(e.isLock)

        self.assertFalse(e.actionNeedObject('murer'))
        self.assertEqual(objet.Key, e.actionNeedObject('locker'))
        self.assertEqual(objet.Key, e.actionNeedObject('delocker'))

        elem = e.action_fermer()
        e = elem((1, 1, 1), 'D')
        self.assertEqual(elem, decors.CloseDoor)
        elem = e.action_ouvrir()
        e = elem((1, 1, 1), 'D')
        self.assertEqual(elem, decors.OpenDoor)

        w = decors.Wall((1, 1, 1), 'W')
        self.assertRaises(element.ActionError, e.action_locker, decors.Wall)
        self.assertRaises(element.ActionError, e.action_locker, objet.Key)
        self.assertRaises(element.ActionError, e.action_locker, w)
        k = objet.Key((1, 1, 1), 'K')
        elem = e.action_locker(k)
        e = elem((1, 1, 1), 'D')
        self.assertEqual(elem, decors.LockDoor)

        self.assertRaises(element.ActionError, e.action_delocker, decors.Wall)
        self.assertRaises(element.ActionError, e.action_delocker, objet.Key)
        self.assertRaises(element.ActionError, e.action_delocker, w)
        elem = e.action_delocker(k)
        e = elem((1, 1, 1), 'D')
        self.assertEqual(elem, decors.OpenDoor)

        self.assertEqual(e.action_percer(), decors.OpenDoor)
        e.robustness = 2
        elem = e.action_percer()
        self.assertTrue(isinstance(elem, decors.Door))
        elem = e.action_percer()
        e = elem((1, 1, 1), 'D')
        self.assertEqual(e.action_percer(), decors.OpenDoor)