/** * Calculate all possible plant yields for current * un-bred candy cane plants * * @return $this */ private function calculateBreedYields() { $this->yields = []; $this->each(function (CandyCanePlant $plantA) { if ($plantA->hasBred()) { return; } $this->each(function (CandyCanePlant $plantB) use($plantA) { if ($plantA === $plantB || $plantB->hasBred()) { return; } $yieldA = $this->breederService->calculateYield($plantA, $plantB); $yieldB = $this->breederService->calculateYield($plantB, $plantA); $this->yields[$yieldA] = new PlantCouple($plantA, $plantB); $this->yields[$yieldB] = new PlantCouple($plantB, $plantA); }); }); krsort($this->yields); return $this; }
public function testCalculateYield() { $father = new CandyCanePlant(5); $mother = new CandyCanePlant(3); $this->assertEquals(5 ** 3 % (5 + 3), $this->breederService->calculateYield($father, $mother)); }