-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_crossTraining.py
61 lines (52 loc) · 1.8 KB
/
test_crossTraining.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import unittest
from crossTraining import CrossTraining
from direct.showbase.MessengerGlobal import messenger
from panda3d.core import loadPrcFileData
from direct.task.TaskManagerGlobal import taskMgr
class CrossTrainingTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
loadPrcFileData("", "window-type offscreen")
#print 'about to load world'
cls.cb = CrossTraining()
def setUp(self):
# re-initialize variables before each test
self.cb.reset_variables()
#self.config = {}
#execfile('testing_config.py', self.config)
def test_move_joystick_right(self):
"""
test that gets reward for pushing the joystick
"""
messenger.send('x_axis', [1])
self.assertTrue(self.cb.reward_on)
def test_hold_joystick_right(self):
"""
test that if required to hold for reward, actually requires hold
"""
self.cb.inc_js_goal()
messenger.send('x_axis', [1])
self.assertFalse(self.cb.reward_on)
messenger.send('x_axis', [1])
self.assertTrue(self.cb.reward_on)
def test_hold_release_joystick_no_reward(self):
"""
test that if we are required to hold, but don't hold long enough,
and release instead, no reward.
"""
# make goal longer
self.cb.inc_js_goal()
messenger.send('x_axis', [1])
self.assertFalse(self.cb.reward_on)
messenger.send('x_axis', [0])
self.assertFalse(self.cb.reward_on)
messenger.send('x_axis', [1])
self.assertFalse(self.cb.reward_on)
@classmethod
def tearDownClass(cls):
taskMgr.remove('Joystick Polling')
cls.cb.close()
del cls.cb
print 'tore down'
if __name__ == "__main__":
unittest.main(verbosity=2)