<commit_before><?php
/**
 * Copyright (C) 2016 <NAME>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

namespace CrEOF\Geo\Obj\Tests;

use CrEOF\Geo\Obj\Configuration;
use CrEOF\Geo\Obj\Exception\RangeException;
use CrEOF\Geo\Obj\Exception\UnexpectedValueException;
use CrEOF\Geo\Obj\Point;
use CrEOF\Geo\Obj\ObjectInterface;
use CrEOF\Geo\Obj\Validator\GeographyValidator;
use CrEOF\Geo\Obj\Validator\DValidator;

/**
 * Class PointTest
 *
 * @author  <NAME> <<EMAIL>>
 * @license http://dlambert.mit-license.org MIT
 */
class PointTest extends \PHPUnit_Framework_TestCase
{
    public function testArrayPoint()
    {
        $point = new Point([0,0]);

        static::assertEquals([0,0], $point->getValue());
    }

    public function testWkbPoint()
    {
        $wkb   = pack('H*', '01010000003D0AD7A3701D41400000000000C055C0');
        $point = new Point($wkb);

        static::assertEquals([34.23, -87], $point->getValue());
    }

    public function testWktPoint()
    {
        $point = new Point('POINT(34.23 -87)');

        static::assertEquals([34.23, -87], $point->getValue());
    }

    public function testCountPoint()
    {
        $point = new Point([0,0]);

        static::assertCount(2, $point);
    }

    /**
     * @expectedException        UnexpectedValueException
     * @expectedExceptionMessage Unsupported value of type "LINESTRING" for CrEOF\Geo\Obj\Point
     */
    public function testBadPointWktType()
    {
        new Point('LINESTRING(0 0,1 1)');
    }

    /**
     * @expectedException        UnexpectedValueException
     * @expectedExceptionMessage Unsupported value of type "LINESTRING" for CrEOF\Geo\Obj\Point
     */
    public function testBadPointWkbType()
    {
        $wkb   = pack('H*', '0102000000020000003D0AD7A3701D41400000000000C055C06666666666A6464000000000000057C0');

        new Point($wkb);
    }

    /**
     * @expectedException        RangeException
     * @expectedExceptionMessage Point value count must be between 2 and 4.
     */
    public function testShortPoint()
    {
        new Point([0]);
    }

    /**
     * @expectedException        RangeException
     * @expectedExceptionMessage Point value count must be between 2 and 4.
     */
    public function testLongPoint()
    {
        new Point([0,0,0,0,0]);
    }

    public function testGoodPointValidatorStacking()
    {
        Configuration::getInstance()->pushValidator(ObjectInterface::T_POINT, new GeographyValidator(GeographyValidator::CRITERIA_LATITUDE_FIRST));
        Configuration::getInstance()->pushValidator(ObjectInterface::T_POINT, new DValidator(2));

        $point = new Point([20, 120]);

        static::assertEquals([20, 120], $point->getValue());
    }

    /**
     * @expectedException        RangeException
     * @expectedExceptionMessage Invalid size "3", size must be 2.
     */
    public function testBadLongPointSizeInnerValidator()
    {
        Configuration::getInstance()->pushValidator(ObjectInterface::T_POINT, new GeographyValidator(GeographyValidator::CRITERIA_LATITUDE_FIRST));
        Configuration::getInstance()->pushValidator(ObjectInterface::T_POINT, new DValidator(2));

        new Point([20, 10, 30]);
    }

