summaryrefslogtreecommitdiffstats
path: root/tests/labeled_axis_test.php
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2007-03-01 16:17:41 +0000
committerKore Nordmann <github@kore-nordmann.de>2007-03-01 16:17:41 +0000
commit77f95ac645f623f89330762f055e9599e03a9a5b (patch)
treed62df38a08a1db499ca09736be5256b1ae9e26d5 /tests/labeled_axis_test.php
parent5ccc6648a4832f3343305fc0074bf86709baad14 (diff)
downloadzetacomponents-graph-77f95ac645f623f89330762f055e9599e03a9a5b.zip
zetacomponents-graph-77f95ac645f623f89330762f055e9599e03a9a5b.tar.gz
- Fixed issue #10275: Low label count on labeled axis
Diffstat (limited to 'tests/labeled_axis_test.php')
-rw-r--r--tests/labeled_axis_test.php146
1 files changed, 144 insertions, 2 deletions
diff --git a/tests/labeled_axis_test.php b/tests/labeled_axis_test.php
index 16c641f..6097eeb 100644
--- a/tests/labeled_axis_test.php
+++ b/tests/labeled_axis_test.php
@@ -9,26 +9,48 @@
* @license http://ez.no/licenses/new_bsd New BSD License
*/
+require_once dirname( __FILE__ ) . '/test_case.php';
+
/**
* Tests for ezcGraph class.
*
* @package ImageAnalysis
* @subpackage Tests
*/
-class ezcGraphLabeledAxisTest extends ezcTestCase
+class ezcGraphLabeledAxisTest extends ezcGraphTestCase
{
+ protected $basePath;
+
+ protected $tempDir;
+
public static function suite()
{
return new PHPUnit_Framework_TestSuite( "ezcGraphLabeledAxisTest" );
}
+ protected function setUp()
+ {
+ static $i = 0;
+
+ $this->tempDir = $this->createTempDir( __CLASS__ . sprintf( '_%03d_', ++$i ) ) . '/';
+ $this->basePath = dirname( __FILE__ ) . '/data/';
+ }
+
+ protected function tearDown()
+ {
+ if ( !$this->hasFailed() )
+ {
+ $this->removeTempDir();
+ }
+ }
+
public function testFactoryLabeledAxis()
{
$chart = new ezcGraphLineChart();
$this->assertTrue(
$chart->xAxis instanceof ezcGraphChartElementLabeledAxis
- );
+ );
}
public function testAutomaticLabelingSingle()
@@ -295,6 +317,101 @@ class ezcGraphLabeledAxisTest extends ezcTestCase
);
}
+ public function testAutomaticLabelingWithLotsOfLabels2()
+ {
+ $labelCount = 31;
+
+ // Make this reproducible
+ mt_srand( 2 );
+
+ for ( $i = 0; $i < $labelCount; ++$i )
+ {
+ $data[(string) ( 2000 + $i )] = mt_rand( 500, 2000 );
+ }
+
+ $chart = new ezcGraphLineChart();
+ $chart->data['sample'] = new ezcGraphArrayDataSet( $data );
+ $chart->render( 500, 200 );
+
+ $this->assertEquals(
+ array(
+ 2000,
+ 2003,
+ 2006,
+ 2009,
+ 2012,
+ 2015,
+ 2018,
+ 2021,
+ 2024,
+ 2027,
+ 2030,
+ ),
+ $this->getAttribute( $chart->xAxis, 'displayedLabels' )
+ );
+ }
+
+ public function testAutomaticLabelingWithLotsOfLabels3()
+ {
+ $labelCount = 32;
+
+ // Make this reproducible
+ mt_srand( 2 );
+
+ for ( $i = 0; $i < $labelCount; ++$i )
+ {
+ $data[(string) ( 2000 + $i )] = mt_rand( 500, 2000 );
+ }
+
+ $chart = new ezcGraphLineChart();
+ $chart->data['sample'] = new ezcGraphArrayDataSet( $data );
+ $chart->render( 500, 200 );
+
+ $this->assertEquals(
+ array(
+ 2000,
+ 2004,
+ 2007,
+ 2011,
+ 2014,
+ 2018,
+ 2021,
+ 2025,
+ 2028,
+ 2031,
+ ),
+ $this->getAttribute( $chart->xAxis, 'displayedLabels' )
+ );
+ }
+
+ public function testAutomaticLabelingWithLotsOfLabels4()
+ {
+ $labelCount = 165;
+
+ // Make this reproducible
+ mt_srand( 2 );
+
+ for ( $i = 0; $i < $labelCount; ++$i )
+ {
+ $data[(string) ( 2000 + $i )] = mt_rand( 500, 2000 );
+ }
+
+ $chart = new ezcGraphLineChart();
+ $chart->data['sample'] = new ezcGraphArrayDataSet( $data );
+ $chart->render( 500, 200 );
+
+ $this->assertEquals(
+ array(
+ 2000,
+ 2041,
+ 2082,
+ 2123,
+ 2164,
+ ),
+ $this->getAttribute( $chart->xAxis, 'displayedLabels' )
+ );
+ }
+
public function testGetLabel()
{
$chart = new ezcGraphLineChart();
@@ -320,6 +437,31 @@ class ezcGraphLabeledAxisTest extends ezcTestCase
'Wrong label returned for nonexisting step.'
);
}
+
+ public function testRenderUnregularLabeling()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+ $labelCount = 32;
+
+ // Make this reproducible
+ mt_srand( 2 );
+
+ for ( $i = 0; $i < $labelCount; ++$i )
+ {
+ $data[(string) ( 2000 + $i )] = mt_rand( 500, 2000 );
+ }
+
+ $chart = new ezcGraphLineChart();
+ $chart->data['sample'] = new ezcGraphArrayDataSet( $data );
+
+ $chart->render( 500, 200, $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
+ );
+ }
}
?>
OpenPOWER on IntegriCloud