/usr/lib/python2.7/dist-packages/chaco/tests/logmapper_test_case.py is in python-chaco 4.5.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | import unittest
from numpy import array, nan
from numpy.testing import assert_array_almost_equal, assert_equal
from chaco.api import ArrayDataSource, DataRange1D, LogMapper
class LogMapperTestCase(unittest.TestCase):
def test_basic(self):
ary = array([1.0, 10.0, 100.0, 1000.0, 10000.0])
ds = ArrayDataSource(ary)
r = DataRange1D(ds)
mapper = LogMapper(range=r, low_pos=50, high_pos=90)
result = mapper.map_screen(ary)
assert_equal(result, array([50, 60, 70, 80, 90]))
return
def test_reversed(self):
ary = array([1.0, 10.0, 100.0, 1000.0, 10000.0])
ds = ArrayDataSource(ary)
r = DataRange1D(ds)
mapper = LogMapper(range=r, low_pos=100, high_pos=0)
result = mapper.map_screen(ary)
assert_array_almost_equal(result, array([100, 75, 50, 25, 0]))
return
def test_fractional(self):
ary = array([0.0001, 0.001, 0.01])
ds = ArrayDataSource(ary)
r = DataRange1D(ds)
mapper = LogMapper(range=r, low_pos=0, high_pos=20)
result = mapper.map_screen(ary)
assert_array_almost_equal(result, [0, 10, 20])
return
def test_zero(self):
ary = array([0.0, 1.0, 10.0, 100.0, 1000.0])
ds = ArrayDataSource(ary)
r = DataRange1D(ds)
mapper = LogMapper(range=r, low_pos=0, high_pos=30)
result = mapper.map_screen(ary)
assert_array_almost_equal(result, [0, 0, 10, 20, 30])
return
def test_negative(self):
ary = array([1.0, -1.0, -2.0, 10.0, 100.0, 1000.0])
ds = ArrayDataSource(ary)
r = DataRange1D(ds)
mapper = LogMapper(range=r, low_pos=0, high_pos=30)
result = mapper.map_screen(ary)
assert_array_almost_equal(result, [0, 0, 0, 10, 20, 30])
return
def test_fill_value(self):
ary = array([1.0, -1.0, -2.0, 10.0, 100.0, 1000.0])
ds = ArrayDataSource(ary)
r = DataRange1D(ds)
mapper = LogMapper(range=r, low_pos=0, high_pos=30)
# This causes out-of-bounds values to be treated as the value 100.0
mapper.fill_value = 100.0
result = mapper.map_screen(ary)
assert_array_almost_equal(result, [0, 20, 20, 10, 20, 30])
return
def test_nan(self):
ary = array([1.0, nan, 10.0, nan, 100.0, 1000.0])
ds = ArrayDataSource(ary)
r = DataRange1D(ds)
mapper = LogMapper(range=r, low_pos=0, high_pos=30)
mapper.fill_value = 100.0
result = mapper.map_screen(ary)
assert_array_almost_equal(result, [0, 20, 10, 20, 20, 30])
return
if __name__ == '__main__':
import nose
nose.run()
|