diff options
Diffstat (limited to 'tests/UnitTests/framework/Collections')
-rw-r--r-- | tests/UnitTests/framework/Collections/utList.php | 236 | ||||
-rw-r--r-- | tests/UnitTests/framework/Collections/utMap.php | 160 |
2 files changed, 0 insertions, 396 deletions
diff --git a/tests/UnitTests/framework/Collections/utList.php b/tests/UnitTests/framework/Collections/utList.php deleted file mode 100644 index e95f718b..00000000 --- a/tests/UnitTests/framework/Collections/utList.php +++ /dev/null @@ -1,236 +0,0 @@ -<?php
-
-require_once(dirname(__FILE__).'/../common.php');
-
-class ListItem
-{
- public $data='data';
-}
-
-class utList extends UnitTestCase
-{
- protected $list;
- protected $item1,$item2,$item3;
-
- public function setUp()
- {
- $this->list=new TList;
- $this->item1=new ListItem;
- $this->item2=new ListItem;
- $this->item3=new ListItem;
- $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);
- $this->assertEqual(3,$list->getCount());
- $list2=new TList($this->list);
- $this->assertEqual(2,$list2->getCount());
- }
- public function testGetCount()
- {
- $this->assertEqual(2,$this->list->getCount());
- $this->assertEqual(2,$this->list->Count);
- }
-
- public function testAdd()
- {
- $this->list->add(null);
- $this->list->add($this->item3);
- $this->assertEqual(4,$this->list->getCount());
- $this->assertEqual(3,$this->list->indexOf($this->item3));
- }
-
-
- public function testInsertAt()
- {
- $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->insertAt(4,$this->item3);
- $this->fail('exception not raised when adding item at an out-of-range index');
- }
- catch(TInvalidDataValueException $e)
- {
- $this->pass();
- }
- }
-
- public function testRemove()
- {
- $this->list->remove($this->item1);
- $this->assertEqual(1,$this->list->getCount());
- $this->assertEqual(-1,$this->list->indexOf($this->item1));
- $this->assertEqual(0,$this->list->indexOf($this->item2));
- try
- {
- $this->list->remove($this->item1);
- $this->fail('exception not raised when removing nonexisting item');
- }
- catch(Exception $e)
- {
- $this->pass();
- }
- }
-
- public function testRemoveAt()
- {
- $this->list->add($this->item3);
- $this->list->removeAt(1);
- $this->assertEqual(-1,$this->list->indexOf($this->item2));
- $this->assertEqual(1,$this->list->indexOf($this->item3));
- $this->assertEqual(0,$this->list->indexOf($this->item1));
- try
- {
- $this->list->removeAt(2);
- $this->fail('exception not raised when removing item with invalid index');
- }
- catch(TInvalidDataValueException $e)
- {
- $this->pass();
- }
- }
-
- public function testClear()
- {
- $this->list->clear();
- $this->assertEqual(0,$this->list->getCount());
- $this->assertEqual(-1,$this->list->indexOf($this->item1));
- $this->assertEqual(-1,$this->list->indexOf($this->item2));
- }
-
- public function testContains()
- {
- $this->assertTrue($this->list->contains($this->item1));
- $this->assertTrue($this->list->contains($this->item2));
- $this->assertFalse($this->list->contains($this->item3));
- }
-
- public function testIndexOf()
- {
- $this->assertEqual(0,$this->list->indexOf($this->item1));
- $this->assertEqual(1,$this->list->indexOf($this->item2));
- $this->assertEqual(-1,$this->list->indexOf($this->item3));
- }
-
- public function testCopyFrom()
- {
- $array=array($this->item3,$this->item1);
- $this->list->copyFrom($array);
- $this->assertTrue(count($array)==2 && $this->list[0]===$this->item3 && $this->list[1]===$this->item1);
- try
- {
- $this->list->copyFrom($this);
- $this->fail('exception not raised when copying from non-traversable object');
- }
- catch(TInvalidDataTypeException $e)
- {
- $this->pass();
- }
- }
-
- public function testMergeWith()
- {
- $array=array($this->item3,$this->item1);
- $this->list->mergeWith($array);
- $this->assertTrue($this->list->getCount()==4 && $this->list[0]===$this->item1 && $this->list[3]===$this->item1);
- try
- {
- $this->list->mergeWith($this);
- $this->fail('exception not raised when copying from non-traversable object');
- }
- catch(TInvalidDataTypeException $e)
- {
- $this->pass();
- }
- }
-
- 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);
- try
- {
- $a=$this->list[2];
- $this->fail('exception not raised when accessing item with out-of-range index');
- }
- catch(TInvalidDataValueException $e)
- {
- $this->pass();
- }
- }
-
- 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)
- {
- $this->pass();
- }
- try
- {
- unset($this->list[5]);
- $this->fail('exception not raised when unsetting item at an out-of-range index');
- }
- catch(TInvalidDataValueException $e)
- {
- $this->pass();
- }
- }
-
- public function testGetIterator()
- {
- $n=0;
- $found=0;
- foreach($this->list as $index=>$item)
- {
- foreach($this->list as $a=>$b); // test of iterator
- $n++;
- if($index===0 && $item===$this->item1)
- $found++;
- if($index===1 && $item===$this->item2)
- $found++;
- }
- $this->assertTrue($n==2 && $found==2);
- }
-
- public function testArrayMisc()
- {
- $this->assertEqual(1,count($this->list));
- $this->assertTrue(isset($this->list[1]));
- $this->assertFalse(isset($this->list[2]));
- }
-}
-
-?>
\ No newline at end of file diff --git a/tests/UnitTests/framework/Collections/utMap.php b/tests/UnitTests/framework/Collections/utMap.php deleted file mode 100644 index 37818542..00000000 --- a/tests/UnitTests/framework/Collections/utMap.php +++ /dev/null @@ -1,160 +0,0 @@ -<?php
-
-require_once(dirname(__FILE__).'/../common.php');
-
-class MapItem
-{
- public $data='data';
-}
-
-class utMap extends UnitTestCase
-{
- protected $map;
- protected $item1,$item2,$item3;
-
- public function setUp()
- {
- $this->map=new TMap;
- $this->item1=new MapItem;
- $this->item2=new MapItem;
- $this->item3=new MapItem;
- $this->map->add('key1',$this->item1);
- $this->map->add('key2',$this->item2);
- }
-
- public function tearDown()
- {
- $this->map=null;
- $this->item1=null;
- $this->item2=null;
- $this->item3=null;
- }
-
- public function testConstruct()
- {
- $a=array(1,2,'key3'=>3);
- $map=new TMap($a);
- $this->assertEqual(3,$map->getCount());
- $map2=new TMap($this->map);
- $this->assertEqual(2,$map2->getCount());
- }
-
- public function testGetCount()
- {
- $this->assertEqual(2,$this->map->getCount());
- }
-
- public function testGetKeys()
- {
- $keys=$this->map->getKeys();
- $this->assertTrue(count($keys)===2 && $keys[0]==='key1' && $keys[1]==='key2');
- }
-
- public function testAdd()
- {
- $this->map->add('key3',$this->item3);
- $this->assertTrue($this->map->getCount()==3 && $this->map->contains('key3'));
- }
-
- public function testRemove()
- {
- $this->map->remove('key1');
- $this->assertTrue($this->map->getCount()==1 && !$this->map->contains('key1'));
- $this->assertTrue($this->map->remove('unknown key')===null);
- }
-
- public function testClear()
- {
- $this->map->clear();
- $this->assertTrue($this->map->getCount()==0 && !$this->map->contains('key1') && !$this->map->contains('key2'));
- }
-
- public function testContains()
- {
- $this->assertTrue($this->map->contains('key1'));
- $this->assertTrue($this->map->contains('key2'));
- $this->assertFalse($this->map->contains('key3'));
- }
-
- public function testCopyFrom()
- {
- $array=array('key3'=>$this->item3,'key4'=>$this->item1);
- $this->map->copyFrom($array);
- $this->assertTrue($this->map->getCount()==2 && $this->map['key3']===$this->item3 && $this->map['key4']===$this->item1);
- try
- {
- $this->map->copyFrom($this);
- $this->fail('no exception raised when copying a non-traversable object');
- }
- catch(TInvalidDataTypeException $e)
- {
- $this->pass();
- }
- }
-
- public function testMergeWith()
- {
- $array=array('key2'=>$this->item1,'key3'=>$this->item3);
- $this->map->mergeWith($array);
- $this->assertTrue($this->map->getCount()==3 && $this->map['key2']===$this->item1 && $this->map['key3']===$this->item3);
- try
- {
- $this->map->mergeWith($this);
- $this->fail('no exception raised when copying a non-traversable object');
- }
- catch(TInvalidDataTypeException $e)
- {
- $this->pass();
- }
- }
-
- public function testArrayRead()
- {
- $this->assertTrue($this->map['key1']===$this->item1);
- $this->assertTrue($this->map['key2']===$this->item2);
- $this->assertEqual(null,$this->map['key3']);
- }
-
- public function testArrayWrite()
- {
- $this->map['key3']=$this->item3;
- $this->assertTrue($this->map['key3']===$this->item3 && $this->map->getCount()===3);
- $this->map['key1']=$this->item3;
- $this->assertTrue($this->map['key1']===$this->item3 && $this->map->getCount()===3);
- unset($this->map['key2']);
- $this->assertTrue($this->map->getCount()===2 && !$this->map->contains('key2'));
- try
- {
- unset($this->map['unknown key']);
- $this->pass();
- }
- catch(Exception $e)
- {
- $this->fail('exception raised when unsetting element with unknown key');
- }
- }
-
- public function testArrayForeach()
- {
- $n=0;
- $found=0;
- foreach($this->map as $index=>$item)
- {
- $n++;
- if($index==='key1' && $item===$this->item1)
- $found++;
- if($index==='key2' && $item===$this->item2)
- $found++;
- }
- $this->assertTrue($n==2 && $found==2);
- }
-
- public function testArrayMisc()
- {
- $this->assertEqual(1,count($this->map));
- $this->assertTrue(isset($this->map['key1']));
- $this->assertFalse(isset($this->map['unknown key']));
- }
-}
-
-?>
\ No newline at end of file |