Ejemplo n.º 1
0
 /**
  * Get a Session instance populated with test data.
  *
  * NOTE: Every time this method is ran, a different instance will be
  *       returned! Keep this in mind when comparing things by reference
  *
  * @return Session
  */
 protected function getSessionWithData()
 {
     // Create new session
     $session = new Session();
     // Participants testdata array
     $participants_data = array(array('position' => 1, 'vehicle' => array('class' => 'class1'), 'laps' => array(array('time' => 130.7517, 'sectors' => array(53.2312, 32.299, 45.2215), 'position' => 1), array('time' => 125.2989, 'sectors' => array(47.4511, 32.063, 45.7848), 'position' => 1), array('time' => 123.3179, 'sectors' => array(46.6382, 32.0084, 44.6712), 'position' => 1))), array('position' => 2, 'vehicle' => array('class' => 'class3'), 'laps' => array(array('time' => 130.9077, 'sectors' => array(54.0223, 32.3176, 44.5677), 'position' => 2), array('time' => 125.6976, 'sectors' => array(47.5271, 32.4621, 45.7083), 'position' => 2), array('time' => 126.062, 'sectors' => array(47.7989, 32.7721, 45.491), 'position' => 2))), array('position' => 3, 'vehicle' => array('class' => 'class2'), 'laps' => array(array('time' => 134.8484, 'sectors' => array(56.0119, 32.4913, 46.3452), 'position' => 12), array('time' => 126.2454, 'sectors' => array(50.4389, 31.8827, 43.9237), 'position' => 3), array('time' => 122.0663, 'sectors' => array(46.2715, 31.8696, 43.9252), 'position' => 3))), array('position' => 4, 'vehicle' => array('class' => 'class1'), 'laps' => array(array('time' => 155.1491, 'sectors' => array(60.0119, 40.4913, 54.6459), 'position' => 4), array('time' => 156.1491, 'sectors' => array(60.0119, 40.4913, 55.6459), 'position' => 4))), array('position' => 5, 'vehicle' => array('class' => 'class2'), 'laps' => array()), array('position' => 6, 'vehicle' => array('class' => 'class3'), 'laps' => array(array('time' => null, 'sectors' => array(42.4389), 'position' => 6))));
     // Loop each participant data
     foreach ($participants_data as $participant_data) {
         // Create the new participant and populate
         $participant = new Participant();
         $participant->setPosition($participant_data['position']);
         $vehicle = new Vehicle();
         $vehicle->setClass($participant_data['vehicle']['class']);
         $participant->setVehicle($vehicle);
         // Create each lap
         foreach ($participant_data['laps'] as $lap_key => $lap_data) {
             $lap = new Lap();
             $lap->setTime($lap_data['time'])->setSectorTimes($lap_data['sectors'])->setNumber($lap_key + 1)->setPosition($lap_data['position'])->setParticipant($participant);
             // Add lap to participant
             $participant->addLap($lap);
         }
         // Add participant to session
         $session->addParticipant($participant);
     }
     // Return the session
     return $session;
 }
Ejemplo n.º 2
0
 /**
  * Test the difference in starting and ending position of a participant
  */
 public function testPositionDifference()
 {
     // Create new participant
     $participant = new Participant();
     // Set position data
     $participant->setPosition(1);
     $participant->setGridPosition(5);
     // Validate positive position difference
     $this->assertSame(4, $participant->getPositionDifference());
     // Set position data
     $participant->setPosition(5);
     $participant->setGridPosition(2);
     // Validate negative position difference
     $this->assertSame(-3, $participant->getPositionDifference());
     // Set position data
     $participant->setPosition(4);
     $participant->setGridPosition(4);
     // Validate no position difference
     $this->assertSame(0, $participant->getPositionDifference());
     // Set grid position to null
     $participant->setPosition(4);
     $participant->setGridPosition(null);
     // Validate no position difference
     $this->assertNull($participant->getPositionDifference());
 }