Commit aa3d92f7 by Alexander Makarov

more tests for Vector

parent 79859238
...@@ -44,6 +44,16 @@ class VectorTest extends \yiiunit\TestCase ...@@ -44,6 +44,16 @@ class VectorTest extends \yiiunit\TestCase
$this->assertEquals(2,$vector2->getCount()); $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() public function testGetCount()
{ {
$this->assertEquals(2,$this->vector->getCount()); $this->assertEquals(2,$this->vector->getCount());
...@@ -93,10 +103,17 @@ class VectorTest extends \yiiunit\TestCase ...@@ -93,10 +103,17 @@ class VectorTest extends \yiiunit\TestCase
public function testClear() public function testClear()
{ {
$this->vector->add($this->item3);
$this->vector->clear(); $this->vector->clear();
$this->assertEquals(0,$this->vector->getCount()); $this->assertEquals(0,$this->vector->getCount());
$this->assertEquals(-1,$this->vector->indexOf($this->item1)); $this->assertEquals(-1,$this->vector->indexOf($this->item1));
$this->assertEquals(-1,$this->vector->indexOf($this->item2)); $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() public function testContains()
...@@ -127,6 +144,12 @@ class VectorTest extends \yiiunit\TestCase ...@@ -127,6 +144,12 @@ class VectorTest extends \yiiunit\TestCase
$array=array($this->item3,$this->item1); $array=array($this->item3,$this->item1);
$this->vector->mergeWith($array); $this->vector->mergeWith($array);
$this->assertTrue($this->vector->getCount()==4 && $this->vector[0]===$this->item1 && $this->vector[3]===$this->item1); $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->setExpectedException('yii\base\InvalidCallException');
$this->vector->mergeWith($this); $this->vector->mergeWith($this);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment