<commit_before><?php

namespace Recurrence\tests\units;

require_once __DIR__.'/../../../src/Recurrence/DatetimeProvider.php';

use atoum;
use Recurrence\Recurrence;

/**
 * Class DatetimeProvider
 * @package Recurrence\tests\units
 */
class DatetimeProvider extends atoum
{

    /**
     * @dataProvider periodAndFrequenciesDataProvider
     *
     * @param \Datetime $periodStartAt
     * @param \Datetime $periodEndAt
     * @param string    $frequency
     * @param integer   $interval
     * @param array     $expected
     */
    public function testFrequencyWithEndedPeriod(
        \Datetime $periodStartAt,
        \Datetime $periodEndAt,
        $frequency,
        $interval,
        array $expected
    )
    {
        $recurrence = (new Recurrence())
            ->setPeriodStartAt($periodStartAt)
            ->setPeriodEndAt($periodEndAt)
            ->setFrequency(new \Recurrence\Frequency($frequency))
            ->setInterval($interval)
        ;

        $period = (new \Recurrence\DatetimeProvider())->provide($recurrence);

        $key = 0;
        foreach ($period as $date) {
            $this
                ->dateTime($date)
                ->isEqualTo($expected[$key])
            ;

            $key++;
        }
    }

    /**
     * @return array
     */
    protected function periodAndFrequenciesDataProvider()
    {
        return [
            [
                new \Datetime('2017-01-01'),
                new \Datetime('2017-12-31'),
                'MONTHLY',
                1,
                [
                    new \Datetime('2017-01-01'),
                    new \Datetime('2017-02-01'),
                    new \Datetime('2017-03-01'),
                    new \Datetime('2017-04-01'),
                    new \Datetime('2017-05-01'),
                    new \Datetime('2017-06-01'),
                    new \Datetime('2017-07-01'),
                    new \Datetime('2017-08-01'),
                    new \Datetime('2017-09-01'),
                    new \Datetime('2017-10-01'),
                    new \Datetime('2017-11-01'),
                    new \Datetime('2017-12-01'),
                ]
            ],
            [
                new \Datetime('2017-01-31'),
                new \Datetime('2017-12-31'),
                'MONTHLY',
                1,
                [
                    new \Datetime('2017-01-31'),
                    new \Datetime('2017-03-03'),
                    new \Datetime('2017-04-03'),
                    new \Datetime('2017-05-03'),
                    new \Datetime('2017-06-03'),
                    new \Datetime('2017-07-03'),
                    new \Datetime('2017-08-03'),
                    new \Datetime('2017-09-03'),
                    new \Datetime('2017-10-03'),
                    new \Datetime('2017-11-03'),
                    new \Datetime('2017-12-03'),
                ]
            ],
            [
                new \Datetime('2017-01-01'),
                new \Datetime('2020-01-01'),
                'YEARLY',
                1,
                [
                    new \Datetime('2017-01-01'),
                    new \Datetime('2018-01-01'),
                    new \Datetime('2019-01-01'),
                    new \Datetime('2020-01-01'),
                ]
            ],
            [
                new \Datetime('2017-01-31'),
                new \Datetime('2017-12-31'),
                'MONTHLY',
                2,
                [
                    new \Datetime('2017-01-31'),
                    new \Datetime('2017-03-31'),
                    new \Datetime('2017-05-31'),
                    new \Datetime('2017-07-31'),
                    new \Datetime('2017-10-01'),
                    new \Datetime('2017-12-01'),
                ]
            ],
            [
                new \Datetime('2017-01-01'),
                new \Datetime('2020-01-01'),
                'YEARLY',
                2,
                [
                    new \Datetime('2017-01-01'),<commit_msg>Add count results check on until option tests<commit_after><?php

namespace Recurrence\tests\units;

require_once __DIR__.'/../../../src/Recurrence/DatetimeProvider.php';

use atoum;
use Recurrence\Recurrence;

/**
 * Class DatetimeProvider
 * @package Recurrence\tests\units
 */
class DatetimeProvider extends atoum
{

    /**
     * @dataProvider periodAndFrequenciesDataProvider
     *
     * @param \Datetime $periodStartAt
     * @param \Datetime $periodEndAt
     * @param string    $frequency
     * @param integer   $interval
     * @param array     $expected
     */
    public function testFrequencyWithEndedPeriod(
        \Datetime $periodStartAt,
        \Datetime $periodEndAt,
        $frequency,
        $interval,
        array $expected
    )
    {
        $recurrence = (new Recurrence())
            ->setPeriodStartAt($periodStartAt)
            ->setPeriodEndAt($periodEndAt)
            ->setFrequency(new \Recurrence\Frequency($frequency))
            ->setInterval($interval)
        ;

        $period = (new \Recurrence\DatetimeProvider())->provide($recurrence);

        $this->assert
            ->integer(count($period))
            ->isEqualTo(count($expected));

        $key = 0;
        foreach ($period as $date) {
            $this
                ->dateTime($date)
                ->isEqualTo($expected[$key])
            ;

            $key++;
        }
    }

    /**
     * @return array
     */
    protected function periodAndFrequenciesDataProvider()
    {
        return [
            [
                new \Datetime('2017-01-01'),
                new \Datetime('2017-12-31'),
                'MONTHLY',
                1,
                [
                    new \Datetime('2017-01-01'),
                    new \Datetime('2017-02-01'),
                    new \Datetime('2017-03-01'),
                    new \Datetime('2017-04-01'),
                    new \Datetime('2017-05-01'),
                    new \Datetime('2017-06-01'),
                    new \Datetime('2017-07-01'),
                    new \Datetime('2017-08-01'),
                    new \Datetime('2017-09-01'),
                    new \Datetime('2017-10-01'),
                    new \Datetime('2017-11-01'),
                    new \Datetime('2017-12-01'),
                ]
            ],
            [
                new \Datetime('2017-01-31'),
                new \Datetime('2017-12-31'),
                'MONTHLY',
                1,
                [
                    new \Datetime('2017-01-31'),
                    new \Datetime('2017-03-03'),
                    new \Datetime('2017-04-03'),
                    new \Datetime('2017-05-03'),
                    new \Datetime('2017-06-03'),
                    new \Datetime('2017-07-03'),
                    new \Datetime('2017-08-03'),
                    new \Datetime('2017-09-03'),
                    new \Datetime('2017-10-03'),
                    new \Datetime('2017-11-03'),
                    new \Datetime('2017-12-03'),
                ]
            ],
            [
                new \Datetime('2017-01-01'),
                new \Datetime('2020-01-02'),
                'YEARLY',
                1,
                [
                    new \Datetime('2017-01-01'),
                    new \Datetime('2018-01-01'),
                    new \Datetime('2019-01-01'),
                    new \Datetime('2020-01-01'),
                ]
            ],
            [
                new \Datetime('2017-01-31'),
                new \Datetime('2017-12-31'),
                'MONTHLY',
                2,
                [
                    new \Datetime('2017-01-31'),
                    new \Datetime('2017-03-31'),
                    new \Datetime('2017-05-31'),
                    new \Datetime('2017-07-31'),
                    new \Datetime('2017-10-01'),
                    new \Datetime('2017-12-01'),
                ]
            ],
            [
                new \Datetime('2017-01-01'),
                new \Datetime('2020-01-01'),
                'YEARLY',
                2,
                [
                    new \Datetime('2017-01-01'),
{'fraction_non_alphanumeric': 0.1385896180215475, 'fraction_numerical': 0.08765915768854064, 'mean_word_length': 1.0644427596664139, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7310307', 'n_tokens_mistral': 2756, 'n_tokens_neox': 2179, 'n_words': 349}