cvs: pear /Math_Vector/tests TupleCreationTest.php VectorCreationTest.php tuple_creation.php vector_creation.php vector_operations.php

From: Date: Wed, 24 Apr 2002 23:25:28 +0000
Subject: cvs: pear /Math_Vector/tests TupleCreationTest.php VectorCreationTest.php tuple_creation.php vector_creation.php vector_operations.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-3525@lists.php.net to get a copy of this message
jmcastagnetto Wed Apr 24 19:25:28 2002 EDT Added files: /pear/Math_Vector/tests TupleCreationTest.php VectorCreationTest.php Removed files: /pear/Math_Vector/tests tuple_creation.php vector_creation.php vector_operations.php Log: Moved old scripts to examples Using PHPUnit to implement unit testing Index: pear/Math_Vector/tests/TupleCreationTest.php +++ pear/Math_Vector/tests/TupleCreationTest.php <?php require_once "Math/Vector/Tuple.php"; echo "Creating tuple\n"; $t = new Math_Tuple(array(2,3,4)); print_r($t); echo "Tuple size: ".$t->getSize()."\n"; echo "Adding element value 7\n"; $t->addElement(7); echo "Tuple size: ".$t->getSize()."\n"; echo "Tuple toString: ".$t->toString()."\n"; echo "Setting element 1 to 11\n"; $t->setElement(1, 11); echo "Tuple toString: ".$t->toString()."\n"; echo "Maximum element value: ".$t->getMax()."\n"; echo "Minimum element value: ".$t->getMin()."\n"; echo "Index of maximum value: ".$t->getMaxIndex()."\n"; echo "Index of minimum value: ".$t->getMinIndex()."\n"; echo "Remove element 2\n"; $t->delElement(2); echo "Tuple toString: ".$t->toString()."\n"; echo "Get element 2: ".$t->getElement(2)."\n"; echo "Get index of element value 11: ".$t->getValueIndex(11)."\n"; ?> Index: pear/Math_Vector/tests/VectorCreationTest.php +++ pear/Math_Vector/tests/VectorCreationTest.php <?php require_once "Math/Vector/Vector.php"; require_once "Math/Vector/Vector2.php"; require_once "Math/Vector/Vector3.php"; require_once "PHPUnit/PHPUnit.php"; class VectorCreationTest extends PHPUnit_TestCase { var $v; var $w; var $z; var $x; var $y; var $a; var $t; var $bad; function VectorCreationTest($name) { $this->PHPUnit_TestCase($name); } function setup() { $this->a = array(2,3,4); $this->t = new Math_Tuple(array(2,6,8)); $this->v = new Math_Vector($this->a); $this->w = new Math_Vector($this->t); $this->z = new Math_Vector(new Math_Vector(range(2,5))); $this->y = new Math_Vector2(array(1,2)); $this->x = new Math_Vector3(new Math_Tuple(array(1,0,1))); $this->bad = new Math_Vector("foo"); } // Vector from array function testFromArray() { $this->assertTrue(Math_VectorOp::isVector($this->v) && $this->v->isValid()); } //Vector from tuple function testFromTuple() { $this->assertTrue(Math_VectorOp::isVector($this->w) && $this->w->isValid()); } function testFromVector() { $this->assertTrue(Math_VectorOp::isVector($this->z) && $this->z->isValid()); } function test2DVector() { $this->assertTrue(Math_VectorOp::isVector2($this->y) && $this->y->isValid()); } function test3DVector() { $this->assertTrue(Math_VectorOp::isVector3($this->x) && $this->x->isValid()); } function testBadVector() { $this->assertTrue(Math_VectorOp::isVector($this->bad) && !$this->bad->isValid()); } function testLength() { $l = number_format($this->v->length(), 8); $this->assertTrue($l == 5.38516481); } function testToString() { $this->assertTrue($this->v->toString() == "Vector: < 2, 3, 4 >"); } function testNormalize() { $this->v->normalize(); $this->assertTrue($this->v->length() == 1); } function testReverse() { $this->v->reverse(); $this->assertTrue($this->v->toString() == "Vector: < -2, -3, -4 >"); } } echo date("Y-m-d H:i:s")."\n"; echo "Vector creation and methods\n"; $suite = new PHPUnit_TestSuite('VectorCreationTest'); $result = PHPUnit::run($suite); echo $result->toString(); ?>

« previous php.pear.cvs (#3525) next »