summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorxue <>2006-01-31 00:01:49 +0000
committerxue <>2006-01-31 00:01:49 +0000
commit01bc363ac789cfb9d644ce82a949da5cd7e1c220 (patch)
treea059046856645d59cf0cb1badee83eb5c73671e9 /tests
parent265b7e85766ba403ca0a8b58648dd091e483cf38 (diff)
Modified TList and TMap implementation so that they can be more easily extended.
Diffstat (limited to 'tests')
-rw-r--r--tests/UnitTests/framework/Collections/utList.php91
-rw-r--r--tests/UnitTests/framework/Collections/utMap.php85
-rw-r--r--tests/unit/Collections/TListTest.php118
-rw-r--r--tests/unit/Collections/TMapTest.php96
4 files changed, 30 insertions, 360 deletions
diff --git a/tests/UnitTests/framework/Collections/utList.php b/tests/UnitTests/framework/Collections/utList.php
index 056f38b1..e95f718b 100644
--- a/tests/UnitTests/framework/Collections/utList.php
+++ b/tests/UnitTests/framework/Collections/utList.php
@@ -7,54 +7,6 @@ class ListItem
public $data='data';
}
-class NewList extends TList
-{
- private $_canAddItem=true;
- private $_canRemoveItem=true;
- private $_itemAdded=false;
- private $_itemRemoved=false;
-
- protected function addedItem($item)
- {
- $this->_itemAdded=true;
- }
-
- protected function removedItem($item)
- {
- $this->_itemRemoved=true;
- }
-
- protected function canAddItem($item)
- {
- return $this->_canAddItem;
- }
-
- protected function canRemoveItem($item)
- {
- return $this->_canRemoveItem;
- }
-
- public function setCanAddItem($value)
- {
- $this->_canAddItem=$value;
- }
-
- public function setCanRemoveItem($value)
- {
- $this->_canRemoveItem=$value;
- }
-
- public function isItemAdded()
- {
- return $this->_itemAdded;
- }
-
- public function isItemRemoved()
- {
- return $this->_itemRemoved;
- }
-}
-
class utList extends UnitTestCase
{
protected $list;
@@ -101,16 +53,16 @@ class utList extends UnitTestCase
}
- public function testInsert()
+ public function testInsertAt()
{
- $this->list->insert(0,$this->item3);
+ $this->list->insertAt(0,$this->item3);
$this->assertEqual(3,$this->list->getCount());
$this->assertEqual(2,$this->list->indexOf($this->item2));
$this->assertEqual(0,$this->list->indexOf($this->item3));
$this->assertEqual(1,$this->list->indexOf($this->item1));
try
{
- $this->list->insert(4,$this->item3);
+ $this->list->insertAt(4,$this->item3);
$this->fail('exception not raised when adding item at an out-of-range index');
}
catch(TInvalidDataValueException $e)
@@ -279,43 +231,6 @@ class utList extends UnitTestCase
$this->assertTrue(isset($this->list[1]));
$this->assertFalse(isset($this->list[2]));
}
-
- public function testDerivedClasses()
- {
- $newList=new NewList;
- $this->assertFalse($newList->isItemAdded());
- $newList->add($this->item1);
- $this->assertTrue($newList->isItemAdded());
- $newList->add($this->item2);
-
- $newList->setCanAddItem(false);
- try
- {
- $newList->add($this->item3);
- $this->fail('no exception raised when adding an item that is disallowed');
- }
- catch(TInvalidOperationException $e)
- {
- $this->assertEqual(2,$newList->getCount());
- $this->pass();
- }
-
- $this->assertFalse($newList->isItemRemoved());
- $newList->remove($this->item1);
- $this->assertTrue($newList->isItemRemoved());
-
- $newList->setCanRemoveItem(false);
- try
- {
- $newList->remove($this->item2);
- $this->fail('no exception raised when removing an item that is disallowed');
- }
- catch(TInvalidOperationException $e)
- {
- $this->assertEqual(1,$newList->getCount());
- $this->pass();
- }
- }
}
?> \ No newline at end of file
diff --git a/tests/UnitTests/framework/Collections/utMap.php b/tests/UnitTests/framework/Collections/utMap.php
index 1f7a20ad..37818542 100644
--- a/tests/UnitTests/framework/Collections/utMap.php
+++ b/tests/UnitTests/framework/Collections/utMap.php
@@ -7,54 +7,6 @@ class MapItem
public $data='data';
}
-class NewMap extends TMap
-{
- private $_canAddItem=true;
- private $_canRemoveItem=true;
- private $_itemAdded=false;
- private $_itemRemoved=false;
-
- protected function addedItem($key,$value)
- {
- $this->_itemAdded=true;
- }
-
- protected function removedItem($key,$value)
- {
- $this->_itemRemoved=true;
- }
-
- protected function canAddItem($key,$value)
- {
- return $this->_canAddItem;
- }
-
- protected function canRemoveItem($key,$value)
- {
- return $this->_canRemoveItem;
- }
-
- public function setCanAddItem($value)
- {
- $this->_canAddItem=$value;
- }
-
- public function setCanRemoveItem($value)
- {
- $this->_canRemoveItem=$value;
- }
-
- public function isItemAdded()
- {
- return $this->_itemAdded;
- }
-
- public function isItemRemoved()
- {
- return $this->_itemRemoved;
- }
-}
-
class utMap extends UnitTestCase
{
protected $map;
@@ -203,43 +155,6 @@ class utMap extends UnitTestCase
$this->assertTrue(isset($this->map['key1']));
$this->assertFalse(isset($this->map['unknown key']));
}
-
- public function testDerivedClasses()
- {
- $newMap=new NewMap;
- $this->assertFalse($newMap->isItemAdded());
- $newMap->add('key','value');
- $this->assertTrue($newMap->isItemAdded());
- $newMap->add('key2','value2');
-
- $newMap->setCanAddItem(false);
- try
- {
- $newMap->add('new key','new value');
- $this->fail('no exception raised when adding an item that is disallowed');
- }
- catch(TInvalidOperationException $e)
- {
- $this->assertEqual(2,$newMap->getCount());
- $this->pass();
- }
-
- $this->assertFalse($newMap->isItemRemoved());
- $newMap->remove('key');
- $this->assertTrue($newMap->isItemRemoved());
-
- $newMap->setCanRemoveItem(false);
- try
- {
- $newMap->remove('key2');
- $this->fail('no exception raised when removing an item that is disallowed');
- }
- catch(TInvalidOperationException $e)
- {
- $this->assertEqual(1,$newMap->getCount());
- $this->pass();
- }
- }
}
?> \ No newline at end of file
diff --git a/tests/unit/Collections/TListTest.php b/tests/unit/Collections/TListTest.php
index 3dacb701..a64e9da2 100644
--- a/tests/unit/Collections/TListTest.php
+++ b/tests/unit/Collections/TListTest.php
@@ -6,61 +6,13 @@ class ListItem
public $data='data';
}
-class NewList extends TList
-{
- private $_canAddItem=true;
- private $_canRemoveItem=true;
- private $_itemAdded=false;
- private $_itemRemoved=false;
-
- protected function addedItem($item)
- {
- $this->_itemAdded=true;
- }
-
- protected function removedItem($item)
- {
- $this->_itemRemoved=true;
- }
-
- protected function canAddItem($item)
- {
- return $this->_canAddItem;
- }
-
- protected function canRemoveItem($item)
- {
- return $this->_canRemoveItem;
- }
-
- public function setCanAddItem($value)
- {
- $this->_canAddItem=$value;
- }
-
- public function setCanRemoveItem($value)
- {
- $this->_canRemoveItem=$value;
- }
-
- public function isItemAdded()
- {
- return $this->_itemAdded;
- }
-
- public function isItemRemoved()
- {
- return $this->_itemRemoved;
- }
-}
-
/**
* @package System.Collections
*/
class TListTest extends PHPUnit2_Framework_TestCase {
protected $list;
protected $item1,$item2,$item3;
-
+
public function setUp() {
$this->list=new TList;
$this->item1=new ListItem;
@@ -69,14 +21,14 @@ class TListTest extends PHPUnit2_Framework_TestCase {
$this->list->add($this->item1);
$this->list->add($this->item2);
}
-
+
public function tearDown() {
$this->list=null;
$this->item1=null;
$this->item2=null;
$this->item3=null;
}
-
+
public function testConstruct() {
$a=array(1,2,3);
$list=new TList($a);
@@ -89,7 +41,7 @@ class TListTest extends PHPUnit2_Framework_TestCase {
$this->assertEquals(2,$this->list->getCount());
$this->assertEquals(2,$this->list->Count);
}
-
+
public function testAdd() {
$this->list->add(null);
$this->list->add($this->item3);
@@ -107,10 +59,10 @@ class TListTest extends PHPUnit2_Framework_TestCase {
$this->list->insert(4,$this->item3);
$this->fail('exception not raised when adding item at an out-of-range index');
} catch(TInvalidDataValueException $e) {
-
+
}
}
-
+
public function testRemove() {
$this->list->remove($this->item1);
$this->assertEquals(1,$this->list->getCount());
@@ -120,10 +72,10 @@ class TListTest extends PHPUnit2_Framework_TestCase {
$this->list->remove($this->item1);
$this->fail('exception not raised when removing nonexisting item');
} catch(Exception $e) {
-
+
}
}
-
+
public function testRemoveAt() {
$this->list->add($this->item3);
$this->list->removeAt(1);
@@ -134,17 +86,17 @@ class TListTest extends PHPUnit2_Framework_TestCase {
$this->list->removeAt(2);
$this->fail('exception not raised when removing item with invalid index');
} catch(TInvalidDataValueException $e) {
-
+
}
}
-
+
public function testClear() {
$this->list->clear();
$this->assertEquals(0,$this->list->getCount());
$this->assertEquals(-1,$this->list->indexOf($this->item1));
$this->assertEquals(-1,$this->list->indexOf($this->item2));
}
-
+
public function testContains() {
$this->assertTrue($this->list->contains($this->item1));
$this->assertTrue($this->list->contains($this->item2));
@@ -165,7 +117,7 @@ class TListTest extends PHPUnit2_Framework_TestCase {
$this->list->copyFrom($this);
$this->fail('exception not raised when copying from non-traversable object');
} catch(TInvalidDataTypeException $e) {
-
+
}
}
@@ -177,15 +129,15 @@ class TListTest extends PHPUnit2_Framework_TestCase {
$this->list->mergeWith($this);
$this->fail('exception not raised when copying from non-traversable object');
} catch(TInvalidDataTypeException $e) {
-
+
}
}
-
+
public function testToArray() {
$array=$this->list->toArray();
$this->assertTrue(count($array)==2 && $array[0]===$this->item1 && $array[1]===$this->item2);
}
-
+
public function testArrayRead() {
$this->assertTrue($this->list[0]===$this->item1);
$this->assertTrue($this->list[1]===$this->item2);
@@ -193,10 +145,10 @@ class TListTest extends PHPUnit2_Framework_TestCase {
$a=$this->list[2];
$this->fail('exception not raised when accessing item with out-of-range index');
} catch(TInvalidDataValueException $e) {
-
+
}
}
-
+
/*public function testArrayWrite() {
$this->list[]=$this->item3;
$this->assertTrue($this->list[2]===$this->item3 && $this->list->getCount()===3);
@@ -208,16 +160,16 @@ class TListTest extends PHPUnit2_Framework_TestCase {
$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;
@@ -231,40 +183,12 @@ class TListTest extends PHPUnit2_Framework_TestCase {
}
$this->assertTrue($n==2 && $found==2);
}
-
+
public function testArrayMisc() {
$this->assertEquals(1,count($this->list));
$this->assertTrue(isset($this->list[1]));
$this->assertFalse(isset($this->list[2]));
}
-
- public function testDerivedClasses() {
- $newList=new NewList;
- $this->assertFalse($newList->isItemAdded());
- $newList->add($this->item1);
- $this->assertTrue($newList->isItemAdded());
- $newList->add($this->item2);
-
- $newList->setCanAddItem(false);
- try {
- $newList->add($this->item3);
- $this->fail('no exception raised when adding an item that is disallowed');
- } catch(TInvalidOperationException $e) {
- $this->assertEquals(2,$newList->getCount());
- }
-
- $this->assertFalse($newList->isItemRemoved());
- $newList->remove($this->item1);
- $this->assertTrue($newList->isItemRemoved());
-
- $newList->setCanRemoveItem(false);
- try {
- $newList->remove($this->item2);
- $this->fail('no exception raised when removing an item that is disallowed');
- } catch(TInvalidOperationException $e) {
- $this->assertEquals(1,$newList->getCount());
- }
- }
}
diff --git a/tests/unit/Collections/TMapTest.php b/tests/unit/Collections/TMapTest.php
index a6f82570..af92fd6a 100644
--- a/tests/unit/Collections/TMapTest.php
+++ b/tests/unit/Collections/TMapTest.php
@@ -5,61 +5,13 @@ class MapItem {
public $data='data';
}
-class NewMap extends TMap
-{
- private $_canAddItem=true;
- private $_canRemoveItem=true;
- private $_itemAdded=false;
- private $_itemRemoved=false;
-
- protected function addedItem($key,$value)
- {
- $this->_itemAdded=true;
- }
-
- protected function removedItem($key,$value)
- {
- $this->_itemRemoved=true;
- }
-
- protected function canAddItem($key,$value)
- {
- return $this->_canAddItem;
- }
-
- protected function canRemoveItem($key,$value)
- {
- return $this->_canRemoveItem;
- }
-
- public function setCanAddItem($value)
- {
- $this->_canAddItem=$value;
- }
-
- public function setCanRemoveItem($value)
- {
- $this->_canRemoveItem=$value;
- }
-
- public function isItemAdded()
- {
- return $this->_itemAdded;
- }
-
- public function isItemRemoved()
- {
- return $this->_itemRemoved;
- }
-}
-
/**
* @package System.Collections
*/
class TMapTest extends PHPUnit2_Framework_TestCase {
protected $map;
protected $item1,$item2,$item3;
-
+
public function setUp() {
$this->map=new TMap;
$this->item1=new MapItem;
@@ -75,7 +27,7 @@ class TMapTest extends PHPUnit2_Framework_TestCase {
$this->item2=null;
$this->item3=null;
}
-
+
public function testConstruct() {
$a=array(1,2,'key3'=>3);
$map=new TMap($a);
@@ -87,7 +39,7 @@ class TMapTest extends PHPUnit2_Framework_TestCase {
public function testGetCount() {
$this->assertEquals(2,$this->map->getCount());
}
-
+
public function testGetKeys() {
$keys=$this->map->getKeys();
$this->assertTrue(count($keys)===2 && $keys[0]==='key1' && $keys[1]==='key2');
@@ -131,7 +83,7 @@ class TMapTest extends PHPUnit2_Framework_TestCase {
}
catch(TInvalidDataTypeException $e)
{
-
+
}
}
@@ -147,7 +99,7 @@ class TMapTest extends PHPUnit2_Framework_TestCase {
}
catch(TInvalidDataTypeException $e)
{
-
+
}
}
@@ -169,7 +121,7 @@ class TMapTest extends PHPUnit2_Framework_TestCase {
try
{
unset($this->map['unknown key']);
-
+
}
catch(Exception $e)
{
@@ -198,42 +150,6 @@ class TMapTest extends PHPUnit2_Framework_TestCase {
$this->assertTrue(isset($this->map['key1']));
$this->assertFalse(isset($this->map['unknown key']));
}
-
- public function testDerivedClasses()
- {
- $newMap=new NewMap;
- $this->assertFalse($newMap->isItemAdded());
- $newMap->add('key','value');
- $this->assertTrue($newMap->isItemAdded());
- $newMap->add('key2','value2');
-
- $newMap->setCanAddItem(false);
- try
- {
- $newMap->add('new key','new value');
- $this->fail('no exception raised when adding an item that is disallowed');
- }
- catch(TInvalidOperationException $e)
- {
- $this->assertEquals(2,$newMap->getCount());
-
- }
-
- $this->assertFalse($newMap->isItemRemoved());
- $newMap->remove('key');
- $this->assertTrue($newMap->isItemRemoved());
-
- $newMap->setCanRemoveItem(false);
- try
- {
- $newMap->remove('key2');
- $this->fail('no exception raised when removing an item that is disallowed');
- }
- catch(TInvalidOperationException $e)
- {
- $this->assertEquals(1,$newMap->getCount());
- }
- }
}
?> \ No newline at end of file