コード例 #1
0
ファイル: VectorTest.php プロジェクト: giorgiosironi/eris
 public function testConcatenationMaintainsLength()
 {
     $this->forAll(Generator\vector(10, Generator\nat(1000)), Generator\vector(10, Generator\nat(1000)))->then(function ($first, $second) {
         $concatenated = array_merge($first, $second);
         $this->assertEquals(count($concatenated), count($first) + count($second), var_export($first, true) . " and " . var_export($second, true) . " do not maintain their length when concatenated.");
     });
 }
コード例 #2
0
ファイル: FrequencyTest.php プロジェクト: nicoder/eris
 public function testAlwaysFails()
 {
     $this->forAll([Generator\frequency([[8, Generator\nat(1, 100)], [4, Generator\nat(100, 200)], [4, Generator\nat(200, 300)]])])->then(function ($element) {
         // Expected to shrunk always to 1
         $this->assertEquals(0, $element);
     });
 }
コード例 #3
0
ファイル: MapTest.php プロジェクト: giorgiosironi/eris
 public function testShrinkingMappedValuesInsideOtherGenerators()
 {
     $this->forAll(Generator\vector(3, Generator\map(function ($n) {
         return $n * 2;
     }, Generator\nat())))->then(function ($tripleOfEvenNumbers) {
         $this->assertLessThanOrEqual(100, array_sum($tripleOfEvenNumbers), "The triple sum " . var_export($tripleOfEvenNumbers, true) . " is not less than 100");
     });
 }
コード例 #4
0
ファイル: CollectTest.php プロジェクト: giorgiosironi/eris
 public function testGeneratedDataCollectionWithCustomMapper()
 {
     $this->forAll(Generator\seq(Generator\nat()))->withMaxSize(10)->hook(Listener\collectFrequencies(function ($array) {
         return count($array);
     }))->then(function ($array) {
         $this->assertEquals(count($array), count(array_reverse($array)));
     });
 }
コード例 #5
0
 /**
  * Shrinking may be avoided when then() is slow or non-deterministic.
  */
 public function testThenIsNotCalledMultipleTime()
 {
     $this->calls = 0;
     $this->forAll(Generator\nat())->disableShrinking()->then(function ($number) {
         $this->calls++;
         $this->assertTrue(false, "Total calls: {$this->calls}");
     });
 }
コード例 #6
0
ファイル: SetTest.php プロジェクト: giorgiosironi/eris
 public function testSetsOfAnotherGeneratorsDomain()
 {
     $this->forAll(Generator\set(Generator\nat()))->then(function ($set) {
         $this->assertInternalType('array', $set);
         foreach ($set as $element) {
             $this->assertGreaterThanOrEqual(0, $element);
         }
     });
 }
コード例 #7
0
ファイル: SortTest.php プロジェクト: nicoder/eris
 public function testArraySorting()
 {
     $this->forAll(Generator\seq(Generator\nat()))->then(function ($array) {
         sort($array);
         for ($i = 0; $i < count($array) - 1; $i++) {
             $this->assertTrue($array[$i] <= $array[$i + 1], "Array is not sorted: " . var_export($array, true));
         }
     });
 }
コード例 #8
0
ファイル: SequenceTest.php プロジェクト: giorgiosironi/eris
 public function testArraySortingIsIdempotent()
 {
     $this->forAll(Generator\seq(Generator\nat()))->then(function ($array) {
         sort($array);
         $expected = $array;
         sort($array);
         $this->assertEquals($expected, $array);
     });
 }
コード例 #9
0
ファイル: BindTest.php プロジェクト: giorgiosironi/eris
 public function testCreatingABrandNewGeneratorFromAGeneratedValue()
 {
     $this->forAll(Generator\bind(Generator\vector(4, Generator\nat()), function ($vector) {
         return Generator\tuple(Generator\elements($vector), Generator\constant($vector));
     }))->then(function ($tuple) {
         list($element, $vector) = $tuple;
         $this->assertContains($element, $vector);
     });
 }
