diff options
author | knut <> | 2007-05-29 23:10:22 +0000 |
---|---|---|
committer | knut <> | 2007-05-29 23:10:22 +0000 |
commit | 0c859c17c7439155d2ed185cb5f1d3977519c002 (patch) | |
tree | 79090adfe0de3ef96b39b941152505cd3ec1b88d /tests | |
parent | 261b6cb919c3c17ba9105958bb0fbbbbe3d74035 (diff) |
full coverage on TList and TMap in System.Collections
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/Collections/TListTest.php | 74 | ||||
-rw-r--r-- | tests/unit/Collections/TMapTest.php | 34 |
2 files changed, 82 insertions, 26 deletions
diff --git a/tests/unit/Collections/TListTest.php b/tests/unit/Collections/TListTest.php index 1750d743..a1c0bf72 100644 --- a/tests/unit/Collections/TListTest.php +++ b/tests/unit/Collections/TListTest.php @@ -1,8 +1,7 @@ <?php require_once dirname(__FILE__).'/../phpunit.php'; -class ListItem -{ +class ListItem { public $data='data'; } @@ -10,8 +9,9 @@ class ListItem * @package System.Collections */ class TListTest extends PHPUnit_Framework_TestCase { - protected $list; - protected $item1,$item2,$item3; + + protected $list; + protected $item1, $item2, $item3; public function setUp() { $this->list=new TList; @@ -37,6 +37,13 @@ class TListTest extends PHPUnit_Framework_TestCase { $this->assertEquals(2,$list2->getCount()); } + public function testGetReadOnly() { + $list = new TList(null, true); + self::assertEquals(true, $list->getReadOnly(), 'List is not read-only'); + $list = new TList(null, false); + self::assertEquals(false, $list->getReadOnly(), 'List is read-only'); + } + public function testGetCount() { $this->assertEquals(2,$this->list->getCount()); $this->assertEquals(2,$this->list->Count); @@ -63,6 +70,16 @@ class TListTest extends PHPUnit_Framework_TestCase { } } + public function testCanNotInsertWhenReadOnly() { + $list = new TList(array(), true); + try { + $list->insertAt(1, 2); + } catch(TInvalidOperationException $e) { + return; + } + self::fail('An expected TInvalidOperationException was not raised'); + } + public function testRemove() { $this->list->remove($this->item1); $this->assertEquals(1,$this->list->getCount()); @@ -90,6 +107,16 @@ class TListTest extends PHPUnit_Framework_TestCase { } } + public function testCanNotRemoveWhenReadOnly() { + $list = new TList(array(1, 2, 3), true); + try { + $list->removeAt(2); + } catch(TInvalidOperationException $e) { + return; + } + self::fail('An expected TInvalidOperationException was not raised'); + } + public function testClear() { $this->list->clear(); $this->assertEquals(0,$this->list->getCount()); @@ -149,27 +176,6 @@ class TListTest extends PHPUnit_Framework_TestCase { } } - /*public function testArrayWrite() { - $this->list[]=$this->item3; - $this->assertTrue($this->list[2]===$this->item3 && $this->list->getCount()===3); - $this->list[0]=$this->item3; - $this->assertTrue($this->list[0]===$this->item3 && $this->list->getCount()===3 && $this->list->indexOf($this->item1)===-1); - unset($this->list[1]); - $this->assertTrue($this->list->getCount()===2 && $this->list->indexOf($this->item2)===-1); - try { - $this->list[5]=$this->item3; - $this->fail('exception not raised when setting item at an out-of-range index'); - } catch(TInvalidDataValueException $e) { - - } - try { - unset($this->list[5]); - $this->fail('exception not raised when unsetting item at an out-of-range index'); - } catch(TInvalidDataValueException $e) { - - } - }*/ - public function testGetIterator() { $n=0; $found=0; @@ -189,6 +195,24 @@ class TListTest extends PHPUnit_Framework_TestCase { $this->assertTrue(isset($this->list[1])); $this->assertFalse(isset($this->list[2])); } + + public function testOffsetSetAdd() { + $list = new TList(array(1, 2, 3)); + $list->offsetSet(null, 4); + self::assertEquals(array(1, 2, 3, 4), $list->toArray()); + } + + public function testOffsetSetReplace() { + $list = new TList(array(1, 2, 3)); + $list->offsetSet(1, 4); + self::assertEquals(array(1, 4, 3), $list->toArray()); + } + + public function testOffsetUnset() { + $list = new TList(array(1, 2, 3)); + $list->offsetUnset(1); + self::assertEquals(array(1, 3), $list->toArray()); + } } diff --git a/tests/unit/Collections/TMapTest.php b/tests/unit/Collections/TMapTest.php index 10e620f5..c6a2172c 100644 --- a/tests/unit/Collections/TMapTest.php +++ b/tests/unit/Collections/TMapTest.php @@ -36,6 +36,13 @@ class TMapTest extends PHPUnit_Framework_TestCase { $this->assertEquals(2,$map2->getCount()); } + public function testGetReadOnly() { + $map = new TMap(null, true); + self::assertEquals(true, $map->getReadOnly(), 'List is not read-only'); + $map = new TList(null, false); + self::assertEquals(false, $map->getReadOnly(), 'List is read-only'); + } + public function testGetCount() { $this->assertEquals(2,$this->map->getCount()); } @@ -51,6 +58,16 @@ class TMapTest extends PHPUnit_Framework_TestCase { $this->assertTrue($this->map->getCount()==3 && $this->map->contains('key3')); } + public function testCanNotAddWhenReadOnly() { + $map = new TMap(array(), true); + try { + $map->add('key', 'value'); + } catch(TInvalidOperationException $e) { + return; + } + self::fail('An expected TInvalidOperationException was not raised'); + } + public function testRemove() { $this->map->remove('key1'); @@ -58,6 +75,16 @@ class TMapTest extends PHPUnit_Framework_TestCase { $this->assertTrue($this->map->remove('unknown key')===null); } + public function testCanNotRemoveWhenReadOnly() { + $map = new TMap(array('key' => 'value'), true); + try { + $map->remove('key'); + } catch(TInvalidOperationException $e) { + return; + } + self::fail('An expected TInvalidOperationException was not raised'); + } + public function testClear() { $this->map->clear(); @@ -150,6 +177,11 @@ class TMapTest extends PHPUnit_Framework_TestCase { $this->assertTrue(isset($this->map['key1'])); $this->assertFalse(isset($this->map['unknown key'])); } + + public function testToArray() { + $map = new TMap(array('key' => 'value')); + self::assertEquals(array('key' => 'value'), $map->toArray()); + } } -?>
\ No newline at end of file +?> |