calculate('WRONG', Entry::factory()->create()); })->throws(TabulationException::class, 'Mode must be seating or advancement'); it('throws an exception if entry is not valid', function () { // Arrange #$calculator = new AllJudgesCount(); $calculator = App::make(AllJudgesCount::class); // Act $calculator->calculate('seating', Entry::factory()->make()); // Assert })->throws(TabulationException::class, 'Invalid entry specified'); it('throws an exception if entry is missing judge scores', function () { // Arrange loadSampleAudition(); $judge1 = User::factory()->create(); $judge2 = User::factory()->create(); Room::find(1000)->addJudge($judge1); Room::find(1000)->addJudge($judge2); $entry = Entry::factory()->create(['audition_id' => 1000]); $scores = [ 1001 => 50, 1002 => 60, 1003 => 70, 1004 => 80, 1005 => 90, ]; #$calculator = new AllJudgesCount(); $calculator = App::make(AllJudgesCount::class); enterScore($judge1, $entry, $scores); // Act $calculator->calculate('seating', $entry); // Assert })->throws(TabulationException::class, 'Not all score sheets are in'); it('throws an exception if a score exists from an invalid judge', function () { // Arrange loadSampleAudition(); $judge1 = User::factory()->create(); $judge2 = User::factory()->create(); $judge3 = User::factory()->create(); Room::find(1000)->addJudge($judge1); Room::find(1000)->addJudge($judge2); $entry = Entry::factory()->create(['audition_id' => 1000]); $scores = [ 1001 => 50, 1002 => 60, 1003 => 70, 1004 => 80, 1005 => 90, ]; #$calculator = new AllJudgesCount(); $calculator = App::make(AllJudgesCount::class); enterScore($judge1, $entry, $scores); $scoreSheetToSpoof = enterScore($judge2, $entry, $scores); $scoreSheetToSpoof->update(['user_id' => $judge3->id]); // Act $calculator->calculate('seating', $entry); // Assert })->throws(TabulationException::class, 'Score exists from a judge not assigned to this audition'); it('correctly calculates scores for seating', function () { // Arrange loadSampleAudition(); $judge1 = User::factory()->create(); $judge2 = User::factory()->create(); Room::find(1000)->addJudge($judge1); Room::find(1000)->addJudge($judge2); $entry = Entry::factory()->create(['audition_id' => 1000]); $scores = [ 1001 => 50, 1002 => 60, 1003 => 70, 1004 => 80, 1005 => 90, ]; $scores2 = [ 1001 => 55, 1002 => 65, 1003 => 75, 1004 => 85, 1005 => 95, ]; #$calculator = new AllJudgesCount(); $calculator = App::make(AllJudgesCount::class); enterScore($judge1, $entry, $scores); enterScore($judge2, $entry, $scores2); // Act $finalScores = $calculator->calculate('seating', $entry); // Assert $expectedScores = [142.5, 165, 125, 145, 105]; expect($finalScores)->toBe($expectedScores); }); it('correctly calculates scores for advancement', function () { // Arrange loadSampleAudition(); $judge1 = User::factory()->create(); $judge2 = User::factory()->create(); Room::find(1000)->addJudge($judge1); Room::find(1000)->addJudge($judge2); $entry = Entry::factory()->create(['audition_id' => 1000]); $scores = [ 1001 => 50, 1002 => 60, 1003 => 70, 1004 => 80, 1005 => 90, ]; $scores2 = [ 1001 => 55, 1002 => 65, 1003 => 75, 1004 => 85, 1005 => 95, ]; $calculator = App::make(AllJudgesCount::class); enterScore($judge1, $entry, $scores); enterScore($judge2, $entry, $scores2); // Act $finalScores = $calculator->calculate('advancement', $entry); // Assert $expectedScores = [152.5, 185, 165, 125, 145]; expect($finalScores)->toBe($expectedScores); });