~ubuntu-branches/ubuntu/precise/python-chaco/precise

« back to all changes in this revision

Viewing changes to enthought/chaco2/tests/arraydatasource_test_case.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2008-12-29 02:34:05 UTC
  • Revision ID: james.westby@ubuntu.com-20081229023405-x7i4kp9mdxzmdnvu
Tags: upstream-3.0.1
ImportĀ upstreamĀ versionĀ 3.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
Test of basic dataseries behavior.
 
3
"""
 
4
 
 
5
import unittest
 
6
 
 
7
from numpy import arange, array, allclose
 
8
from enthought.chaco2.api import ArrayDataSource, PointDataSource
 
9
 
 
10
 
 
11
class ArrayDataTestCase(unittest.TestCase):
 
12
    def test_basic_set_get(self):
 
13
        myarray = arange(10)
 
14
        sd = ArrayDataSource(myarray)
 
15
        self.assertTrue(allclose(myarray, sd._data))
 
16
        self.assert_(sd.value_dimension == "scalar")
 
17
        return
 
18
 
 
19
    def test_bounds(self):
 
20
        # ascending
 
21
        myarray = arange(10)
 
22
        sd = ArrayDataSource(myarray, sort_order="ascending")
 
23
        bounds = sd.get_bounds()
 
24
        self.assert_(bounds == (0,9))
 
25
        
 
26
        # descending
 
27
        myarray = arange(10)[::-1]
 
28
        sd = ArrayDataSource(myarray, sort_order="descending")
 
29
        bounds = sd.get_bounds()
 
30
        self.assert_(bounds == (0,9))
 
31
        
 
32
        # no order
 
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))
 
37
        return
 
38
 
 
39
    def test_data_size(self):
 
40
        # We know that ScalarData always returns the exact length of its data
 
41
        myarray = arange(913)
 
42
        sd = ArrayDataSource(myarray)
 
43
        self.assert_(len(myarray) == sd.get_size())
 
44
        return
 
45
 
 
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)))
 
51
    
 
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")
 
57
        return
 
58
 
 
59
    def test_bounds(self):
 
60
        myarray = self.create_array()
 
61
        pd = PointDataSource(myarray)
 
62
        self.assertEqual(pd.get_bounds(),((0,0), (9,90)))
 
63
        return
 
64
        
 
65
if __name__ == '__main__':
 
66
    import nose
 
67
    nose.run()