Esempio n. 1
0
 /**
  * @param $nrOfTravellers
  * @return Traveller[]
  */
 public static function getTravellers($levelId, $currentTime = 0)
 {
     $travellerArray = array();
     $timeLength = 100;
     // constant for flow rate
     /** @var Level $level */
     $level = Level::find($levelId);
     $travellerArray[] = new Traveller(0, 2, 1);
     $travellerArray[] = new Traveller(0, 2, 1);
     $travellerArray[] = new Traveller(0, 2, 1);
     $travellerArray[] = new Traveller(0, 2, 1);
     $travellerArray[] = new Traveller(0, 2, 1);
     $travellerArray[] = new Traveller(0, 2, 1);
     $travellerArray[] = new Traveller(0, 2, 1);
     $travellerArray[] = new Traveller(0, 2, 1);
     $travellerArray[] = new Traveller(0, 2, 1);
     $travellerArray[] = new Traveller(0, 2, 1);
     if ($level != null) {
         for ($i = 0; $i < $level->getTotalTravellers(); $i++) {
             $originalFloor = self::getRandomFloor($level->nr_of_floors);
             $demandedFloor = self::getRandomFloor($level->nr_of_floors);
             while ($originalFloor == $demandedFloor) {
                 $demandedFloor = self::getRandomFloor($level->nr_of_floors);
             }
             $travellerArray[] = new Traveller($originalFloor, $demandedFloor, self::getRandomTime($currentTime, $timeLength));
         }
     }
     return $travellerArray;
 }
Esempio n. 2
0
 public function testGetTravellers()
 {
     /** @var Level $level */
     $level = Level::find(1);
     $travellers = TravellerFactory::getTravellers($level->id);
     $this->assertEquals($level->getTotalTravellers(), count($travellers), "Nr of travellersData is equal");
     foreach ($travellers as $traveller) {
         $this->assertNotEquals($traveller->getDemandedFloor(), $traveller->getOriginalFloor(), "Traveller goes to different floor");
         $this->assertLessThanOrEqual($level->nr_of_floors, $traveller->getDemandedFloor());
     }
     $travellers = TravellerFactory::getTravellers($level->id, 500);
     foreach ($travellers as $traveller) {
         $this->assertGreaterThanOrEqual(500, $traveller->getCheckInTime(), "Traveller check in time is after 500");
     }
 }