コード例 #1
0
ファイル: FluentArrayTest.php プロジェクト: letsdrink/ouzo
 /**
  * @test
  */
 public function shouldSortElements()
 {
     //given
     $array = array(4, 1, 3, 2);
     //when
     $result = FluentArray::from($array)->sort(Comparator::natural())->toArray();
     //then
     $this->assertEquals(array(1, 2, 3, 4), $result);
 }
コード例 #2
0
ファイル: ArraysTest.php プロジェクト: letsdrink/ouzo
 /**
  * @test
  */
 public function shouldSortArrayByDefaultExtractor()
 {
     //given
     $array = array(1, 3, 2);
     //when
     $sorted = Arrays::sort($array, Comparator::natural());
     //then
     $this->assertEquals(array(1, 2, 3), $sorted);
 }
コード例 #3
0
ファイル: ComparatorTest.php プロジェクト: letsdrink/ouzo
 /**
  * @test
  */
 public function shouldNotUseFinalTieBreakerWhenAnyPriorResolves()
 {
     //given
     $alwaysLess = Functions::constant(-1);
     $alwaysGreater = Functions::constant(1);
     $alwaysEqual = Functions::constant(0);
     $greaterComparator = Comparator::compound($alwaysEqual, $alwaysGreater, $alwaysLess);
     $lesserComparator1 = Comparator::compound($alwaysEqual, $alwaysLess, $alwaysGreater);
     $lesserComparator2 = Comparator::compound($alwaysLess, $alwaysEqual, $alwaysEqual);
     //when
     $greater = $greaterComparator(null, null);
     $lesser1 = $lesserComparator1(null, null);
     $lesser2 = $lesserComparator2(null, null);
     //then
     $this->assertEquals(-1, $lesser1);
     $this->assertEquals(1, $greater);
     $this->assertEquals(-1, $lesser2);
 }