Skip to content

Commit

Permalink
Improve test for sampler
Browse files Browse the repository at this point in the history
  • Loading branch information
PineappleIOnic committed May 15, 2024
1 parent 96efcea commit 72fd846
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/e2e/AdapterBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,35 @@ public function testAdapter(): void
$response = $logger->addLog($this->log);
$this->assertEquals($this->expected, $response);
}

/**
* @throws \Throwable
*/
public function testSampler(): void
{
if (empty($this->log) || empty($this->adapter)) {
throw new \Exception('Log or adapter not set');
}

$logger = new Logger($this->adapter);
$logger->setSample(0.1);

$results = [];
$zeroCount = 0;

for ($x = 0; $x <= 100; $x++) {
$result = $logger->addLog($this->log);
$results[] = $result;
if ($result === 0) {
$zeroCount++;
}
}

$totalCount = count($results);
$zeroPercentage = ($zeroCount / $totalCount) * 100;

echo "Percentage of 0 returns: " . $zeroPercentage . "%";

$this->assertLessThan(10, $zeroPercentage);
}
}

0 comments on commit 72fd846

Please sign in to comment.