summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2007-01-25 15:32:47 +0000
committerKore Nordmann <github@kore-nordmann.de>2007-01-25 15:32:47 +0000
commitc5b1b0f5d7b7ef32d1930a217e569699d2551374 (patch)
treef0a77ca94f9fcdd6485cc76c7df1e187db43599f /tests
parentab43942be9c79356a669bb63dca67c8de8c3ff82 (diff)
downloadzetacomponents-graph-c5b1b0f5d7b7ef32d1930a217e569699d2551374.zip
zetacomponents-graph-c5b1b0f5d7b7ef32d1930a217e569699d2551374.tar.gz
- Added simple class for 2d vectors as an extension for coordinates to
simplify calculations.
Diffstat (limited to 'tests')
-rw-r--r--tests/suite.php2
-rw-r--r--tests/vector_test.php164
2 files changed, 166 insertions, 0 deletions
diff --git a/tests/suite.php b/tests/suite.php
index ce8a09c..6c75338 100644
--- a/tests/suite.php
+++ b/tests/suite.php
@@ -38,6 +38,7 @@ require_once 'driver_flash_test.php';
require_once 'font_test.php';
require_once 'palette_test.php';
require_once 'matrix_test.php';
+require_once 'vector_test.php';
require_once 'boundings_test.php';
require_once 'polynom_test.php';
require_once 'struct_test.php';
@@ -82,6 +83,7 @@ class ezcGraphSuite extends PHPUnit_Framework_TestSuite
$this->addTest( ezcGraphTextTest::suite() );
$this->addTest( ezcGraphPaletteTest::suite() );
$this->addTest( ezcGraphMatrixTest::suite() );
+ $this->addTest( ezcGraphVectorTest::suite() );
$this->addTest( ezcGraphBoundingsTest::suite() );
$this->addTest( ezcGraphPolynomTest::suite() );
$this->addTest( ezcGraphStructTest::suite() );
diff --git a/tests/vector_test.php b/tests/vector_test.php
new file mode 100644
index 0000000..a3cb429
--- /dev/null
+++ b/tests/vector_test.php
@@ -0,0 +1,164 @@
+<?php
+/**
+ * ezcGraphVectorTest
+ *
+ * @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 ezcGraphVectorTest extends ezcTestCase
+{
+ public static function suite()
+ {
+ return new PHPUnit_Framework_TestSuite( "ezcGraphVectorTest" );
+ }
+
+ public function testCreateVector()
+ {
+ $vector = new ezcGraphVector( 1, 2 );
+
+ $this->assertEquals(
+ 1,
+ $vector->x
+ );
+
+ $this->assertEquals(
+ 2,
+ $vector->y
+ );
+ }
+
+ public function testCreateVectorFromCoordinate()
+ {
+ $vector = ezcGraphVector::fromCoordinate( new ezcGraphCoordinate( 1, 2 ) );
+
+ $this->assertEquals(
+ 1,
+ $vector->x
+ );
+
+ $this->assertEquals(
+ 2,
+ $vector->y
+ );
+ }
+
+ public function testVectorLength()
+ {
+ $vector = new ezcGraphVector( 1, 2 );
+
+ $this->assertEquals(
+ sqrt( 5 ),
+ $vector->length()
+ );
+ }
+
+ public function testUnifyVector()
+ {
+ $vector = new ezcGraphVector( 2, 0 );
+ $vector->unify();
+
+ $this->assertEquals(
+ 1,
+ $vector->x
+ );
+
+ $this->assertEquals(
+ 0,
+ $vector->y
+ );
+ }
+
+ public function testVectorMultiplyScalar()
+ {
+ $vector = new ezcGraphVector( 1, 2 );
+ $vector->scalar( 2 );
+
+ $this->assertEquals(
+ 2,
+ $vector->x
+ );
+
+ $this->assertEquals(
+ 4,
+ $vector->y
+ );
+ }
+
+ public function testVectorMultiplyCoordinate()
+ {
+ $vector = new ezcGraphVector( 1, 2 );
+ $result = $vector->mul( new ezcGraphCoordinate( 3, 2 ) );
+
+ $this->assertEquals(
+ $result,
+ 7
+ );
+ }
+
+ public function testVectorMultiplyVector()
+ {
+ $vector = new ezcGraphVector( 1, 2 );
+ $result = $vector->mul( new ezcGraphVector( 3, 2 ) );
+
+ $this->assertEquals(
+ $result,
+ 7
+ );
+ }
+
+ public function testVectorAddCoordinate()
+ {
+ $vector = new ezcGraphVector( 1, 2 );
+ $vector->add( new ezcGraphCoordinate( 3, 2 ) );
+
+ $this->assertEquals(
+ $vector,
+ new ezcGraphVector( 4, 4 )
+ );
+ }
+
+ public function testVectorAddVector()
+ {
+ $vector = new ezcGraphVector( 1, 2 );
+ $vector->add( new ezcGraphVector( 3, 2 ) );
+
+ $this->assertEquals(
+ $vector,
+ new ezcGraphVector( 4, 4 )
+ );
+ }
+
+ public function testVectorSubCoordinate()
+ {
+ $vector = new ezcGraphVector( 1, 2 );
+ $vector->sub( new ezcGraphCoordinate( 3, 2 ) );
+
+ $this->assertEquals(
+ $vector,
+ new ezcGraphVector( -2, 0 )
+ );
+ }
+
+ public function testVectorSubVector()
+ {
+ $vector = new ezcGraphVector( 1, 2 );
+ $vector->sub( new ezcGraphVector( 3, 2 ) );
+
+ $this->assertEquals(
+ $vector,
+ new ezcGraphVector( -2, 0 )
+ );
+ }
+}
+
+?>
OpenPOWER on IntegriCloud