예제 #1
0
 /**
  * Test calculating the pitstop times based on laps
  *
  * Pit time is calculated using 2 sectors that were part of the pitstop
  * (e.g. L1S3->L2S1) MINUS the averages of all non pitstop sectors.
  *
  * For inner understanding how these values are calculated, please see
  * the document `docs/RfactorReaderTest_testReadingPitTimes.ods`
  */
 public function testCalculatingPitTimes()
 {
     // Init participant
     $participant = new Participant();
     // Init new laps
     $laps = array();
     // Normal lap
     $lap1 = new Lap();
     $lap1->setSectorTimes(array(42.9237, 42.9237, 44.9237))->setParticipant($participant);
     $laps[] = $lap1;
     // Pit lap
     $lap2 = new Lap();
     $lap2->setSectorTimes($lap2_sectors = array(41.9237, 42.9237, 53.9237))->setParticipant($participant)->setPitLap(true);
     $laps[] = $lap2;
     // Normal lap
     $lap3 = new Lap();
     $lap3->setSectorTimes(array(51.9237, 42.9237, 56.9237))->setParticipant($participant);
     $laps[] = $lap3;
     // Set laps to participant
     $participant->setLaps($laps);
     //---- Validate pit times
     $this->assertSame(0, $lap1->getPitTime());
     $this->assertSame(53.9237 - (44.9237 + 56.9237) / 2 + (51.9237 - (42.9237 + 41.9237) / 2), $lap2->getPitTime());
     $this->assertSame(0, $lap3->getPitTime());
     //---- Validate special cases
     // Invalidate participant cache
     $participant->invalidateAverageLapCache();
     // Validate that when sector 3 is missing no calculation is done on that
     $lap2->setSectorTimes(array(41.9237, 42.9237, null));
     $this->assertSame(51.9237 - (42.9237 + 41.9237) / 2, $lap2->getPitTime());
     // Restore lap 2 sectors
     $lap2->setSectorTimes($lap2_sectors);
     //-----
     // Validate that when sector 1 of next lap is missing, any calculation
     // on that sector is ignored, thus pit time is only based on sector 3
     // of this pit lap. This also validates ignoring multipe pit sectors
     // that should be ignored in the averages as we're now marking a
     // second lap as pit lap
     // Invalidate participant cache
     $participant->invalidateAverageLapCache();
     // Set lap3 as pit lap
     $lap3->setPitLap(true);
     // Invalidate participant cache
     $participant->invalidateAverageLapCache();
     // Check time
     $this->assertSame(56.9237 - 44.9237, $lap3->getPitTime());
     //-----
     // Validate that calculation is done when hard pit time is available
     $lap2->setPitTime(21);
     $this->assertSame(21, $lap2->getPitTime());
 }
예제 #2
0
 /**
  * Test the best possible lap
  */
 public function testBestPossibleLap()
 {
     // Get populated participant
     $participant = $this->getParticipantWithLaps();
     //-- Run twice to test cache
     for ($i = 0; $i < 2; $i++) {
         // Get average lap
         $possible_lap = $participant->getBestPossibleLap();
         // Validate
         $this->assertSame(121.03, $possible_lap->getTime());
         $this->assertSame(array(39.601, 33.5, 47.929), $possible_lap->getSectorTimes());
         $this->assertSame($participant, $possible_lap->getParticipant());
         $this->assertSame(array(), $possible_lap->getAids());
         $this->assertNull($possible_lap->getNumber());
         $this->assertNull($possible_lap->getPosition());
         $this->assertNull($possible_lap->getElapsedSeconds());
     }
     // Validate empty participant
     $participant = new Participant();
     $this->assertNull($participant->getBestPossibleLap());
     // Validate participant with one partial lap
     $participant = new Participant();
     $lap = new Lap();
     $this->assertNull($participant->addLap($lap->setSectorTimes(array(14)))->getBestPossibleLap());
 }
예제 #3
0
 /**
  * Test sorting laps by sector
  */
 public function testSortingLapsBySector()
 {
     // Init laps
     $laps = array();
     $lap = new Lap();
     $lap->setSectorTimes(array(100.2));
     $laps[] = $lap;
     $lap = new Lap();
     $lap->setSectorTimes(array(100.1));
     $laps[] = $lap;
     $lap = new Lap();
     $lap->setSectorTimes(array(103.5));
     $laps[] = $lap;
     // Sort laps
     $laps = Helper::sortLapsBySector($laps, 1);
     // Get sector info
     $sectors1 = $laps[0]->getSectorTimes();
     $sectors2 = $laps[1]->getSectorTimes();
     $sectors3 = $laps[2]->getSectorTimes();
     // Validate laps
     $this->assertSame(100.1, $sectors1[0]);
     $this->assertSame(100.2, $sectors2[0]);
     $this->assertSame(103.5, $sectors3[0]);
 }