diff options
author | knut <> | 2007-05-30 12:57:59 +0000 |
---|---|---|
committer | knut <> | 2007-05-30 12:57:59 +0000 |
commit | 17585ab833c900027b724af39a85a66a0491b1ea (patch) | |
tree | 200b238bb48a648721215e4b834b605b82a38d90 /tests/unit | |
parent | 0c859c17c7439155d2ed185cb5f1d3977519c002 (diff) |
full coverage for TQueue
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/Collections/AllTests.php | 6 | ||||
-rw-r--r-- | tests/unit/Collections/TQueueTest.php | 124 |
2 files changed, 128 insertions, 2 deletions
diff --git a/tests/unit/Collections/AllTests.php b/tests/unit/Collections/AllTests.php index c9da9132..d9158f3a 100644 --- a/tests/unit/Collections/AllTests.php +++ b/tests/unit/Collections/AllTests.php @@ -5,8 +5,9 @@ if(!defined('PHPUnit_MAIN_METHOD')) { define('PHPUnit_MAIN_METHOD', 'Collections_AllTests::main'); } -require_once 'Collections/TListTest.php'; -require_once 'Collections/TMapTest.php'; +require_once 'TListTest.php'; +require_once 'TMapTest.php'; +require_once 'TQueueTest.php'; class Collections_AllTests { public static function main() { @@ -18,6 +19,7 @@ class Collections_AllTests { $suite->addTestSuite('TListTest'); $suite->addTestSuite('TMapTest'); + $suite->addTestSuite('TQueueTest'); return $suite; } diff --git a/tests/unit/Collections/TQueueTest.php b/tests/unit/Collections/TQueueTest.php new file mode 100644 index 00000000..d0fe1af0 --- /dev/null +++ b/tests/unit/Collections/TQueueTest.php @@ -0,0 +1,124 @@ +<?php +require_once dirname(__FILE__).'/../phpunit.php'; + +Prado::using('System.Collections.TQueue'); + +/** + * @package System.Collections + */ +class TQueueTest extends PHPUnit_Framework_TestCase { + + public function setUp() { + } + + public function tearDown() { + } + + public function testConstruct() { + $queue = new TQueue(); + self::assertEquals(array(), $queue->toArray()); + $queue = new TQueue(array(1, 2, 3)); + self::assertEquals(array(1, 2, 3), $queue->toArray()); + } + + public function testToArray() { + $queue = new TQueue(array(1, 2, 3)); + self::assertEquals(array(1, 2, 3), $queue->toArray()); + } + + public function testCopyFrom() { + $queue = new TQueue(array(1, 2, 3)); + $data = array(4, 5, 6); + $queue->copyFrom($data); + self::assertEquals(array(4, 5, 6), $queue->toArray()); + } + + public function testCanNotCopyFromNonTraversableTypes() { + $queue = new TQueue(); + $data = new stdClass(); + try { + $queue->copyFrom($data); + } catch(TInvalidDataTypeException $e) { + return; + } + self::fail('An expected TInvalidDataTypeException was not raised'); + } + + public function testClear() { + $queue = new TQueue(array(1, 2, 3)); + $queue->clear(); + self::assertEquals(array(), $queue->toArray()); + } + + public function testContains() { + $queue = new TQueue(array(1, 2, 3)); + self::assertEquals(true, $queue->contains(2)); + self::assertEquals(false, $queue->contains(4)); + } + + public function testPeek() { + $queue = new TQueue(array(1)); + self::assertEquals(1, $queue->peek()); + } + + public function testCanNotPeekAnEmptyQueue() { + $queue = new TQueue(); + try { + $item = $queue->peek(); + } catch(TInvalidOperationException $e) { + return; + } + self::fail('An expected TInvalidOperationException was not raised'); + } + + public function testDequeue() { + $queue = new TQueue(array(1, 2, 3)); + $first = $queue->dequeue(); + self::assertEquals(1, $first); + self::assertEquals(array(2, 3), $queue->toArray()); + } + + public function testCanNotDequeueAnEmptyQueue() { + $queue = new TQueue(); + try { + $item = $queue->dequeue(); + } catch(TInvalidOperationException $e) { + return; + } + self::fail('An expected TInvalidOperationException was not raised'); + } + + public function testEnqueue() { + $queue = new TQueue(); + $queue->enqueue(1); + self::assertEquals(array(1), $queue->toArray()); + } + + public function testGetIterator() { + $queue = new TQueue(array(1, 2)); + self::assertType('TQueueIterator', $queue->getIterator()); + $n = 0; + $found = 0; + foreach($queue as $index => $item) { + foreach($queue as $a => $b); // test of iterator + $n++; + if($index === 0 && $item === 1) { + $found++; + } + if($index === 1 && $item === 2) { + $found++; + } + } + self::assertTrue($n == 2 && $found == 2); + } + + public function testGetCount() { + $queue = new TQueue(); + self::assertEquals(0, $queue->getCount()); + $queue = new TQueue(array(1, 2, 3)); + self::assertEquals(3, $queue->getCount()); + } + +} + +?> |