Source of file KahnSorterTest.php
Size: 2,232 Bytes - Last Modified: 2021-12-24T06:39:27+00:00
/var/www/docs.ssmods.com/process/src/src/Tests/Helper/KahnSorterTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 | <?php namespace ChrisPenny\DataObjectToFixture\Tests\Helper; use ChrisPenny\DataObjectToFixture\Helper\KahnSorter; use SilverStripe\Dev\SapphireTest; /** * Shout out to Adrian Humphreys (@adrhumphreys) for providing this one. */ class KhanSorterTest extends SapphireTest { public function testSorter(): void { $items = [ 'bigOlStew' => [ 'thingy', 'pig', 'cheeseDanish', 'chicken', ], 'cheeseDanish' => [ 'flour', 'butter', 'egg', 'vanilla', 'creamCheese', 'sugar', ], 'butter' => [ 'milk', 'salt', ], 'thingy' => [ 'iron', 'apple', 'vanilla', ], 'creamCheese' => [ 'milk', 'salt', ], 'chicken' => [ 'worm', ], 'worm' => [ 'apple', ], 'egg' => [ 'chicken', ], 'milk' => [ 'cow', ], 'cow' => [ 'grass', ], 'pig' => [ 'apple', 'worm', ], ]; $sorter = new KahnSorter($items); $results = $sorter->sort(); $this->assertEquals( [ 'iron', 'apple', 'vanilla', 'thingy', 'worm', 'pig', 'flour', 'grass', 'cow', 'milk', 'salt', 'butter', 'chicken', 'egg', 'creamCheese', 'sugar', 'cheeseDanish', 'bigOlStew', ], $results ); } public function testEmptySort(): void { $sorter = new KahnSorter([]); $results = $sorter->sort(); $this->assertEquals([], $results); } } |