コード例 #1
0
 /**
  * Test the consistency of a participant
  */
 public function testConsistency()
 {
     // Get populated participant
     $participant = $this->getParticipantWithLaps();
     // Add slow lap (exactly +21s of best lap)
     // This lap should be ignored in calculating
     //
     // NOTE: The lap 155.730 will also be ignored from populated test data
     $lap = new Lap();
     $participant->addLap($lap->setTime($participant->getBestLap()->getTime() + 21)->setSectorTimes(array($participant->getBestLap()->getSectorTime(1) + 7, $participant->getBestLap()->getSectorTime(2) + 7, $participant->getBestLap()->getSectorTime(3) + 7)));
     //-- Run twice to test cache
     for ($i = 0; $i < 2; $i++) {
         // Test without ignoring first lap
         $this->assertSame(2.7405, $participant->getConsistency(false));
         $this->assertSame(97.81999999999999, $participant->getConsistencyPercentage(false));
         // Test with ignoring first lap
         $this->assertSame(3.0, $participant->getConsistency());
         $this->assertSame(97.61, $participant->getConsistencyPercentage());
     }
     // Validate empty participant
     $participant = new Participant();
     // Prevent cache
     $this->assertNull($participant->getConsistency(false));
     $this->assertNull($participant->getConsistencyPercentage(false));
     // Validate one lap participant
     $participant = new Participant();
     // Prevent cache
     $lap = new Lap();
     $participant->addLap($lap->setTime(128.211));
     $this->assertNull($participant->getConsistency(false));
     // Validate extra pit stop lap not causing devise by zero error
     $participant = new Participant();
     // Prevent cache
     $lap = new Lap();
     $participant->addLap($lap->setTime(125.211));
     $lap = new Lap();
     $participant->addLap($lap->setTime(128.211)->setPitLap(true));
     $this->assertNull($participant->getConsistency(false));
 }