Changeset 176 for trunk/tests
- Timestamp:
- 03/22/09 03:38:17 (3 years ago)
- Files:
-
- 1 modified
-
trunk/tests/bar.py (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/bar.py
r112 r176 1 # Copyright (c) 2007-2008by Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com>1 # Copyright(c) 2007-2009 by Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com> 2 2 # 3 3 # This file is part of PyCha. … … 22 22 import pycha.bar 23 23 24 24 25 class RectTests(unittest.TestCase): 25 26 … … 34 35 self.assertEqual(r.name, 'test') 35 36 37 36 38 class BarTests(unittest.TestCase): 37 39 … … 45 47 # An evil dataset with just one point. See bug #9 46 48 dataset = ( 47 ('dataset1', ([0, 0], )),49 ('dataset1', ([0, 0], )), 48 50 ) 49 51 ch = pycha.bar.BarChart(surface) … … 54 56 self.assertEqual(ch.xscale, 1.0) 55 57 self.assertEqual(ch.minxval, 0) 58 self.assertEqual(ch.minxdelta, 1.0) 56 59 self.assertAlmostEqual(ch.barWidthForSet, 0.75, 4) 57 60 self.assertAlmostEqual(ch.barMargin, 0.125, 4) 61 62 def test_customRangeWithOnePoint(self): 63 """Weird results with a custom range and just one point. See bug #20""" 64 surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 500, 500) 65 66 dataset = ( 67 ('dataset1', ([0, 1], )), 68 ) 69 options = { 70 'axis': { 71 'x': { 72 'range': (0.0, 4.0), 73 }, 74 }, 75 } 76 ch = pycha.bar.BarChart(surface, options) 77 ch.addDataset(dataset) 78 ch._updateXY() 79 ch._updateChart() 80 81 self.assertEqual(ch.xscale, 0.2) 82 self.assertEqual(ch.minxval, 0) 83 self.assertEqual(ch.minxdelta, 1.0) 84 self.assertAlmostEqual(ch.barWidthForSet, 0.15, 2) 85 self.assertAlmostEqual(ch.barMargin, 0.025, 3) 86 58 87 59 88 class VerticalBarTests(unittest.TestCase): … … 132 161 R(0.03125, 0.625, 0.1875, 0.375, 0, -3, 'dataset1'), 133 162 R(0.28125, 0.625, 0.1875, 0.125, 1, -1, 'dataset1'), 134 R(0.53125, 0.250, 0.1875, 0.375, 2, 3, 'dataset1'),135 R(0.78125, 0.000, 0.1875, 0.625, 3, 5, 'dataset1'),163 R(0.53125, 0.250, 0.1875, 0.375, 2, 3, 'dataset1'), 164 R(0.78125, 0.000, 0.1875, 0.625, 3, 5, 'dataset1'), 136 165 ) 137 166 … … 165 194 (1.0, 0.0), (0.9, 0.4), (0.8, 0.8), (0.7, 1.2), (0.6, 1.6), 166 195 (0.5, 2.0), (0.4, 2.4), (0.3, 2.8), (0.2, 3.2), (0.1, 3.6), 167 (0.0, 4.0) 196 (0.0, 4.0), 168 197 ] 169 198 for i in range(len(yticks)): … … 189 218 (1.0, -2.0), (0.9, -1.5), (0.8, -1.0), (0.7, -0.5), (0.6, 0.0), 190 219 (0.5, 0.5), (0.4, 1.0), (0.3, 1.5), (0.2, 2.0), (0.1, 2.5), 191 (0.0, 3.0) 220 (0.0, 3.0), 192 221 ] 193 222 for i in range(len(yticks)): … … 199 228 shadow = ch._getShadowRectangle(10, 20, 400, 300) 200 229 self.assertEqual(shadow, (8, 18, 404, 302)) 230 201 231 202 232 class HorizontalBarTests(unittest.TestCase): … … 295 325 (0.0, 0.0), (0.1, 0.4), (0.2, 0.8), (0.3, 1.2), (0.4, 1.6), 296 326 (0.5, 2.0), (0.6, 2.4), (0.7, 2.8), (0.8, 3.2), (0.9, 3.6), 297 (1.0, 4.0) 327 (1.0, 4.0), 298 328 ] 299 329 for i in range(len(xticks)): … … 319 349 (0.0, -2.0), (0.1, -1.5), (0.2, -1.0), (0.3, -0.5), (0.4, 0.0), 320 350 (0.5, 0.5), (0.6, 1.0), (0.7, 1.5), (0.8, 2.0), (0.9, 2.5), 321 (1.0, 3.0) 351 (1.0, 3.0), 322 352 ] 323 353 for i in range(len(xticks)): … … 334 364 shadow = ch._getShadowRectangle(10, 20, 400, 300) 335 365 self.assertEqual(shadow, (10, 18, 402, 304)) 366 336 367 337 368 def test_suite(): … … 345 376 if __name__ == '__main__': 346 377 unittest.main(defaultTest='test_suite') 347
