2
Test of basic dataseries behavior.
7
from numpy import arange, array, allclose
8
from enthought.chaco2.api import ArrayDataSource, PointDataSource
11
class ArrayDataTestCase(unittest.TestCase):
12
def test_basic_set_get(self):
14
sd = ArrayDataSource(myarray)
15
self.assertTrue(allclose(myarray, sd._data))
16
self.assert_(sd.value_dimension == "scalar")
19
def test_bounds(self):
22
sd = ArrayDataSource(myarray, sort_order="ascending")
23
bounds = sd.get_bounds()
24
self.assert_(bounds == (0,9))
27
myarray = arange(10)[::-1]
28
sd = ArrayDataSource(myarray, sort_order="descending")
29
bounds = sd.get_bounds()
30
self.assert_(bounds == (0,9))
33
myarray = array([12,3,0,9,2,18,3])
34
sd = ArrayDataSource(myarray, sort_order="none")
35
bounds = sd.get_bounds()
36
self.assert_(bounds == (0,18))
39
def test_data_size(self):
40
# We know that ScalarData always returns the exact length of its data
42
sd = ArrayDataSource(myarray)
43
self.assert_(len(myarray) == sd.get_size())
46
class PointDataTestCase(unittest.TestCase):
47
# Since PointData is mostly the same as ScalarData, the key things to
48
# test are functionality that use _compute_bounds() and reverse_map().
49
def create_array(self):
50
return array(zip(range(10), range(0, 100, 10)))
52
def test_basic_set_get(self):
53
myarray = self.create_array()
54
pd = PointDataSource(myarray)
55
self.assertTrue(allclose(myarray,pd._data))
56
self.assert_(pd.value_dimension == "point")
59
def test_bounds(self):
60
myarray = self.create_array()
61
pd = PointDataSource(myarray)
62
self.assertEqual(pd.get_bounds(),((0,0), (9,90)))
65
if __name__ == '__main__':