diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2006-09-06 14:46:41 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2006-09-06 14:46:41 +0000 |
commit | 9f40ec30e4737262a2132dfa76dc0beba30fa795 (patch) | |
tree | 5ba5ae643af19c62548be81765c2fddabccc6487 /tests/dataset_average_test.php | |
parent | 3b131319615c8949013734a141ce3939ea4b614d (diff) | |
download | zetacomponents-graph-9f40ec30e4737262a2132dfa76dc0beba30fa795.zip zetacomponents-graph-9f40ec30e4737262a2132dfa76dc0beba30fa795.tar.gz |
- Got average datasets working
Diffstat (limited to 'tests/dataset_average_test.php')
-rw-r--r-- | tests/dataset_average_test.php | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/tests/dataset_average_test.php b/tests/dataset_average_test.php index 9a00763..758d8c5 100644 --- a/tests/dataset_average_test.php +++ b/tests/dataset_average_test.php @@ -18,6 +18,10 @@ class ezcGraphDataSetAverageTest extends ezcTestCase { + protected $basePath; + + protected $tempDir; + public static function suite() { return new ezcTestSuite( "ezcGraphDataSetAverageTest" ); @@ -30,6 +34,9 @@ class ezcGraphDataSetAverageTest extends ezcTestCase */ public function setUp() { + static $i = 0; + $this->tempDir = $this->createTempDir( __CLASS__ . sprintf( '_%03d_', ++$i ) ) . '/'; + $this->basePath = dirname( __FILE__ ) . '/data/'; } /** @@ -39,6 +46,37 @@ class ezcGraphDataSetAverageTest extends ezcTestCase */ public function tearDown() { + if( !$this->hasFailed() ) + { + $this->removeTempDir(); + } + } + + /** + * Compares a generated image with a stored file + * + * @param string $generated Filename of generated image + * @param string $compare Filename of stored image + * @return void + */ + protected function compare( $generated, $compare ) + { + $this->assertTrue( + file_exists( $generated ), + 'No image file has been created.' + ); + + $this->assertTrue( + file_exists( $compare ), + 'Comparision image does not exist.' + ); + + if ( md5_file( $generated ) !== md5_file( $compare ) ) + { + // Adding a diff makes no sense here, because created XML uses + // only two lines + $this->fail( 'Rendered image is not correct.'); + } } public function testCreateDatasetFromDataset() @@ -85,6 +123,7 @@ class ezcGraphDataSetAverageTest extends ezcTestCase $polynom->__toString() ); } + public function testCreateDatasetFromDatasetHighOrder() { $arrayDataSet = new ezcGraphArrayDataSet( array( -1 => 2, 1 => 2, 3 => 10 ) ); @@ -99,5 +138,78 @@ class ezcGraphDataSetAverageTest extends ezcTestCase $polynom->__toString() ); } + + public function testIterateOverAverageDataset() + { + $arrayDataSet = new ezcGraphArrayDataSet( array( -1 => 2, 1 => 2, 3 => 10 ) ); + + $averageDataSet = new ezcGraphDataSetAveragePolynom( $arrayDataSet ); + $averageDataSet->polynomOrder = 3; + + $this->assertEquals( + 2., + $averageDataSet[-1], + 'Polynom should evaluate to 2.', + .01 + ); + + $this->assertEquals( + 2., + $averageDataSet[1], + 'Polynom should evaluate to 2.', + .01 + ); + + $this->assertEquals( + 5., + $averageDataSet[2], + 'Polynom should evaluate to 5.', + .01 + ); + + $this->assertEquals( + 10., + $averageDataSet[3], + 'Polynom should evaluate to 10.', + .01 + ); + } + + public function testRenderCompleteLineChart() + { + $filename = $this->tempDir . __FUNCTION__ . '.svg'; + + $chart = new ezcGraphLineChart(); + $chart->data['Statistical data'] = new ezcGraphArrayDataSet( array( + '1' => 1, + '2.5' => -2.3, + '3.1' => 1.4, + '4' => 5, + '5.3' => 1.2, + '7' => 6.5, + ) ); + $chart->data['Statistical data']->symbol = ezcGraph::BULLET; + + $chart->data['polynom order 0'] = new ezcGraphDataSetAveragePolynom( $chart->data['Statistical data'] ); + $chart->data['polynom order 0']->polynomOrder = 0; + + $chart->data['polynom order 1'] = new ezcGraphDataSetAveragePolynom( $chart->data['Statistical data'] ); + $chart->data['polynom order 1']->polynomOrder = 1; + + $chart->data['polynom order 3'] = new ezcGraphDataSetAveragePolynom( $chart->data['Statistical data'] ); + $chart->data['polynom order 3']->polynomOrder = 3; + + $chart->data['polynom order 5'] = new ezcGraphDataSetAveragePolynom( $chart->data['Statistical data'] ); + $chart->data['polynom order 5']->polynomOrder = 5; + + $chart->xAxis = new ezcGraphChartElementNumericAxis(); + + $chart->render( 500, 200, $filename ); + + $this->compare( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' + ); + } } ?> |