2021-02-27 11:08:39 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
2022-06-21 11:57:17 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2021-02-27 11:08:39 +01:00
|
|
|
*/
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-02-27 11:08:39 +01:00
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
2024-09-16 13:13:55 +02:00
|
|
|
*
|
2021-02-27 11:08:39 +01:00
|
|
|
*/
|
|
|
|
class RangeDetectionTest extends TestCase
|
|
|
|
{
|
2024-08-22 08:57:52 +02:00
|
|
|
protected function setUp(): void
|
2021-02-27 11:08:39 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_range_detection()
|
|
|
|
{
|
|
|
|
$ranges = [];
|
|
|
|
$ranges[] = [100, 105];
|
|
|
|
$ranges[] = [106, 110];
|
|
|
|
$ranges[] = [110, 115];
|
|
|
|
|
|
|
|
$expanded_ranges = [];
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
foreach ($ranges as $range) {
|
|
|
|
$expanded_ranges = array_merge(array_values($expanded_ranges), array_values($this->makeRanges($range)));
|
2021-02-27 11:08:39 +01:00
|
|
|
}
|
|
|
|
|
2021-02-28 05:32:08 +01:00
|
|
|
$value_count_array = array_count_values($expanded_ranges);
|
2021-02-27 11:08:39 +01:00
|
|
|
|
2021-02-28 05:32:08 +01:00
|
|
|
$value_count_array = array_diff($value_count_array, [1]);
|
|
|
|
|
|
|
|
$this->assertEquals(count($value_count_array), 1);
|
2021-02-27 11:08:39 +01:00
|
|
|
}
|
|
|
|
|
2021-02-28 03:12:55 +01:00
|
|
|
private function makeRanges(array $range)
|
2021-02-27 11:08:39 +01:00
|
|
|
{
|
|
|
|
return range($range[0], $range[1]);
|
|
|
|
}
|
|
|
|
}
|