Created
August 20, 2010 16:55
-
-
Save cirpo/540701 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class ArrayTest extends PHPUnit_Framework_TestCase { | |
| public function testNextAndPrev1(){ | |
| $rs = array(1=>1,2=>2,3=>3,4=>4,5=>5); | |
| $curID = 3; | |
| $prev = null; | |
| foreach ($rs as $ID => $r){ | |
| if ($ID==$curID) break; | |
| $prev=$r; | |
| } | |
| $next = current($rs); | |
| $this->assertEquals($prev,2); | |
| $this->assertEquals($next,4); | |
| } | |
| public function testNextAndPrev2(){ | |
| $rs = array(1=>1,2=>2,3=>3,4=>4,5=>5); | |
| $curID = 3; | |
| list($prev, $next) = $this->getBackNext2($rs, $curID); | |
| $this->assertEquals($prev,2); | |
| $this->assertEquals($next,4); | |
| } | |
| public function testNextAndPrev3(){ | |
| $rs = array(1=>1,2=>2,3=>3,4=>4,5=>5); | |
| $curID = 3; | |
| list($prev, $next) = $this->getBackNext3($rs, $curID); | |
| $this->assertEquals($prev,2); | |
| $this->assertEquals($next,4); | |
| } | |
| private function getBackNext2($rs, $curID=null){ | |
| $prev = null; | |
| foreach ($rs as $ID => $r) { | |
| if ($ID==$curID) break; | |
| $prev=$r; | |
| } | |
| $next = current($rs); | |
| return array($prev, $next); | |
| } | |
| private function getBackNext3(&$rs, $curID=null){ | |
| $prev = null; | |
| foreach ($rs as $ID => $r) { | |
| if ($ID==$curID) break; | |
| $prev=$r; | |
| } | |
| $next = current($rs); | |
| return array($prev, $next); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment