diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2007-03-27 14:46:09 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2007-03-27 14:46:09 +0000 |
commit | 46b36627ff6184fed301ab68c428a26ac5412cda (patch) | |
tree | 567f5673cad427d22601f9823d8fb1fdb3e400c7 /tests | |
parent | 8c9729064b7d8fde5aa75701c799e4ea0181f23c (diff) | |
download | zetacomponents-graph-46b36627ff6184fed301ab68c428a26ac5412cda.zip zetacomponents-graph-46b36627ff6184fed301ab68c428a26ac5412cda.tar.gz |
- Added private classes for more convenient coordinate and vector
transformations
Diffstat (limited to 'tests')
-rw-r--r-- | tests/suite.php | 2 | ||||
-rw-r--r-- | tests/transformation_test.php | 143 | ||||
-rw-r--r-- | tests/vector_test.php | 20 |
3 files changed, 165 insertions, 0 deletions
diff --git a/tests/suite.php b/tests/suite.php index 4b490ae..22ad96c 100644 --- a/tests/suite.php +++ b/tests/suite.php @@ -44,6 +44,7 @@ require_once 'renderer_3d_test.php'; require_once 'struct_test.php'; require_once 'text_test.php'; require_once 'tools_test.php'; +require_once 'transformation_test.php'; require_once 'vector_test.php'; /** @@ -91,6 +92,7 @@ class ezcGraphSuite extends PHPUnit_Framework_TestSuite $this->addTest( ezcGraphSvgDriverTest::suite() ); $this->addTest( ezcGraphTextTest::suite() ); $this->addTest( ezcGraphToolsTest::suite() ); + $this->addTest( ezcGraphTransformationTest::suite() ); $this->addTest( ezcGraphVectorTest::suite() ); } diff --git a/tests/transformation_test.php b/tests/transformation_test.php new file mode 100644 index 0000000..023c7e1 --- /dev/null +++ b/tests/transformation_test.php @@ -0,0 +1,143 @@ +<?php +/** + * ezcGraphTransformationTest + * + * @package Graph + * @version //autogen// + * @subpackage Tests + * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + */ + +/** + * Tests for ezcGraph class. + * + * @package ImageAnalysis + * @subpackage Tests + */ +class ezcGraphTransformationTest extends ezcTestCase +{ + public static function suite() + { + return new PHPUnit_Framework_TestSuite( "ezcGraphTransformationTest" ); + } + + public function testCreateTransformation() + { + $transformation = new ezcGraphTransformation(); + $matrix = new ezcGraphMatrix( 3, 3 ); + + $this->assertEquals( + $this->getAttribute( $matrix, 'matrix' ), + $this->getAttribute( $transformation, 'matrix' ), + 'Transformation matrices are not aequivalent', + .0001 + ); + } + + public function testCreateTransformation2() + { + $transformation = new ezcGraphTransformation( + array( + array( 2, 1, 0 ), + array( 2, 1, 0 ), + array( 2, 1, 0 ), + ) + ); + + $matrix = new ezcGraphMatrix( 3, 3, + array( + array( 2, 1, 0 ), + array( 2, 1, 0 ), + array( 2, 1, 0 ), + ) + ); + + $this->assertEquals( + $this->getAttribute( $matrix, 'matrix' ), + $this->getAttribute( $transformation, 'matrix' ), + 'Transformation matrices are not aequivalent', + .0001 + ); + } + + public function testCreateTranslation() + { + $transformation = new ezcGraphTranslation( 5, 5 ); + + $matrix = new ezcGraphMatrix( 3, 3, + array( + array( 1, 0, 5 ), + array( 0, 1, 5 ), + array( 0, 0, 1 ), + ) + ); + + $this->assertEquals( + $this->getAttribute( $matrix, 'matrix' ), + $this->getAttribute( $transformation, 'matrix' ), + 'Transformation matrices are not aequivalent', + .0001 + ); + } + + public function testTranslateCoordinate() + { + $transformation = new ezcGraphTranslation( 5, 5 ); + + $testCoordinate = new ezcGraphCoordinate( 0, 0 ); + $testCoordinate = $transformation->transformCoordinate( $testCoordinate ); + + $this->assertEquals( + new ezcGraphCoordinate( 5, 5 ), + $testCoordinate, + 'Transformation of coordinate has wrong result.', + .0001 + ); + } + + public function testCreateRotation() + { + $transformation = new ezcGraphRotation( 90 ); + + $matrix = new ezcGraphMatrix( 3, 3, + array( + array( 0, -1, 0 ), + array( 1, 0, 0 ), + array( 0, 0, 1 ), + ) + ); + + $this->assertEquals( + $this->getAttribute( $matrix, 'matrix' ), + $this->getAttribute( $transformation, 'matrix' ), + 'Transformation matrices are not aequivalent', + .0001 + ); + } + + public function testCreateTranslatedRotation() + { + $transformation = new ezcGraphRotation( 90, new ezcGraphCoordinate( 10, 10 ) ); + + $matrix = new ezcGraphMatrix( 3, 3, + array( + array( 0, 1, 0 ), + array( -1, 0, 0 ), + array( 0, 0, 1 ), + ) + ); + + $testCoordinate = new ezcGraphCoordinate( 0, 0 ); + $testCoordinate = $transformation->transformCoordinate( $testCoordinate ); + + $this->assertEquals( + new ezcGraphCoordinate( 20, 0 ), + $testCoordinate, + 'Transformation matrices are not aequivalent', + .0001 + ); + } +} + +?> diff --git a/tests/vector_test.php b/tests/vector_test.php index acab733..f588d65 100644 --- a/tests/vector_test.php +++ b/tests/vector_test.php @@ -271,6 +271,26 @@ class ezcGraphVectorTest extends ezcTestCase 'Result should be the vector itself' ); } + + public function testVectorTransform() + { + $vector = new ezcGraphVector( 0, 0 ); + + $result = $vector->transform( new ezcGraphRotation( -90, new ezcGraphCoordinate( 15, 15 ) ) ); + + $this->assertEquals( + $vector, + new ezcGraphVector( 0, 30 ), + 'Vector transformation does not have the expected result', + .0001 + ); + + $this->assertEquals( + $result, + $vector, + 'Result should be the vector itself' + ); + } } ?> |