Ejemplo n.º 1
0
 /**
  * This method creates a list of "n" length with every item set to the given object.
  *
  * @access public
  * @static
  * @param Core\Type $x                                      the object to be replicated
  * @param IInt32\Type $n                                    the number of times to replicate
  * @return ILinkedList\Type                                 the collection
  */
 public static function replicate(Core\Type $x, IInt32\Type $n) : ILinkedList\Type
 {
     if ($n->unbox() <= 0) {
         return ILinkedList\Type::nil();
     }
     return ILinkedList\Type::cons($x, ILinkedList\Type::replicate($x, IInt32\Module::decrement($n)));
 }
Ejemplo n.º 2
0
 /**
  * This method tests the "replicate" method.
  *
  * @dataProvider data_replicate
  */
 public function test_replicate(array $provided, array $expected)
 {
     $p0 = ILinkedList\Type::replicate(IObject\Type::box($provided[0]), IInt32\Type::box($provided[1]));
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\ILinkedList\\Type', $p0);
     $this->assertSame($e0, $p0->unbox(1));
 }