forked from codedragon/calibrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_positions.py
85 lines (78 loc) · 3.58 KB
/
test_positions.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from __future__ import division
import unittest
from positions import Positions
from positions import visual_angle
class TestPositions(unittest.TestCase):
def setUp(self):
self.config = {}
execfile('config.py', self.config)
self.depth = 0
def test_non_random_list_pops(self):
# make sure all positions are yielded.
# number of positions
total = self.config['X_POINTS'] * self.config['Y_POINTS']
count = 0
pos = Positions().get_position(self.depth)
# generator object, will output until done
for i in pos:
#print i
count += 1
#print self.pos.get_position(self.depth)
#self.pos.get_position(self.depth)
# Try to get another, should not work
self.assertRaises(StopIteration, next, pos)
self.assertEqual(count, total)
def test_random_list_pops(self):
# make sure all positions are yielded.
# number of positions
pos = Positions().get_position(self.depth, True)
total = self.config['X_POINTS'] * self.config['Y_POINTS'] * self.config['POINT_REPEAT']
count = 0
#for i in range(self.config['X_LIMITS'] * self.config['X_LIMITS']):
for i in pos:
#print i
count += 1
#print self.pos.get_position(self.depth)
#self.pos.get_position(self.depth)
# Try to get another, should not work
self.assertRaises(StopIteration, next, pos)
self.assertEqual(count, total)
def test_visual_angle(self):
# visual angle returns deg_per_pix,
# check with projector parameters
# screen_size = [1337, 991]
# resolution = [1024, 768]
screen_size = [1467, 902]
resolution = [1280, 800]
view_dist = 1219
deg_per_pix = visual_angle(screen_size, resolution, view_dist)
print deg_per_pix
print 1/deg_per_pix[0]
print 1/deg_per_pix[1]
# used Fine's tutorial in Matlab to come up with the
# numbers for testing
#self.assertAlmostEqual(deg_per_pix[0], 0.061369, 6)
#self.assertAlmostEqual(deg_per_pix[1], 0.06065, 6)
self.assertAlmostEqual(deg_per_pix[0], 0.0539, 4)
self.assertAlmostEqual(deg_per_pix[1], 0.0530, 4)
def test_visual_angle_positions(self):
# make sure furthest out positions are plotted are at the correct visual angle
# for this test, just test whatever is in the config file, and make sure it
# is following whatever is there, regardless of if that is really correct (more
# likely it is me sitting a foot or two away from the laptop, but not going to change
# the view_dist and screen size since it doesn't really matter...
max_x = self.config['MAX_DEGREES_X']
max_y = self.config['MAX_DEGREES_Y']
deg_per_pixel = visual_angle(self.config['SCREEN'], self.config['WIN_RES'], self.config['VIEW_DIST'])
#
# Key 9 should get you the max visual degrees for both x and y. Of course, it will
# really be farther than the max visual angle, since we are maximizing both x and y,
# but as long as the cardinal directions are the right visual angle, we understand the
# corners are really further out, and will take this under consideration
pos = Positions(self.config)
pos_9 = pos.get_key_position(self.depth, key=9)
#print pos_9
self.assertAlmostEqual(pos_9[0], max_x / deg_per_pixel[0], 4)
self.assertAlmostEqual(pos_9[2], max_y / deg_per_pixel[1], 4)
if __name__ == "__main__":
unittest.main(verbosity=2)