Esempio n. 1
0
 public function testRemoveItems()
 {
     $items = $this->createRandomItems();
     $items_count = count($items);
     $last_index = $items_count - 1;
     // pick some random items to remove
     $max_remove = round($items_count / 2, 0);
     $numof_items_to_remove = self::$faker->numberBetween(1, $max_remove);
     $random_items = [];
     $randomly_picked_indexes = [];
     for ($i = 0; $i < $numof_items_to_remove; $i++) {
         $random_index = 0;
         do {
             if ($last_index > 0) {
                 $random_index = self::$faker->numberBetween(0, $last_index);
             }
         } while (in_array($random_index, $randomly_picked_indexes));
         $random_items[] = $items[$random_index];
         $randomly_picked_indexes[] = $random_index;
     }
     $list = new ArrayList($items);
     $list->removeItems($random_items);
     // assert item count
     $expected_item_count = $items_count - count($random_items);
     $this->assertEquals($expected_item_count, count($list));
     // assert item order
     $expected_items = [];
     foreach ($items as $index => $item) {
         if (!in_array($index, $randomly_picked_indexes)) {
             $expected_items[] = $item;
         }
     }
     foreach ($list as $index => $item) {
         $this->assertEquals($expected_items[$index], $item);
     }
 }