<commit_before><?php
namespace LVAC\Test\Race;

use \LVAC\Slug;
use \Carbon\Carbon as c;

class RaceTest extends \PHPUnit_Framework_TestCase
{
    protected $db;
    public function __construct()
    {
        $this->db = new \PDO(
            'sqlite::memory:'
        );
        $sql = "CREATE TABLE races
            (
                id INTEGER PRIMARY KEY ASC,
                title TEXT,
                date,
                description TEXT,
                slug TEXT,
                latitude TEXT,
                longitude TEXT,
                report TEXT
            )";
        $this->db->exec($sql);

        $race_mapper = new \LVAC\Race\Mapper($this->db);
        $faker = \Faker\Factory::create();

        for ($i = 0; $i < 20; $i++) {
            $race = new \LVAC\Race\Race();
            $race->setTitle($faker->sentence(rand(3, 10)));
            $race->setDate($faker->dateTimeBetween('-3 years', 'now')->format('Y-m-d H:i:s'));
            $race->setDescription($faker->paragraph(rand(3, 10)));
            $race->setSlug(Slug::create($race->getTitle(), $race->getDate()));
            $race->setLatitude($faker->latitude());
            $race->setLongitude($faker->longitude());

            $race_mapper->save($race);
        }

        for ($i = 0; $i < 20; $i++) {
            $race = new \LVAC\Race\Race();
            $race->setTitle($faker->sentence(rand(3, 10)));
            $race->setDate($faker->dateTimeBetween('now', '3 months')->format('Y-m-d H:i:s'));
            $race->setDescription($faker->paragraph(rand(3, 10)));
            $race->setSlug(Slug::create($race->getTitle(), $race->getDate()));
            $race->setLatitude($faker->latitude());
            $race->setLongitude($faker->longitude());

            $race_mapper->save($race);
        }
    }

    public function testGetResultsReturnsTenRaceItemsByDefault()
    {
        $race = new \LVAC\Race\Mapper($this->db);
        $result = $race->getResults();

        $this->assertEquals(10, count($result));
    }

    public function testGetResultsReturnsFiveRaceItemsIfAsked()
    {
        $race = new \LVAC\Race\Mapper($this->db);
        $result = $race->getResults(5);

        $this->assertEquals(5, count($result));
    }

    public function testGetFutureRacesReturnsTenRaceItemsByDefault()
    {
        $race = new \LVAC\Race\Mapper($this->db);
        $result = $race->getFutureRaces();

        $this->assertEquals(10, count($result));
    }

    public function testGetFutureRacesReturnsFiveRaceItemsIfAsked()
    {
        $race = new \LVAC\Race\Mapper($this->db);
        $result = $race->getFutureRaces(5);

        $this->assertEquals(5, count($result));
    }

    public function testGetMapReturnsAnArrayWithCoordinates()
    {
        $race = new \LVAC\Race\Mapper($this->db);
        $result = $race->getFutureRaces(1);
        $map = $result[0]->getMap();

        $this->assertTrue(array_key_exists('latitude', $map));<commit_msg>Adds a test for getRaceBySlug()<commit_after><?php
namespace LVAC\Test\Race;

use \LVAC\Slug;
use \Carbon\Carbon as c;

class RaceTest extends \PHPUnit_Framework_TestCase
{
    protected $db;
    public function __construct()
    {
        $this->db = new \PDO(
            'sqlite::memory:'
        );
        $sql = "CREATE TABLE races
            (
                id INTEGER PRIMARY KEY ASC,
                title TEXT,
                date,
                description TEXT,
                slug TEXT,
                latitude TEXT,
                longitude TEXT,
                report TEXT
            )";
        $this->db->exec($sql);

        $race_mapper = new \LVAC\Race\Mapper($this->db);
        $faker = \Faker\Factory::create();

        for ($i = 0; $i < 20; $i++) {
            $race = new \LVAC\Race\Race();
            $race->setTitle($faker->sentence(rand(3, 10)));
            $race->setDate($faker->dateTimeBetween('-3 years', 'now')->format('Y-m-d H:i:s'));
            $race->setDescription($faker->paragraph(rand(3, 10)));
            $race->setSlug(Slug::create($race->getTitle(), $race->getDate()));
            $race->setLatitude($faker->latitude());
            $race->setLongitude($faker->longitude());

            $race_mapper->save($race);
        }

        for ($i = 0; $i < 20; $i++) {
            $race = new \LVAC\Race\Race();
            $race->setTitle($faker->sentence(rand(3, 10)));
            $race->setDate($faker->dateTimeBetween('now', '3 months')->format('Y-m-d H:i:s'));
            $race->setDescription($faker->paragraph(rand(3, 10)));
            $race->setSlug(Slug::create($race->getTitle(), $race->getDate()));
            $race->setLatitude($faker->latitude());
            $race->setLongitude($faker->longitude());

            $race_mapper->save($race);
        }
    }

    public function testGetResultsReturnsTenRaceItemsByDefault()
    {
        $race = new \LVAC\Race\Mapper($this->db);
        $result = $race->getResults();

        $this->assertEquals(10, count($result));
    }

    public function testGetResultsReturnsFiveRaceItemsIfAsked()
    {
        $race = new \LVAC\Race\Mapper($this->db);
        $result = $race->getResults(5);

        $this->assertEquals(5, count($result));
    }

    public function testGetFutureRacesReturnsTenRaceItemsByDefault()
    {
        $race = new \LVAC\Race\Mapper($this->db);
        $result = $race->getFutureRaces();

        $this->assertEquals(10, count($result));
    }

    public function testGetFutureRacesReturnsFiveRaceItemsIfAsked()
    {
        $race = new \LVAC\Race\Mapper($this->db);
        $result = $race->getFutureRaces(5);

        $this->assertEquals(5, count($result));
    }

    public function testGetRaceBySlug()
    {
        $faker = \Faker\Factory::create();
        $mapper = new \LVAC\Race\Mapper($this->db);

        $expected = new \LVAC\Race\Race();
        $expected->setTitle('Annual 10k');
        $expected->setDate('2014-06-06 12:00:00');
        $expected->setSlug('20140606-annual-10k');

        $mapper->save($expected);

        $result = $mapper->getRaceBySlug('20140606-annual-10k');

        $this->assertEquals($expected->getTitle(), $result->getTitle());
    }

    public function testGetMapReturnsAnArrayWithCoordinates()
    {
        $race = new \LVAC\Race\Mapper($this->db);
        $result = $race->getFutureRaces(1);
        $map = $result[0]->getMap();

        $this->assertTrue(array_key_exists('latitude', $map));
{'fraction_non_alphanumeric': 0.17225325884543763, 'fraction_numerical': 0.0148975791433892, 'mean_word_length': 2.225725725725726, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 112, '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': '2440797', 'n_tokens_mistral': 2221, 'n_tokens_neox': 2002, 'n_words': 316}