コード例 #10
0
ファイル: EnduranceTest.php プロジェクト: onebip/recruiter
 public function testNotWithstandingCrashesJobsAreEventuallyPerformed()
 {
     $this->limitTo(100)->forAll(Generator\bind(Generator\choose(1, 4), function ($workers) {
         return Generator\tuple(Generator\constant($workers), Generator\seq(Generator\oneOf(Generator\map(function ($durationAndTag) {
             list($duration, $tag) = $durationAndTag;
             return ['enqueueJob', $duration, $tag];
         }, Generator\tuple(Generator\nat(), Generator\elements(['generic', 'fast-lane']))), Generator\map(function ($workerIndex) {
             return ['restartWorkerGracefully', $workerIndex];
         }, Generator\choose(0, $workers - 1)), Generator\map(function ($workerIndex) {
             return ['restartWorkerByKilling', $workerIndex];
         }, Generator\choose(0, $workers - 1)), Generator\constant('restartRecruiterGracefully'), Generator\constant('restartRecruiterByKilling'), Generator\map(function ($milliseconds) {
             return ['sleep', $milliseconds];
         }, Generator\choose(1, 1000)))));
     }))->hook(Listener\log('/tmp/recruiter-test-iterations.log'))->hook(Listener\collectFrequencies())->disableShrinking()->then(function ($tuple) {
         list($workers, $actions) = $tuple;
         $this->clean();
         $this->start($workers);
         foreach ($actions as $action) {
             $this->logAction($action);
             if (is_array($action)) {
                 $arguments = $action;
                 $method = array_shift($arguments);
                 call_user_func_array([$this, $method], $arguments);
             } else {
                 $this->{$action}();
             }
         }
         $estimatedTime = max(count($actions) * 4, 60);
         Timeout::inSeconds($estimatedTime, function () {
             return "all {$this->jobs} jobs to be performed. Now is " . date('c') . " Logs: " . $this->files();
         })->until(function () {
             return $this->jobRepository->countArchived() === $this->jobs;
         });
         $at = T\now();
         $statistics = $this->recruiter->statistics($tag = null, $at);
         $this->assertInvariantsOnStatistics($statistics);
         // TODO: remove duplication
         $statisticsByTag = [];
         $cumulativeThroughput = 0;
         foreach (['generic', 'fast-lane'] as $tag) {
             $statisticsByTag[$tag] = $this->recruiter->statistics($tag, $at);
             $this->assertInvariantsOnStatistics($statisticsByTag[$tag]);
             $cumulativeThroughput += $statisticsByTag[$tag]['throughput']['value'];
         }
         var_dump($statistics, $statisticsByTag);
         // TODO: add tolerance
         $this->assertEquals($statistics['throughput']['value'], $cumulativeThroughput);
     });
 }
コード例 #11
0
ファイル: ConstantTest.php プロジェクト: nicoder/eris
 public function testUseConstantGeneratorImplicitly()
 {
     $this->forAll(Generator\nat(), 2)->then(function ($number, $alwaysTwo) {
         $this->assertTrue($number * $alwaysTwo % 2 === 0);
     });
 }
コード例 #12
0
ファイル: ReadmeTest.php プロジェクト: nicoder/eris
 public function testNaturalNumbersMagnitude()
 {
     $this->forAll(Generator\nat(1000))->then(function ($number) {
         $this->assertTrue($number < 42, "{$number} is not less than 42 apparently");
     });
 }
コード例 #13
0
ファイル: SequenceTest.php プロジェクト: nicoder/eris
 public function testArrayReverse()
 {
     $this->forAll(Generator\seq(Generator\nat()))->then(function ($array) {
         $this->assertEquals($array, array_reverse(array_reverse($array)));
     });
 }
コード例 #14
0
 public function testDiff()
 {
     $this->iterations = 1000;
     $this->forAll(Generator\nat(), Generator\date(new DateTime('1980-01-01'), new DateTime('2020-12-31')))->then(function ($days, $datetime) {
         $date = UTCDateTime::box($datetime);
         $addDiff = $date->addDays($days)->diff($date)->days;
         $subDiff = $date->subtractDays($days)->diff($date)->days;
         $this->assertSame($days, $addDiff, "adding and diffing {$days} days(s) from {$date->toIso8601()} returned {$addDiff}");
         $this->assertEquals($days, $subDiff, "subtracting and diffing {$days} month(s) from {$date->toIso8601()} returned {$subDiff}");
     });
 }
コード例 #15
0
ファイル: SampleTest.php プロジェクト: giorgiosironi/eris
 public function testSamplingShrinking()
 {
     $generator = Generator\nat(1000);
     var_dump($this->sampleShrink($generator));
 }
コード例 #16
0
ファイル: SumTest.php プロジェクト: giorgiosironi/eris
 public function testPropertyNeverSatisfied()
 {
     $this->forAll(Generator\nat(1000), Generator\nat(1000))->then(function ($first, $second) {
         $this->assertEquals(-1, my_sum($first, $second), "Summing {$first} and {$second}");
     });
 }