예제 #1
0
 /**
  * @covers NumbersPHP\Basic::range
  */
 public function testRange()
 {
     $msg = 'range should return an appropriate range for the given start, stop, and step parameters';
     $this->assertEquals(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), \NumbersPHP\Basic::range(1, 10), $msg);
     $this->assertEquals(array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1), \NumbersPHP\Basic::range(10, 1), $msg);
     $this->assertEquals(array(1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5), \NumbersPHP\Basic::range(1, 5, 0.5), $msg);
     $this->assertEquals(array(5, 4.5, 4, 3.5, 3, 2.5, 2, 1.5, 1), \NumbersPHP\Basic::range(5, 1, 0.5), $msg);
 }
예제 #2
0
 /**
  * @covers NumbersPHP\Statistic::exponentialRegression
  */
 public function testExponentialRegression()
 {
     $source = array(10, 9, 8, 8, 7, 7, 6, 6.5, 6.4, 6.3, 6.2);
     $regressionValues = array(9.077131929916444, 8.669377715385259, 8.279940244595563, 7.907996710352883, 7.552761266818376, 7.213483369166244, 6.8894461878255076, 6.579965093955639, 6.284386212956255, 6.002085042954625, 5.732465135352174);
     $exponentialRegression = \NumbersPHP\Statistic::exponentialRegression($source);
     $regressionFunction = $exponentialRegression[0];
     $regressionRSquared = $exponentialRegression[1];
     $this->assertTrue(\NumbersPHP\Basic::numbersEqual($regressionRSquared, 0.8491729985314136));
     $regressionFunctionValues = $regressionFunction(\NumbersPHP\Basic::range(1, count($source)));
     for ($i = 0; $i < count($regressionValues); ++$i) {
         $this->assertTrue(\NumbersPHP\Basic::numbersEqual($regressionValues[$i], $regressionFunctionValues[$i]));
     }
     $this->assertTrue(\NumbersPHP\Basic::numbersEqual($regressionFunction(1), 9.077131929916444));
     $this->assertTrue(\NumbersPHP\Basic::numbersEqual($regressionFunction(15), 4.769782016165231));
 }