<commit_before>package com.openxc;

import java.io.File;
import java.io.IOException;

import java.net.URI;
import java.net.URISyntaxException;

import org.apache.commons.io.FileUtils;

import com.openxc.measurements.HeadlampStatus;
import com.openxc.measurements.ParkingBrakeStatus;
import com.openxc.measurements.Measurement;

import com.openxc.remote.VehicleService;

import com.openxc.sources.trace.TraceVehicleDataSource;

import com.openxc.VehicleManager;


import android.content.Intent;

import android.test.ServiceTestCase;

import android.test.suitebuilder.annotation.MediumTest;

import junit.framework.Assert;

public class SporadicDataTest extends ServiceTestCase<VehicleManager> {
    VehicleManager service;
    int headlampStatusCount = 0;
    int parkingBrakeStatusCount = 0;
    URI traceUri;
    TraceVehicleDataSource source;

    HeadlampStatus.Listener headlampListener = new HeadlampStatus.Listener() {
        public void receive(Measurement measurement) {
            headlampStatusCount += 1;
        }
    };

    ParkingBrakeStatus.Listener parkingBrakeListener =
            new ParkingBrakeStatus.Listener() {
        public void receive(Measurement measurement) {
            parkingBrakeStatusCount += 1;
        }
    };

    public SporadicDataTest() {
        super(VehicleManager.class);
    }

    private URI copyToStorage(int resource, String filename) {
        URI uri = null;
        try {
            uri = new URI("file:///sdcard/com.openxc/" + filename);
        } catch(URISyntaxException e) {
            Assert.fail("Couldn't construct resource URIs: " + e);
        }

        try {
            FileUtils.copyInputStreamToFile(
                    getContext().getResources().openRawResource(resource),
                        new File(uri));
        } catch(IOException e) {
            Assert.fail("Couldn't copy trace files to SD card" + e);
        }
        return uri;
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        traceUri = copyToStorage(R.raw.slowtrace, "slowtrace.json");

        // if the service is already running (and thus may have old data
        // cached), kill it.
        getContext().stopService(new Intent(getContext(), VehicleService.class));
        Intent startIntent = new Intent();
        startIntent.setClass(getContext(), VehicleManager.class);
        service = ((VehicleManager.VehicleBinder)
                bindService(startIntent)).getService();
        service.waitUntilBound();

        service.addListener(HeadlampStatus.class, headlampListener);
        service.addListener(ParkingBrakeStatus.class, parkingBrakeListener);

        source = new TraceVehicleDataSource(getContext(), traceUri, false);
        service.addSource(source);
    }

    @Override
    protected void tearDown() throws Exception {
        if(source != null) {
            source.stop();
        }
        super.tearDown();
    }

    @MediumTest
    public void testSlowSends() {
        TestUtils.pause(800);
        assertEquals(headlampStatusCount, 2);
        assertEquals(parkingBrakeStatusCount, 1);
    }
}
<commit_msg>Remove an unpredictable test case.<commit_after>package com.openxc;

import java.io.File;
import java.io.IOException;

import java.net.URI;
import java.net.URISyntaxException;

import org.apache.commons.io.FileUtils;

import com.openxc.measurements.HeadlampStatus;
import com.openxc.measurements.ParkingBrakeStatus;
import com.openxc.measurements.Measurement;

import com.openxc.remote.VehicleService;

import com.openxc.sources.trace.TraceVehicleDataSource;

import com.openxc.VehicleManager;


import android.content.Intent;

import android.test.ServiceTestCase;

import android.test.suitebuilder.annotation.MediumTest;

import junit.framework.Assert;

public class SporadicDataTest extends ServiceTestCase<VehicleManager> {
    VehicleManager service;
    int headlampStatusCount = 0;
    int parkingBrakeStatusCount = 0;
    URI traceUri;
    TraceVehicleDataSource source;

    HeadlampStatus.Listener headlampListener = new HeadlampStatus.Listener() {
        public void receive(Measurement measurement) {
            headlampStatusCount += 1;
        }
    };

    ParkingBrakeStatus.Listener parkingBrakeListener =
            new ParkingBrakeStatus.Listener() {
        public void receive(Measurement measurement) {
            parkingBrakeStatusCount += 1;
        }
    };

    public SporadicDataTest() {
        super(VehicleManager.class);
    }

    private URI copyToStorage(int resource, String filename) {
        URI uri = null;
        try {
            uri = new URI("file:///sdcard/com.openxc/" + filename);
        } catch(URISyntaxException e) {
            Assert.fail("Couldn't construct resource URIs: " + e);
        }

        try {
            FileUtils.copyInputStreamToFile(
                    getContext().getResources().openRawResource(resource),
                        new File(uri));
        } catch(IOException e) {
            Assert.fail("Couldn't copy trace files to SD card" + e);
        }
        return uri;
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        traceUri = copyToStorage(R.raw.slowtrace, "slowtrace.json");

        // if the service is already running (and thus may have old data
        // cached), kill it.
        getContext().stopService(new Intent(getContext(), VehicleService.class));
        Intent startIntent = new Intent();
        startIntent.setClass(getContext(), VehicleManager.class);
        service = ((VehicleManager.VehicleBinder)
                bindService(startIntent)).getService();
        service.waitUntilBound();

        service.addListener(HeadlampStatus.class, headlampListener);
        service.addListener(ParkingBrakeStatus.class, parkingBrakeListener);

        source = new TraceVehicleDataSource(getContext(), traceUri, false);
        service.addSource(source);
    }

    @Override
    protected void tearDown() throws Exception {
        if(source != null) {
            source.stop();
        }
        super.tearDown();
    }
}

{'fraction_non_alphanumeric': 0.09610983981693363, 'fraction_numerical': 0.0021248774109186006, 'mean_word_length': 2.7794935145151327, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1451934', 'n_tokens_mistral': 1716, 'n_tokens_neox': 1674, 'n_words': 349}