initital commit
This commit is contained in:
74
tests/Unit/Services/Granularity/DayWeatherByDateTest.php
Normal file
74
tests/Unit/Services/Granularity/DayWeatherByDateTest.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Unit\Services\Granularity;
|
||||
|
||||
use App\DTO\WeatherAtTimePoint;
|
||||
use App\Services\Granularity\DayWeatherByDate;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DayWeatherByDateTest extends TestCase
|
||||
{
|
||||
public function testCalculateFromMultipleRecordsInDay(): void
|
||||
{
|
||||
$data = [
|
||||
new WeatherAtTimePoint(
|
||||
new \DateTimeImmutable('2020-01-01 01:01:01'),
|
||||
0.2,
|
||||
5.2,
|
||||
5
|
||||
),
|
||||
new WeatherAtTimePoint(
|
||||
new \DateTimeImmutable('2020-01-01 01:01:10'),
|
||||
-1.1,
|
||||
6.2,
|
||||
10.5
|
||||
)
|
||||
];
|
||||
|
||||
$service = $this->createService();
|
||||
$calculatedData = $service->calculateFromMultipleRecords($data);
|
||||
$this->assertEquals(1, count($calculatedData));
|
||||
$this->assertEquals("2020-01-01 00:00:00", $calculatedData[0]->date->format('Y-m-d H:i:s'));
|
||||
$this->assertEquals($calculatedData[0]->min, -1.1);
|
||||
$this->assertEquals($calculatedData[0]->max, 6.2);
|
||||
$temperatureValue = ($data[0]->value + $data[1]->value) / 2;
|
||||
$this->assertEquals($calculatedData[0]->value, $temperatureValue);
|
||||
}
|
||||
|
||||
public function testCalculateFromSingleRecordsInDay(): void
|
||||
{
|
||||
$data = [
|
||||
new WeatherAtTimePoint(
|
||||
new \DateTimeImmutable('2020-01-01 01:01:01'),
|
||||
0.2,
|
||||
5.2,
|
||||
5
|
||||
),
|
||||
new WeatherAtTimePoint(
|
||||
new \DateTimeImmutable('2020-01-02 01:01:10'),
|
||||
-1.1,
|
||||
6.2,
|
||||
10.5
|
||||
)
|
||||
];
|
||||
|
||||
$service = $this->createService();
|
||||
$calculatedData = $service->calculateFromMultipleRecords($data);
|
||||
$this->assertEquals(2, count($calculatedData));
|
||||
$this->assertEquals("2020-01-01 00:00:00", $calculatedData[0]->date->format('Y-m-d H:i:s'));
|
||||
$this->assertEquals($calculatedData[0]->min, 0.2);
|
||||
$this->assertEquals($calculatedData[0]->max, 5.2);
|
||||
$this->assertEquals($calculatedData[0]->value, 5);
|
||||
$this->assertEquals("2020-01-02 00:00:00", $calculatedData[1]->date->format('Y-m-d H:i:s'));
|
||||
$this->assertEquals($calculatedData[1]->min, -1.1);
|
||||
$this->assertEquals($calculatedData[1]->max, 6.2);
|
||||
$this->assertEquals($calculatedData[1]->value, 10.5);
|
||||
}
|
||||
|
||||
private function createService(): DayWeatherByDate
|
||||
{
|
||||
return new DayWeatherByDate();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user