    /**
     * @expectedException        RangeException
     * @expectedExceptionMessage Invalid size "3", size must be 4.
     */
    public function testBadShortPointSizeInnerValidator()
    {
        Configuration::getInstance()->pushValidator(ObjectInterface::T_POINT, new GeographyValidator(GeographyValidator::CRITERIA_LATITUDE_FIRST));
        Configuration::getInstance()->pushValidator(ObjectInterface::T_POINT, new DValidator(4));

        new Point([20, 10, 30]);
    }
}<commit_msg>Refactor PointTest, move data to data provider method<commit_after><?php
/**
 * Copyright (C) 2016 <NAME>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

namespace CrEOF\Geo\Obj\Tests;

use CrEOF\Geo\Obj\Configuration;
use CrEOF\Geo\Obj\Exception\RangeException;
use CrEOF\Geo\Obj\Exception\UnexpectedValueException;
use CrEOF\Geo\Obj\Point;
use CrEOF\Geo\Obj\ObjectInterface;
use CrEOF\Geo\Obj\Validator\GeographyValidator;
use CrEOF\Geo\Obj\Validator\DValidator;

/**
 * Class PointTest
 *
 * @author  <NAME> <<EMAIL>>
 * @license http://dlambert.mit-license.org MIT
 */
class PointTest extends \PHPUnit_Framework_TestCase
{
    public function testCountPoint()
    {
        $point = new Point([0,0]);

        static::assertCount(2, $point);
    }

    /**
     * @param $value
     * @param $validators
     * @param $expected
     *
     * @dataProvider pointTestData
     */
    public function testParser($value, $validators, $expected)
    {
        if (null !== $validators) {
            foreach ($validators as $validator) {
                Configuration::getInstance()->pushValidator(ObjectInterface::T_POINT, $validator);
            }
        }
        try {
            $actual = (new Point($value))->getValue();
        } catch (\Exception $e) {
            $actual = $e;
        }

        self::assertEquals($expected, $actual);
    }

    public function pointTestData()
    {
        return [
            'testGoodArrayPoint' => [
                'value'      => [0,0],
                'validators' => null,
                'expected'   => [0,0]
            ],
            'testGoodWkbPoint' => [
                'value'      => pack('H*', '01010000003D0AD7A3701D41400000000000C055C0'),
                'validators' => null,
                'expected'   => [34.23, -87]
            ],
            'testBadPointWktType' => [
                'value'      => 'LINESTRING(0 0,1 1)',
                'validators' => null,
                'expected'   => new UnexpectedValueException('Unsupported value of type "LINESTRING" for CrEOF\Geo\Obj\Point')
            ],
            'testBadPointWkbType' => [
                'value'      => pack('H*', '0102000000020000003D0AD7A3701D41400000000000C055C06666666666A6464000000000000057C0'),
                'validators' => null,
                'expected'   => new UnexpectedValueException('Unsupported value of type "LINESTRING" for CrEOF\Geo\Obj\Point')
            ],
            'testBadShortPoint' => [
                'value'      => [0],
                'validators' => null,
                'expected'   => new RangeException('Point value count must be between 2 and 4.')
            ],
            'testBadLongPoint' => [
                'value'      => [0,0,0,0,0],
                'validators' => null,
                'expected'   => new RangeException('Point value count must be between 2 and 4.')
            ],
            'testGoodPointValidatorStacking' => [
                'value'      => [20, 120],
                'validators' => [
                    new GeographyValidator(GeographyValidator::CRITERIA_LATITUDE_FIRST),
                    new DValidator(2)
                ],
                'expected'   => [20, 120]
            ],
            'testBadLongPointDValidator' => [
                'value'      => [20, 10, 30],
                'validators' => [
                    new GeographyValidator(GeographyValidator::CRITERIA_LATITUDE_FIRST),
                    new DValidator(2)
                ],
                'expected'   => new RangeException('Invalid size "3", size must be 2.')
            ],
            'testBadShortPointDValidator' => [
                'value'      => [20, 10, 30],
                'validators' => [
                    new GeographyValidator(GeographyValidator::CRITERIA_LATITUDE_FIRST),
                    new DValidator(4)
                ],
                'expected'   => new RangeException('Invalid size "3", size must be 4.')
            ]
        ];
    }
}
{'fraction_non_alphanumeric': 0.10883864337101747, 'fraction_numerical': 0.03576567317574512, 'mean_word_length': 2.5592538405267007, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 10, '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': '616113', 'n_tokens_mistral': 2928, 'n_tokens_neox': 2606, 'n_words': 740}