From aa3d92f71550c154c52814086ae603de4dddaf61 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Mon, 25 Feb 2013 02:54:31 +0400 Subject: [PATCH] more tests for Vector --- tests/unit/framework/base/VectorTest.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/unit/framework/base/VectorTest.php b/tests/unit/framework/base/VectorTest.php index f7fadfd..3c89ce0 100644 --- a/tests/unit/framework/base/VectorTest.php +++ b/tests/unit/framework/base/VectorTest.php @@ -44,6 +44,16 @@ class VectorTest extends \yiiunit\TestCase $this->assertEquals(2,$vector2->getCount()); } + public function testItemAt() + { + $a=array(1, 2, null, 4); + $vector=new Vector($a); + $this->assertEquals(1, $vector->itemAt(0)); + $this->assertEquals(2, $vector->itemAt(1)); + $this->assertNull($vector->itemAt(2)); + $this->assertEquals(4, $vector->itemAt(3)); + } + public function testGetCount() { $this->assertEquals(2,$this->vector->getCount()); @@ -93,10 +103,17 @@ class VectorTest extends \yiiunit\TestCase public function testClear() { + $this->vector->add($this->item3); $this->vector->clear(); $this->assertEquals(0,$this->vector->getCount()); $this->assertEquals(-1,$this->vector->indexOf($this->item1)); $this->assertEquals(-1,$this->vector->indexOf($this->item2)); + + $this->vector->add($this->item3); + $this->vector->clear(true); + $this->assertEquals(0,$this->vector->getCount()); + $this->assertEquals(-1,$this->vector->indexOf($this->item1)); + $this->assertEquals(-1,$this->vector->indexOf($this->item2)); } public function testContains() @@ -127,6 +144,12 @@ class VectorTest extends \yiiunit\TestCase $array=array($this->item3,$this->item1); $this->vector->mergeWith($array); $this->assertTrue($this->vector->getCount()==4 && $this->vector[0]===$this->item1 && $this->vector[3]===$this->item1); + + $a=array(1); + $vector=new Vector($a); + $this->vector->mergeWith($vector); + $this->assertTrue($this->vector->getCount()==5 && $this->vector[0]===$this->item1 && $this->vector[3]===$this->item1 && $this->vector[4]===1); + $this->setExpectedException('yii\base\InvalidCallException'); $this->vector->mergeWith($this); }