/** * @expectedException Pherserk\Tombola\Exception\FolderException * @covers Folder::addRow */ public function testCantAddNumbersFromSameHalfScoreThreeTimes() { $folderNumbers = [[1, 10, 20, 30, 76], [2, 11, 22, 33, 77], [3, 12, 23, 34, 78]]; $rows = []; foreach ($folderNumbers as $rowNumber) { $row = new Row(); foreach ($rowNumber as $number) { $row->addNumber($number); } $rows[] = $row; } $folder = new Folder(); foreach ($rows as $row) { $folder->addRow($row); } }
/** * @param Row $row */ public function addRow(Row $row) { $added = false; foreach ($this->rows as $index => $rowToFill) { if (is_null($rowToFill)) { $this->rows[$index] = $row; $added = true; break; } } if (!$added) { throw new FolderException('Folder is full'); } $this->numbersHistory = array_merge($this->numbersHistory, $row->getCells()); $this->checkNumbersHistory(); return $this; }
/** * @return array[Row] */ public static function generate() { $bucket = new Bucket(); $rows = []; for ($k = 0; $k < 18; $k++) { $row = new Row(); for ($i = 0; $i < 5; $i++) { $number = $bucket->extractNumber(); $row->addNumber($number); } $rows[] = $row; } $folders = []; for ($i = 0; $i < 6; $i++) { $folder = new Folder(); $folder->addRow(array_pop($rows))->addRow(array_pop($rows))->addRow(array_pop($rows)); $folders[] = $folder; } return $folders; }
/** * @expectedException Pherserk\Tombola\Exception\RowException * @cover Row::addNumber */ public function testOutOfRangeNumberThrowsException() { $row = new Row(); $row->addNumber(0); }