php-histogram/tests/BufferTest.php

42 lines
1.1 KiB
PHP

<?php
namespace NoccyLabs\Histogram;
class BufferTest extends \PhpUnit\Framework\TestCase
{
public function testThatCreatingBufferSetsSize()
{
$buffer = new Buffer(2);
$buffer->pushSamples(1, 2, 3);
$this->assertEquals(2, count($buffer));
$this->assertEquals([2, 3], $buffer->getSamples());
}
public function testGettingSampleMaxMinValues()
{
$buffer = new Buffer(5);
$buffer->pushSamples(10, 20, 30, 40, 50);
$this->assertEquals(10, $buffer->getSampleMin());
$this->assertEquals(30, $buffer->getSampleAverage());
$this->assertEquals(50, $buffer->getSampleMax());
}
public function testMappingTheBuffer()
{
$buffer = new Buffer(5);
$buffer->pushSamples(10, 20, 30, 40, 50);
$mapped = $buffer->getMappedSamples(0, 1000, 0, 100);
$this->assertEquals([1, 2, 3, 4, 5], $mapped);
$mapped = $buffer->getMappedSamples(0, 100, 500, 600);
$this->assertEquals([510, 520, 530, 540, 550], $mapped);
$mapped = $buffer->getMappedSamples(0, 100);
$this->assertEquals([0.1, 0.2, 0.3, 0.4, 0.5], $mapped);
}
}