Exemplo n.º 1
0
 public function test_each_cons_1()
 {
     $arr = range(1, 10);
     $follower = 0;
     $message = '';
     Enumerator::each_cons_($arr, 3, function ($key, $value, $leader) use(&$follower, &$message) {
         if ($follower < $leader) {
             $message .= '||';
             $follower = $leader;
         }
         $message .= $value . ',';
     });
     $this->assertEquals("1,2,3,||2,3,4,||3,4,5,||4,5,6,||5,6,7,||6,7,8,||7,8,9,||8,9,10,", $message);
     $this->assertEquals(array(array(1, 2, 3), array(2, 3, 4), array(3, 4, 5), array(4, 5, 6), array(5, 6, 7), array(6, 7, 8), array(7, 8, 9), array(8, 9, 10)), $arr);
 }