<commit_before>package com.conveyal.gtfs.validator;

import com.conveyal.gtfs.TestUtils;
import com.conveyal.gtfs.loader.FeedLoadResult;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import javax.sql.DataSource;

import static com.conveyal.gtfs.GTFS.*;
import static com.conveyal.gtfs.TestUtils.assertThatSqlCountQueryYieldsExpectedCount;

public class TravelTooFastTest {
    private static String testDBName;
    private static DataSource testDataSource;
    private static String testNamespace;

    @BeforeClass
    public static void setUpClass() {
        // create a new database
        testDBName = TestUtils.generateNewDB();
        String dbConnectionUrl = String.format("jdbc:postgresql://localhost/%s", testDBName);
        testDataSource = createDataSource(dbConnectionUrl, null, null);
    }

    @AfterClass
    public static void tearDownClass() {
        TestUtils.dropDB(testDBName);
    }

    /**
     * Can validate the travel speed between stops which have different frequency of arrival and departure times.
     * The stop_times are in three parts:
     * 1. A sequence of stops with arrival and departure times. To confirm that the travel speed can be calculated when
     * all the stops provide arrival and departure times.
     * 2. A sequence of stops where only the first and last stop have an arrival and departure time. To confirm that the
     * travel speed can be calculated when intermediate stops have no arrival/departure times.
     * 3. A sequence of stops where the first and last stop have arrival and departure times only a minute apart. To
     * confirm that the travel speed can be calculated when intermediate stops have no arrival/departure times and that
     * the 'TRAVEL_TOO_FAST' error is logged.
     */
    @Test
    public void canValidateTravelSpeedBetweenStops() throws Exception {
        String zipFileName = TestUtils.zipFolderFiles("real-world-gtfs-feeds/VTA-gtfs-single-trip", true);
        // load feed into db
        FeedLoadResult feedLoadResult = load(zipFileName, testDataSource);
        testNamespace = feedLoadResult.uniqueIdentifier;
        // validate feed to create additional tables
        validate(testNamespace, testDataSource);

        assertThatSqlCountQueryYieldsExpectedCount(
            testDataSource,
            String.format("select count(*) from %s.errors where error_type = 'TRAVEL_TOO_FAST'", testNamespace),
            1);
    }
}
<commit_msg>refactor(TravelTooFastTest): Updated to use test utils to create data source.<commit_after>package com.conveyal.gtfs.validator;

import com.conveyal.gtfs.TestUtils;
import com.conveyal.gtfs.loader.FeedLoadResult;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import javax.sql.DataSource;

import static com.conveyal.gtfs.GTFS.*;
import static com.conveyal.gtfs.TestUtils.assertThatSqlCountQueryYieldsExpectedCount;

public class TravelTooFastTest {
    private static String testDBName;
    private static DataSource testDataSource;
    private static String testNamespace;

    @BeforeClass
    public static void setUpClass() {
        // create a new database
        testDBName = TestUtils.generateNewDB();
        String dbConnectionUrl = String.format("jdbc:postgresql://localhost/%s", testDBName);
        testDataSource = TestUtils.createTestDataSource(dbConnectionUrl);
    }

    @AfterClass
    public static void tearDownClass() {
        TestUtils.dropDB(testDBName);
    }

    /**
     * Can validate the travel speed between stops which have different frequency of arrival and departure times.
     * The stop_times are in three parts:
     * 1. A sequence of stops with arrival and departure times. To confirm that the travel speed can be calculated when
     * all the stops provide arrival and departure times.
     * 2. A sequence of stops where only the first and last stop have an arrival and departure time. To confirm that the
     * travel speed can be calculated when intermediate stops have no arrival/departure times.
     * 3. A sequence of stops where the first and last stop have arrival and departure times only a minute apart. To
     * confirm that the travel speed can be calculated when intermediate stops have no arrival/departure times and that
     * the 'TRAVEL_TOO_FAST' error is logged.
     */
    @Test
    public void canValidateTravelSpeedBetweenStops() throws Exception {
        String zipFileName = TestUtils.zipFolderFiles("real-world-gtfs-feeds/VTA-gtfs-single-trip", true);
        // load feed into db
        FeedLoadResult feedLoadResult = load(zipFileName, testDataSource);
        testNamespace = feedLoadResult.uniqueIdentifier;
        // validate feed to create additional tables
        validate(testNamespace, testDataSource);

        assertThatSqlCountQueryYieldsExpectedCount(
            testDataSource,
            String.format("select count(*) from %s.errors where error_type = 'TRAVEL_TOO_FAST'", testNamespace),
            1);
    }
}

{'fraction_non_alphanumeric': 0.06790123456790123, 'fraction_numerical': 0.0015929908403026682, 'mean_word_length': 3.445132743362832, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3834602', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1293, 'n_words': 459}