diff options
author | Fabio Bas <ctrlaltca@gmail.com> | 2014-01-15 19:05:25 +0100 |
---|---|---|
committer | Fabio Bas <ctrlaltca@gmail.com> | 2014-08-23 12:30:22 +0200 |
commit | 9733613002b664ec9cbdc6dec9d6fd57ee901f1e (patch) | |
tree | ca20722ae61a4ff9046c58cef4d2e374801800da /tests/unit/Collections | |
parent | 21a909f819cc340564770ea63e383ee6013fc167 (diff) |
Removed ?> from tests
Diffstat (limited to 'tests/unit/Collections')
-rw-r--r-- | tests/unit/Collections/AllTests.php | 7 | ||||
-rw-r--r-- | tests/unit/Collections/TAttributeCollectionTest.php | 19 | ||||
-rw-r--r-- | tests/unit/Collections/TListTest.php | 68 | ||||
-rw-r--r-- | tests/unit/Collections/TMapTest.php | 3 | ||||
-rw-r--r-- | tests/unit/Collections/TPagedDataSourceTest.php | 25 | ||||
-rw-r--r-- | tests/unit/Collections/TPagedListTest.php | 53 | ||||
-rw-r--r-- | tests/unit/Collections/TPriorityMapTest.php | 161 | ||||
-rw-r--r-- | tests/unit/Collections/TQueueTest.php | 13 | ||||
-rw-r--r-- | tests/unit/Collections/TStackTest.php | 13 |
9 files changed, 176 insertions, 186 deletions
diff --git a/tests/unit/Collections/AllTests.php b/tests/unit/Collections/AllTests.php index f290be31..3c286132 100644 --- a/tests/unit/Collections/AllTests.php +++ b/tests/unit/Collections/AllTests.php @@ -16,10 +16,10 @@ class Collections_AllTests { public static function main() { PHPUnit_TextUI_TestRunner::run(self::suite()); } - + public static function suite() { $suite = new PHPUnit_Framework_TestSuite('System.Collections'); - + $suite->addTestSuite('TListTest'); $suite->addTestSuite('TMapTest'); $suite->addTestSuite('TQueueTest'); @@ -27,7 +27,7 @@ class Collections_AllTests { $suite->addTestSuite('TAttributeCollectionTest'); $suite->addTestSuite('TPagedListTest'); $suite->addTestSuite('TPagedDataSourceTest'); - + return $suite; } } @@ -35,4 +35,3 @@ class Collections_AllTests { if(PHPUnit_MAIN_METHOD == 'Collections_AllTests::main') { Collections_AllTests::main(); } -?> diff --git a/tests/unit/Collections/TAttributeCollectionTest.php b/tests/unit/Collections/TAttributeCollectionTest.php index 5805f2d0..f61f58b3 100644 --- a/tests/unit/Collections/TAttributeCollectionTest.php +++ b/tests/unit/Collections/TAttributeCollectionTest.php @@ -19,7 +19,7 @@ class TAttributeCollectionTest extends PHPUnit_Framework_TestCase { self::assertEquals('value', $collection->Property); self::assertEquals(true, $collection->canGetProperty('Property')); } - + public function testCanNotGetUndefinedProperty() { $collection = new TAttributeCollection(array(), true); self::assertEquals(false, $collection->canGetProperty('Property')); @@ -37,7 +37,7 @@ class TAttributeCollectionTest extends PHPUnit_Framework_TestCase { self::assertEquals('value', $collection->itemAt('Property')); self::assertEquals(true, $collection->canSetProperty('Property')); } - + public function testCanNotSetPropertyIfReadOnly() { $collection = new TAttributeCollection(array(), true); try { @@ -47,7 +47,7 @@ class TAttributeCollectionTest extends PHPUnit_Framework_TestCase { } self::fail('An expected TInvalidOperationException was not raised'); } - + public function testGetCaseSensitive() { $collection = new TAttributeCollection(); $collection->setCaseSensitive(false); @@ -55,40 +55,40 @@ class TAttributeCollectionTest extends PHPUnit_Framework_TestCase { $collection->setCaseSensitive(true); self::assertEquals(true, $collection->getCaseSensitive()); } - + public function testSetCaseSensitive() { $collection = new TAttributeCollection(); $collection->Property = 'value'; $collection->setCaseSensitive(false); self::assertEquals('value', $collection->itemAt('property')); } - + public function testItemAt() { $collection = new TAttributeCollection(); $collection->Property = 'value'; self::assertEquals('value', $collection->itemAt('Property')); } - + public function testAdd() { $collection = new TAttributeCollection(); $collection->add('Property', 'value'); self::assertEquals('value', $collection->itemAt('Property')); } - + public function testRemove() { $collection = new TAttributeCollection(); $collection->add('Property', 'value'); $collection->remove('Property'); self::assertEquals(0, count($collection)); } - + public function testContains() { $collection = new TAttributeCollection(); self::assertEquals(false, $collection->contains('Property')); $collection->Property = 'value'; self::assertEquals(true, $collection->contains('Property')); } - + public function testHasProperty() { $collection = new TAttributeCollection(); self::assertEquals(false, $collection->hasProperty('Property')); @@ -98,4 +98,3 @@ class TAttributeCollectionTest extends PHPUnit_Framework_TestCase { } -?> diff --git a/tests/unit/Collections/TListTest.php b/tests/unit/Collections/TListTest.php index 349d87ed..9d6950b9 100644 --- a/tests/unit/Collections/TListTest.php +++ b/tests/unit/Collections/TListTest.php @@ -8,7 +8,7 @@ class ListItem { * @package System.Collections */ class TListTest extends PHPUnit_Framework_TestCase { - + protected $list; protected $item1, $item2, $item3, $item4; @@ -21,7 +21,7 @@ class TListTest extends PHPUnit_Framework_TestCase { $this->list->add($this->item1); $this->list->add($this->item2); } - + public function tearDown() { $this->list=null; $this->item1=null; @@ -29,7 +29,7 @@ class TListTest extends PHPUnit_Framework_TestCase { $this->item3=null; $this->item4=null; } - + public function testConstruct() { $a=array(1,2,3); $list=new TList($a); @@ -37,19 +37,19 @@ class TListTest extends PHPUnit_Framework_TestCase { $list2=new TList($this->list); $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); } - + public function testItemAt() { $this->assertTrue($this->list->itemAt(0) === $this->item1); $this->assertTrue($this->list->itemAt(1) === $this->item2); @@ -59,14 +59,14 @@ class TListTest extends PHPUnit_Framework_TestCase { } catch(TInvalidDataValueException $e) { } } - + public function testAdd() { $this->assertEquals(2,$this->list->add(null)); $this->assertEquals(3,$this->list->add($this->item3)); $this->assertEquals(4,$this->list->getCount()); $this->assertEquals(3,$this->list->indexOf($this->item3)); } - + public function testCanNotAddWhenReadOnly() { $list = new TList(array(), true); try { @@ -75,7 +75,7 @@ class TListTest extends PHPUnit_Framework_TestCase { } catch(TInvalidOperationException $e) { } } - + public function testInsertAt() { $this->assertNull($this->list->insertAt(0,$this->item3)); $this->assertEquals(3,$this->list->getCount()); @@ -88,7 +88,7 @@ class TListTest extends PHPUnit_Framework_TestCase { } catch(TInvalidDataValueException $e) { } } - + public function testCanNotInsertAtWhenReadOnly() { $list = new TList(array(), true); try { @@ -102,7 +102,7 @@ class TListTest extends PHPUnit_Framework_TestCase { } catch(TInvalidOperationException $e) { } } - + public function testInsertBefore() { try { $this->list->insertBefore($this->item4,$this->item3); @@ -116,7 +116,7 @@ class TListTest extends PHPUnit_Framework_TestCase { $this->assertEquals(1,$this->list->indexOf($this->item1)); $this->assertEquals(2,$this->list->indexOf($this->item2)); } - + public function testCanNotInsertBeforeWhenReadOnly() { $list = new TList(array(5), true); try { @@ -130,7 +130,7 @@ class TListTest extends PHPUnit_Framework_TestCase { } catch(TInvalidOperationException $e) { } } - + public function testInsertAfter() { try { $this->list->insertAfter($this->item4,$this->item3); @@ -144,7 +144,7 @@ class TListTest extends PHPUnit_Framework_TestCase { $this->assertEquals(1,$this->list->indexOf($this->item2)); $this->assertEquals(2,$this->list->indexOf($this->item3)); } - + public function testCanNotInsertAfterWhenReadOnly() { $list = new TList(array(5), true); try { @@ -158,7 +158,7 @@ class TListTest extends PHPUnit_Framework_TestCase { } catch(TInvalidOperationException $e) { } } - + public function testRemove() { $this->assertEquals(0,$this->list->remove($this->item1)); $this->assertEquals(1,$this->list->getCount()); @@ -170,7 +170,7 @@ class TListTest extends PHPUnit_Framework_TestCase { } catch(Exception $e) { } } - + public function testCanNotRemoveWhenReadOnly() { $list = new TList(array(1, 2, 3), true); try { @@ -178,7 +178,7 @@ class TListTest extends PHPUnit_Framework_TestCase { self::fail('An expected TInvalidOperationException was not raised'); } catch(TInvalidOperationException $e) { } - + $list = new TList(array(1, 2, 3), true); try { $list->remove(10); @@ -186,7 +186,7 @@ class TListTest extends PHPUnit_Framework_TestCase { } catch(TInvalidOperationException $e) { } } - + public function testRemoveAt() { $this->list->add($this->item3); $this->assertEquals($this->item2, $this->list->removeAt(1)); @@ -199,7 +199,7 @@ class TListTest extends PHPUnit_Framework_TestCase { } catch(TInvalidDataValueException $e) { } } - + public function testCanNotRemoveAtWhenReadOnly() { $list = new TList(array(1, 2, 3), true); try { @@ -207,7 +207,7 @@ class TListTest extends PHPUnit_Framework_TestCase { self::fail('An expected TInvalidOperationException was not raised'); } catch(TInvalidOperationException $e) { } - + $list = new TList(array(1, 2, 3), true); try { $list->removeAt(10); @@ -215,14 +215,14 @@ class TListTest extends PHPUnit_Framework_TestCase { } catch(TInvalidOperationException $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 testCanNotClearWhenReadOnly() { $list = new TList(array(1, 2, 3), true); try { @@ -232,19 +232,19 @@ class TListTest extends PHPUnit_Framework_TestCase { } self::fail('An expected TInvalidOperationException was not raised'); } - + 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->assertEquals(0,$this->list->indexOf($this->item1)); $this->assertEquals(1,$this->list->indexOf($this->item2)); $this->assertEquals(-1,$this->list->indexOf($this->item3)); } - + public function testCopyFrom() { $array=array($this->item3,$this->item1); $this->list->copyFrom($array); @@ -255,7 +255,7 @@ class TListTest extends PHPUnit_Framework_TestCase { } catch(TInvalidDataTypeException $e) { } } - + public function testMergeWith() { $array=array($this->item3,$this->item1); $this->list->mergeWith($array); @@ -266,12 +266,12 @@ class TListTest extends PHPUnit_Framework_TestCase { } 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); @@ -281,7 +281,7 @@ class TListTest extends PHPUnit_Framework_TestCase { } catch(TInvalidDataValueException $e) { } } - + public function testGetIterator() { $n=0; $found=0; @@ -295,25 +295,25 @@ class TListTest extends PHPUnit_Framework_TestCase { } $this->assertTrue($n==2 && $found==2); } - + public function testArrayMisc() { $this->assertEquals($this->list->Count,count($this->list)); $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); @@ -321,5 +321,3 @@ class TListTest extends PHPUnit_Framework_TestCase { } } - -?>
\ No newline at end of file diff --git a/tests/unit/Collections/TMapTest.php b/tests/unit/Collections/TMapTest.php index 0634a2a3..da198eb4 100644 --- a/tests/unit/Collections/TMapTest.php +++ b/tests/unit/Collections/TMapTest.php @@ -176,11 +176,10 @@ 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()); } } -?> diff --git a/tests/unit/Collections/TPagedDataSourceTest.php b/tests/unit/Collections/TPagedDataSourceTest.php index 92f4061b..ebb8e60d 100644 --- a/tests/unit/Collections/TPagedDataSourceTest.php +++ b/tests/unit/Collections/TPagedDataSourceTest.php @@ -16,55 +16,54 @@ class TPagedDataSourceTest extends PHPUnit_Framework_TestCase { public function testDataSource() { throw new PHPUnit_Framework_IncompleteTestError(); } - + public function testPageSize() { throw new PHPUnit_Framework_IncompleteTestError(); } - + public function testCurrentPageIndex() { throw new PHPUnit_Framework_IncompleteTestError(); } - + public function testAllowPaging() { throw new PHPUnit_Framework_IncompleteTestError(); } - + public function testAllowCustomPaging() { throw new PHPUnit_Framework_IncompleteTestError(); } - + public function testVirtualItemCount() { throw new PHPUnit_Framework_IncompleteTestError(); } - + public function testCount() { throw new PHPUnit_Framework_IncompleteTestError(); } - + public function testPageCount() { throw new PHPUnit_Framework_IncompleteTestError(); } - + public function testIsFirstPage() { throw new PHPUnit_Framework_IncompleteTestError(); } - + public function testIsLastPage() { throw new PHPUnit_Framework_IncompleteTestError(); } - + public function testFirstIndexInPage() { throw new PHPUnit_Framework_IncompleteTestError(); } - + public function testDataSourceCount() { throw new PHPUnit_Framework_IncompleteTestError(); } - + public function testIterator() { throw new PHPUnit_Framework_IncompleteTestError(); } } -?> diff --git a/tests/unit/Collections/TPagedListTest.php b/tests/unit/Collections/TPagedListTest.php index 2d884736..a225db61 100644 --- a/tests/unit/Collections/TPagedListTest.php +++ b/tests/unit/Collections/TPagedListTest.php @@ -3,26 +3,26 @@ Prado::using('System.Collections.TPagedList'); class MyPagedList extends TPagedList { - + private $_isPageIndexChanged = false; private $_hasFetchedData = false; - + public function pageIndexChanged($sender, $param) { $this->_isPageIndexChanged = true; } - + public function fetchData($sender, $param) { $this->_hasFetchedData = true; } - + public function isPageIndexChanged() { return $this->_isPageIndexChanged; } - + public function hasFetchedData() { return $this->_hasFetchedData; } - + } /** @@ -58,7 +58,7 @@ class TPagedListTest extends PHPUnit_Framework_TestCase { $list->PageSize = 5; self::assertEquals(5, $list->PageSize); } - + public function testCanNotSetInvalidPageSize() { $list = new TPagedList(); try { @@ -68,14 +68,14 @@ class TPagedListTest extends PHPUnit_Framework_TestCase { } self::fail('An expected TInvalidDataValueException was not raised'); } - + public function testCurrentPageIndex() { $list = new TPagedList(array(1, 2, 3)); $list->PageSize = 1; $list->CurrentPageIndex = 2; self::assertEquals(2, $list->CurrentPageIndex); } - + public function testOnPageIndexChanged() { $list = new TPagedList(array(1, 2, 3, 4, 5)); $list->PageSize = 1; @@ -87,7 +87,7 @@ class TPagedListTest extends PHPUnit_Framework_TestCase { $list->onPageIndexChanged(new TPagedListPageChangedEventParameter($oldPage)); self::assertEquals(true, $myList->isPageIndexChanged()); } - + public function testOnFetchData() { $list = new TPagedList(array(1, 2, 3, 4)); $list->CustomPaging = true; @@ -95,18 +95,18 @@ class TPagedListTest extends PHPUnit_Framework_TestCase { $list->gotoPage(0); $myList = new MyPagedList(); $list->attachEventHandler('OnFetchData', array($myList, 'fetchData')); - self::assertEquals(false, $myList->hasFetchedData()); + self::assertEquals(false, $myList->hasFetchedData()); $list->onFetchData(new TPagedListFetchDataEventParameter($list->CurrentPageIndex, $list->PageSize*$list->CurrentPageIndex, $list->PageSize)); self::assertEquals(true, $myList->hasFetchedData()); } - + public function testGotoPage() { $list = new TPagedList(array(1, 2, 3)); $list->PageSize = 1; self::assertEquals(2, $list->gotoPage(2)); self::assertEquals(false, $list->gotoPage(4)); } - + public function testNextPage() { $list = new TPagedList(array(1, 2)); $list->PageSize = 1; @@ -114,7 +114,7 @@ class TPagedListTest extends PHPUnit_Framework_TestCase { self::assertEquals(1, $list->nextPage()); self::assertEquals(false, $list->nextPage()); } - + public function testPreviousPage() { $list = new TPagedList(array(1, 2)); $list->PageSize = 1; @@ -122,7 +122,7 @@ class TPagedListTest extends PHPUnit_Framework_TestCase { self::assertEquals(0, $list->previousPage()); self::assertEquals(false, $list->previousPage()); } - + public function testVirtualCount() { $list = new TPagedList(array(1, 2)); $list->VirtualCount = -10; @@ -130,7 +130,7 @@ class TPagedListTest extends PHPUnit_Framework_TestCase { $list->VirtualCount = 5; self::assertEquals(5, $list->VirtualCount); } - + public function testPageCount() { $list = new TPagedList(array(1, 2, 3)); $list->PageSize = 1; @@ -141,7 +141,7 @@ class TPagedListTest extends PHPUnit_Framework_TestCase { $list->CustomPaging = false; self::assertEquals(3, $list->PageCount); } - + public function testIsFirstPage() { $list = new TPagedList(array(1, 2, 3)); $list->PageSize = 1; @@ -150,7 +150,7 @@ class TPagedListTest extends PHPUnit_Framework_TestCase { $list->gotoPage(1); self::assertEquals(false, $list->IsFirstPage); } - + public function testIsLastPage() { $list = new TPagedList(array(1, 2, 3)); $list->PageSize = 1; @@ -159,7 +159,7 @@ class TPagedListTest extends PHPUnit_Framework_TestCase { $list->gotoPage(2); self::assertEquals(true, $list->IsLastPage); } - + public function testGetCount() { $list = new TPagedList(array(1, 2, 3)); $list->PageSize = 1; @@ -167,7 +167,7 @@ class TPagedListTest extends PHPUnit_Framework_TestCase { $list->CustomPaging = true; self::assertEquals(3, $list->Count); } - + public function testGetIterator() { $list = new TPagedList(array(1, 2)); $list->CustomPaging = true; @@ -181,12 +181,12 @@ class TPagedListTest extends PHPUnit_Framework_TestCase { $found++; } if($index === 1 && $item === 2) { - $found++; + $found++; } } self::assertTrue($n == 2 && $found == 2); } - + public function testItemAt() { $list = new TPagedList(array(1, 2, 3)); $list->CustomPaging = true; @@ -196,27 +196,27 @@ class TPagedListTest extends PHPUnit_Framework_TestCase { $list->CurrentPageIndex = 0; self::assertEquals(1, $list[0]); } - + public function testIndexOf() { $list = new TPagedList(array(1, 2, 3)); $list->CustomPaging = true; self::assertEquals(0, $list->indexOf(1)); self::assertEquals(-1, $list->indexOf(0)); } - + public function testOffsetExists() { $list = new TPagedList(array(1, 2, 3)); $list->CustomPaging = true; self::assertEquals(true, isset($list[0])); self::assertEquals(false, isset($list[4])); } - + public function testOffsetGet() { $list = new TPagedList(array(1, 2, 3)); $list->CustomPaging = true; self::assertEquals(2, $list[1]); } - + public function testToArray() { $list = new TPagedList(array(1, 2, 3)); $list->CustomPaging = true; @@ -225,4 +225,3 @@ class TPagedListTest extends PHPUnit_Framework_TestCase { } -?> diff --git a/tests/unit/Collections/TPriorityMapTest.php b/tests/unit/Collections/TPriorityMapTest.php index 7c6ed498..847e09fe 100644 --- a/tests/unit/Collections/TPriorityMapTest.php +++ b/tests/unit/Collections/TPriorityMapTest.php @@ -22,10 +22,10 @@ class TPriorityMapTest extends PHPUnit_Framework_TestCase { $this->item5=new TPriorityMapTest_MapItem; $this->map->add('key1',$this->item1); $this->map->add('key2',$this->item2); - + //Test the priority capabilities } - + public function setUpPriorities() { $this->map->add('key3', $this->item3, 0); $this->map->add('key4', $this->item4, 100); @@ -45,16 +45,16 @@ class TPriorityMapTest extends PHPUnit_Framework_TestCase { $this->assertEquals(3,$map->getCount()); $map2=new TPriorityMap($this->map); $this->assertEquals(2,$map2->getCount()); - + /* Test the priority functionality of TPriorityMap */ - + $map3=new TPriorityMap($this->map, false, 100, -1); $this->assertEquals(100,$map3->getDefaultPriority()); $this->assertEquals(-1,$map3->getPrecision()); } - + /* Test that TPriorityMap complies with TMap */ - + public function testGetReadOnly() { $map = new TPriorityMap(null, true); @@ -202,46 +202,46 @@ class TPriorityMapTest extends PHPUnit_Framework_TestCase { $this->assertTrue(isset($this->map['key1'])); $this->assertFalse(isset($this->map['unknown key'])); } - + public function testToArray() { $map = new TPriorityMap(array('key' => 'value')); self::assertEquals(array('key' => 'value'), $map->toArray()); } - - - - + + + + /* Test the priority functionality of TPriorityMap */ - - + + public function testDefaultPriorityAndPrecision() { - + $this->assertEquals(10, $this->map->DefaultPriority); - + $this->map->DefaultPriority = 5; $this->assertEquals(5, $this->map->getDefaultPriority()); - + $this->assertEquals(8, $this->map->Precision); - + $this->map->Precision = 0; $this->assertEquals(0, $this->map->getPrecision()); - + ; - + $this->assertEquals(5, $this->map->add('key3', $this->item3)); $this->assertEquals(10, $this->map->add('key4', $this->item1, 10)); $this->assertTrue(10 == $this->map->add('key4', $this->item1, 10.01)); $this->assertTrue(100 == $this->map->add('key4', $this->item1, 100)); $this->map->Precision = 1; $this->assertTrue(10.1 == $this->map->add('key5', $this->item1, 10.1)); - + $this->assertEquals(5, $this->map->getCount()); } - + public function testAddWithPriorityAndPriorityOfAt() { - + $this->setUpPriorities(); - + $this->assertEquals(5, $this->map->getCount()); $this->assertEquals(10, $this->map->priorityOf($this->item1)); $this->assertEquals(0, $this->map->priorityOf($this->item3)); @@ -249,74 +249,74 @@ class TPriorityMapTest extends PHPUnit_Framework_TestCase { $this->assertEquals(1, $this->map->priorityOf($this->item5)); $this->assertEquals(false, $this->map->priorityOf(null)); $this->assertEquals(false, $this->map->priorityOf('foo')); - + $this->assertEquals(10, $this->map->priorityAt('key1')); $this->assertEquals(0, $this->map->priorityAt('key3')); $this->assertEquals(100, $this->map->priorityAt('key4')); $this->assertEquals(1, $this->map->priorityAt('key5')); $this->assertEquals(false, $this->map->priorityAt(null)); $this->assertEquals(false, $this->map->priorityAt('foo')); - + } - + public function testRemoveWithPriorityAndItemsAtWithPriority() { - + $this->setUpPriorities(); - + $this->assertEquals(5, $this->map->getCount()); $this->map->remove('key6'); $this->assertEquals(5, $this->map->getCount()); $this->map->remove('key6', null); $this->assertEquals(5, $this->map->getCount()); - - + + // key5 is at priority 1... not the default priority defined by null... nothing should happen here $this->map->remove('key5', null); $this->assertEquals(5, $this->map->getCount()); - + // key5 is at priority 1... not 50... nothing should happen here $this->map->remove('key5', 50); $this->assertEquals(5, $this->map->getCount()); - - - + + + $this->assertEquals(array('key3'=>$this->item3), $this->map->itemsAtPriority(0)); $this->assertEquals(array('key1'=>$this->item1, 'key2'=>$this->item2), $this->map->itemsAtPriority($this->map->DefaultPriority)); - + $this->assertEquals($this->item2, $this->map->itemAt('key2')); $this->assertEquals($this->item2, $this->map->itemAt('key2', 10)); $this->assertNull($this->map->itemAt('key2', 11)); //'key2' doesn't exist and priority 11... it is only at priority 10 $this->assertNull($this->map->itemAt('key2', 10.1)); //'key2' doesn't exist and priority 10.1... it is only at priority 10 - + $this->assertEquals($this->item4, $this->map->remove('key4')); $this->assertEquals(4, $this->map->getCount()); - + $this->assertEquals($this->item5, $this->map->remove('key5')); $this->assertEquals(3, $this->map->getCount()); } public function testIteratorAndArrayWithPriorities() { - + $this->setUpPriorities(); - + // This is the primary reason for a TPriorityMap $array = $this->map->toArray(); - + $ordered_keys = array_keys($array); $this->assertEquals('key3', $ordered_keys[0]); $this->assertEquals('key5', $ordered_keys[1]); $this->assertEquals('key1', $ordered_keys[2]); $this->assertEquals('key2', $ordered_keys[3]); $this->assertEquals('key4', $ordered_keys[4]); - + $ordered_values = array_values($array); $this->assertEquals($this->item3, $ordered_values[0]); $this->assertEquals($this->item5, $ordered_values[1]); $this->assertEquals($this->item1, $ordered_values[2]); $this->assertEquals($this->item2, $ordered_values[3]); $this->assertEquals($this->item4, $ordered_values[4]); - + $iter = $this->map->getIterator(); - + $this->assertTrue($iter->valid()); $this->assertEquals('key3', $iter->key()); $this->assertEquals($this->item1, $iter->current()); @@ -341,31 +341,31 @@ class TPriorityMapTest extends PHPUnit_Framework_TestCase { $this->assertEquals(null, $iter->key()); $this->assertEquals(null, $iter->current()); } - - + + public function testGetPriorities() { $this->setUpPriorities(); - + $priorities = $this->map->getPriorities(); - + $this->assertEquals(0, $priorities[0]); $this->assertEquals(1, $priorities[1]); $this->assertEquals(10, $priorities[2]); $this->assertEquals(100, $priorities[3]); $this->assertEquals(false, isset($priorities[4])); } - - + + public function testCopyAndMergeWithPriorities() { $this->setUpPriorities(); - + $map1 = new TPriorityMap(); $map1->add('key1', $this->item1); $map1->add('keyc', 'valuec'); $map1->copyFrom($this->map); - + $this->assertEquals(5, $map1->getCount()); - + $array = $map1->toArray(); $ordered_keys = array_keys($array); $this->assertEquals('key3', $ordered_keys[0]); @@ -373,24 +373,24 @@ class TPriorityMapTest extends PHPUnit_Framework_TestCase { $this->assertEquals('key1', $ordered_keys[2]); $this->assertEquals('key2', $ordered_keys[3]); $this->assertEquals('key4', $ordered_keys[4]); - + $ordered_values = array_values($array); $this->assertEquals($this->item3, $ordered_values[0]); $this->assertEquals($this->item5, $ordered_values[1]); $this->assertEquals($this->item1, $ordered_values[2]); $this->assertEquals($this->item2, $ordered_values[3]); $this->assertEquals($this->item4, $ordered_values[4]); - - - + + + $map2 = new TPriorityMap(); $map2->add('startkey', 'startvalue', -1000); $map2->add('key5', 'value5', 40); $map2->add('endkey', 'endvalue', 1000); $map2->mergeWith($this->map); - + $this->assertEquals(7, $map2->getCount()); - + $array = $map2->toArray(); $ordered_keys = array_keys($array); $this->assertEquals('startkey', $ordered_keys[0]); @@ -400,7 +400,7 @@ class TPriorityMapTest extends PHPUnit_Framework_TestCase { $this->assertEquals('key2', $ordered_keys[4]); $this->assertEquals('key4', $ordered_keys[5]); $this->assertEquals('endkey', $ordered_keys[6]); - + $ordered_values = array_values($array); $this->assertEquals('startvalue', $ordered_values[0]); $this->assertEquals($this->item3, $ordered_values[1]); @@ -409,81 +409,80 @@ class TPriorityMapTest extends PHPUnit_Framework_TestCase { $this->assertEquals($this->item2, $ordered_values[4]); $this->assertEquals($this->item4, $ordered_values[5]); $this->assertEquals('endvalue', $ordered_values[6]); - + $this->assertEquals(1, $map2->priorityAt('key5')); $this->assertEquals(1, $map2->priorityOf($this->item5)); } - + public function testSetPriorityAt() { - + $this->assertEquals(10, $this->map->priorityAt('key2')); $this->assertEquals(10, $this->map->setPriorityAt('key2', 1)); $this->assertEquals(1, $this->map->priorityAt('key2')); $this->assertEquals(1, $this->map->setPriorityAt('key2')); $this->assertEquals(10, $this->map->priorityAt('key2')); } - + public function testToArrayBelowPriority() { $this->setUpPriorities(); - + $array = $this->map->toArrayBelowPriority(1); $this->assertEquals(array('key3'=> $this->item3), $array); $this->assertEquals(1, count($array)); - + $array = $this->map->toArrayBelowPriority(1, true); $this->assertEquals(array('key3'=> $this->item3, 'key5'=> $this->item5), $array); $this->assertEquals(2, count($array)); - + $array = $this->map->toArrayBelowPriority(2); $this->assertEquals(array('key3'=> $this->item3, 'key5'=> $this->item5), $array); $this->assertEquals(2, count($array)); - + $array = $this->map->toArrayBelowPriority(10); $this->assertEquals(array('key3'=> $this->item3, 'key5'=> $this->item5), $array); $this->assertEquals(2, count($array)); - + $array = $this->map->toArrayBelowPriority(10, true); $this->assertEquals(array('key3'=> $this->item3, 'key5'=> $this->item5, 'key1' => $this->item1, 'key2' => $this->item2), $array); $this->assertEquals(4, count($array)); - + $array = $this->map->toArrayBelowPriority(100); $this->assertEquals(array('key3'=> $this->item3, 'key5'=> $this->item5, 'key1' => $this->item1, 'key2' => $this->item2), $array); $this->assertEquals(4, count($array)); - + $array = $this->map->toArrayBelowPriority(100, true); $this->assertEquals(array('key3'=> $this->item3, 'key5'=> $this->item5, 'key1' => $this->item1, 'key2' => $this->item2, 'key4' => $this->item4), $array); $this->assertEquals(5, count($array)); } - + public function testToArrayAbovePriority() { $this->setUpPriorities(); - + $array = $this->map->toArrayAbovePriority(100, false); $this->assertEquals(0, count($array)); - + $array = $this->map->toArrayAbovePriority(100, true); $this->assertEquals(1, count($array)); $this->assertEquals(array('key4' => $this->item4), $array); - + $array = $this->map->toArrayAbovePriority(11); $this->assertEquals(array('key4' => $this->item4), $array); $this->assertEquals(1, count($array)); - + $array = $this->map->toArrayAbovePriority(10, false); $this->assertEquals(array('key4' => $this->item4), $array); $this->assertEquals(1, count($array)); - + $array = $this->map->toArrayAbovePriority(10); $this->assertEquals(array('key1' => $this->item1, 'key2' => $this->item2, 'key4' => $this->item4), $array); $this->assertEquals(3, count($array)); - + $array = $this->map->toArrayAbovePriority(0); $this->assertEquals(array('key3' => $this->item3, 'key5' => $this->item5, 'key1' => $this->item1, 'key2' => $this->item2, 'key4' => $this->item4), $array); $this->assertEquals(5, count($array)); } - - - + + + } -?> diff --git a/tests/unit/Collections/TQueueTest.php b/tests/unit/Collections/TQueueTest.php index efee7cb7..da60eae3 100644 --- a/tests/unit/Collections/TQueueTest.php +++ b/tests/unit/Collections/TQueueTest.php @@ -31,7 +31,7 @@ class TQueueTest extends PHPUnit_Framework_TestCase { $queue->copyFrom($data); self::assertEquals(array(4, 5, 6), $queue->toArray()); } - + public function testCanNotCopyFromNonTraversableTypes() { $queue = new TQueue(); $data = new stdClass(); @@ -42,7 +42,7 @@ class TQueueTest extends PHPUnit_Framework_TestCase { } self::fail('An expected TInvalidDataTypeException was not raised'); } - + public function testClear() { $queue = new TQueue(array(1, 2, 3)); $queue->clear(); @@ -59,7 +59,7 @@ class TQueueTest extends PHPUnit_Framework_TestCase { $queue = new TQueue(array(1,2,3)); self::assertEquals(1, $queue->peek()); } - + public function testCanNotPeekAnEmptyQueue() { $queue = new TQueue(); try { @@ -76,7 +76,7 @@ class TQueueTest extends PHPUnit_Framework_TestCase { self::assertEquals(1, $first); self::assertEquals(array(2, 3), $queue->toArray()); } - + public function testCanNotDequeueAnEmptyQueue() { $queue = new TQueue(); try { @@ -105,7 +105,7 @@ class TQueueTest extends PHPUnit_Framework_TestCase { $found++; } if($index === 1 && $item === 2) { - $found++; + $found++; } } self::assertTrue($n == 2 && $found == 2); @@ -117,7 +117,7 @@ class TQueueTest extends PHPUnit_Framework_TestCase { $queue = new TQueue(array(1, 2, 3)); self::assertEquals(3, $queue->getCount()); } - + public function testCountable() { $queue = new TQueue(); self::assertEquals(0, count($queue)); @@ -127,4 +127,3 @@ class TQueueTest extends PHPUnit_Framework_TestCase { } -?> diff --git a/tests/unit/Collections/TStackTest.php b/tests/unit/Collections/TStackTest.php index 89a42749..80dc77c3 100644 --- a/tests/unit/Collections/TStackTest.php +++ b/tests/unit/Collections/TStackTest.php @@ -31,7 +31,7 @@ class TStackTest extends PHPUnit_Framework_TestCase { $stack->copyFrom($data); self::assertEquals(array(4, 5, 6), $stack->toArray()); } - + public function testCanNotCopyFromNonTraversableTypes() { $stack = new TStack(); $data = new stdClass(); @@ -42,7 +42,7 @@ class TStackTest extends PHPUnit_Framework_TestCase { } self::fail('An expected TInvalidDataTypeException was not raised'); } - + public function testClear() { $stack = new TStack(array(1, 2, 3)); $stack->clear(); @@ -59,7 +59,7 @@ class TStackTest extends PHPUnit_Framework_TestCase { $stack = new TStack(array(1)); self::assertEquals(1, $stack->peek()); } - + public function testCanNotPeekAnEmptyStack() { $stack = new TStack(); try { @@ -76,7 +76,7 @@ class TStackTest extends PHPUnit_Framework_TestCase { self::assertEquals(3, $last); self::assertEquals(array(1, 2), $stack->toArray()); } - + public function testCanNotPopAnEmptyStack() { $stack = new TStack(); try { @@ -105,7 +105,7 @@ class TStackTest extends PHPUnit_Framework_TestCase { $found++; } if($index === 1 && $item === 2) { - $found++; + $found++; } } self::assertTrue($n == 2 && $found == 2); @@ -117,7 +117,7 @@ class TStackTest extends PHPUnit_Framework_TestCase { $stack = new TStack(array(1, 2, 3)); self::assertEquals(3, $stack->getCount()); } - + public function testCount() { $stack = new TStack(); self::assertEquals(0, count($stack)); @@ -127,4 +127,3 @@ class TStackTest extends PHPUnit_Framework_TestCase { } -?> |