Example #1
0
 /**
  * This method computes the nth fibonacci number.
  *
  * @access public
  * @static
  * @param IInteger\Type $n                                  the operand
  * @return IInteger\Type                                    the result
  */
 public static function fibonacci(IInteger\Type $n) : IInteger\Type
 {
     return IInteger\Module::le($n, IInteger\Type::one())->unbox() ? $n : IInteger\Module::add(IInteger\Module::fibonacci(IInteger\Module::decrement($n)), IInteger\Module::fibonacci(IInteger\Module::subtract($n, IInteger\Type::box('2'))));
 }
Example #2
0
 /**
  * This method tests the "fibonacci" method.
  *
  * @dataProvider data_fibonacci
  */
 public function test_fibonacci(array $provided, array $expected)
 {
     $p0 = IInteger\Module::fibonacci(IInteger\Type::box($provided[0]));
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IInteger\\Type', $p0);
     $this->assertSame($e0, $p0->unbox());
 }