android.hardware.cts.helpers.SensorStats

Here are the examples of the java api class android.hardware.cts.helpers.SensorStats taken from open source projects.

1. StandardDeviationVerificationTest#runVerification()

Project: CtsVerifier
File: StandardDeviationVerificationTest.java
private void runVerification(float[] threshold, float[][] values, boolean pass, float[] standardDeviations) {
    SensorStats stats = new SensorStats();
    StandardDeviationVerification verification = getVerification(threshold, values);
    if (pass) {
        verification.verify(stats);
    } else {
        boolean failed = false;
        try {
            verification.verify(stats);
        } catch (AssertionError e) {
            failed = true;
        }
        assertTrue("Expected an AssertionError", failed);
    }
    assertEquals(pass, stats.getValue(StandardDeviationVerification.PASSED_KEY));
    float[] actual = (float[]) stats.getValue(SensorStats.STANDARD_DEVIATION_KEY);
    for (int i = 0; i < standardDeviations.length; i++) {
        assertEquals(standardDeviations[i], actual[i], 0.1);
    }
}

2. MagnitudeVerificationTest#runStats()

Project: CtsVerifier
File: MagnitudeVerificationTest.java
private void runStats(float expected, float threshold, float[][] values, boolean pass, float magnitude) {
    SensorStats stats = new SensorStats();
    MagnitudeVerification verification = getVerification(expected, threshold, values);
    if (pass) {
        verification.verify(stats);
    } else {
        try {
            verification.verify(stats);
            fail("Expected an AssertionError");
        } catch (AssertionError e) {
        }
    }
    assertEquals(pass, stats.getValue(MagnitudeVerification.PASSED_KEY));
    assertEquals(magnitude, (Float) stats.getValue(SensorStats.MAGNITUDE_KEY), 0.01);
}

3. EventOrderingVerificationTest#testMultipleOutOfOrder()

Project: CtsVerifier
File: EventOrderingVerificationTest.java
/**
     * Test that the verification fails when there are multiple events out of order.
     */
public void testMultipleOutOfOrder() {
    SensorStats stats = new SensorStats();
    EventOrderingVerification verification = getVerification(4, 0, 1, 2, 3);
    try {
        verification.verify(stats);
        fail("Expected an AssertionError");
    } catch (AssertionError e) {
    }
    verifyStats(stats, false, 4);
    List<Integer> indices = getIndices(stats);
    assertTrue(indices.contains(1));
    assertTrue(indices.contains(2));
    assertTrue(indices.contains(3));
    assertTrue(indices.contains(4));
}

4. EventOrderingVerificationTest#testSingleOutofOrder()

Project: CtsVerifier
File: EventOrderingVerificationTest.java
/**
     * Test that the verification fails when there is one event out of order.
     */
public void testSingleOutofOrder() {
    SensorStats stats = new SensorStats();
    EventOrderingVerification verification = getVerification(0, 2, 1, 3, 4);
    try {
        verification.verify(stats);
        fail("Expected an AssertionError");
    } catch (AssertionError e) {
    }
    verifyStats(stats, false, 1);
    List<Integer> indices = getIndices(stats);
    assertTrue(indices.contains(2));
}

5. MeanVerificationTest#testVerify()

Project: CtsVerifier
File: MeanVerificationTest.java
/**
     * Test {@link MeanVerification#verify(TestSensorEnvironment, SensorStats)}.
     */
public void testVerify() {
    float[][] values = { { 0, 1, 0 }, { 1, 2, 1 }, { 2, 3, 4 }, { 3, 4, 9 }, { 4, 5, 16 } };
    float[] expected = { 2.0f, 3.0f, 6.0f };
    float[] threshold = { 0.1f, 0.1f, 0.1f };
    SensorStats stats = new SensorStats();
    MeanVerification verification = getVerification(expected, threshold, values);
    verification.verify(stats);
    verifyStats(stats, true, new float[] { 2.0f, 3.0f, 6.0f });
    expected = new float[] { 2.5f, 2.5f, 5.5f };
    threshold = new float[] { 0.6f, 0.6f, 0.6f };
    stats = new SensorStats();
    verification = getVerification(expected, threshold, values);
    verification.verify(stats);
    verifyStats(stats, true, new float[] { 2.0f, 3.0f, 6.0f });
    expected = new float[] { 2.5f, 2.5f, 5.5f };
    threshold = new float[] { 0.1f, 0.6f, 0.6f };
    stats = new SensorStats();
    verification = getVerification(expected, threshold, values);
    try {
        verification.verify(stats);
        fail("Expected an AssertionError");
    } catch (AssertionError e) {
    }
    verifyStats(stats, false, new float[] { 2.0f, 3.0f, 6.0f });
    expected = new float[] { 2.5f, 2.5f, 5.5f };
    threshold = new float[] { 0.6f, 0.1f, 0.6f };
    stats = new SensorStats();
    verification = getVerification(expected, threshold, values);
    try {
        verification.verify(stats);
        fail("Expected an AssertionError");
    } catch (AssertionError e) {
    }
    verifyStats(stats, false, new float[] { 2.0f, 3.0f, 6.0f });
    threshold = new float[] { 0.6f, 0.6f, 0.1f };
    stats = new SensorStats();
    verification = getVerification(expected, threshold, values);
    try {
        verification.verify(stats);
        fail("Expected an AssertionError");
    } catch (AssertionError e) {
    }
    verifyStats(stats, false, new float[] { 2.0f, 3.0f, 6.0f });
}

6. FrequencyVerificationTest#testVerifification()

Project: CtsVerifier
File: FrequencyVerificationTest.java
/**
     * Test that the verifications passes/fails based on threshold given.
     */
public void testVerifification() {
    // 1000Hz
    long[] timestamps = { 0, 1000000, 2000000, 3000000, 4000000 };
    SensorStats stats = new SensorStats();
    ISensorVerification verification = getVerification(999.0, 1001.0, timestamps);
    verification.verify(getEnvironment(1000), stats);
    verifyStats(stats, true, 1000.0);
    stats = new SensorStats();
    verification = getVerification(850.0, 1050.0, timestamps);
    verification.verify(getEnvironment(950), stats);
    verifyStats(stats, true, 1000.0);
    stats = new SensorStats();
    verification = getVerification(950.0, 1150.0, timestamps);
    verification.verify(getEnvironment(1050), stats);
    verifyStats(stats, true, 1000.0);
    stats = new SensorStats();
    verification = getVerification(850.0, 975.0, timestamps);
    try {
        verification.verify(getEnvironment(950), stats);
        fail("Expected an AssertionError");
    } catch (AssertionError e) {
    }
    verifyStats(stats, false, 1000.0);
    stats = new SensorStats();
    verification = getVerification(1025.0, 1150.0, timestamps);
    try {
        verification.verify(getEnvironment(1050), stats);
        fail("Expected an AssertionError");
    } catch (AssertionError e) {
    }
    verifyStats(stats, false, 1000.0);
}

7. JitterVerificationTest#testVerify()

Project: CtsVerifier
File: JitterVerificationTest.java
public void testVerify() {
    final int SAMPLE_SIZE = 100;
    // for unit testing the verification, only the parameter 'sensorMightHaveMoreListeners' is
    // required
    TestSensorEnvironment environment = new TestSensorEnvironment(null, /* context */
    null, /* sensor */
    false, /* sensorMightHaveMoreListeners */
    0, /*samplingPeriodUs */
    0);
    // 100 samples at 1000Hz
    long[] timestamps = new long[SAMPLE_SIZE];
    for (int i = 0; i < SAMPLE_SIZE; i++) {
        timestamps[i] = i * 100000;
    }
    SensorStats stats = new SensorStats();
    ISensorVerification verification = getVerification(1, timestamps);
    verification.verify(environment, stats);
    verifyStats(stats, true, 0.0);
    // 90 samples at 1000Hz, 10 samples at 2000Hz
    long timestamp = 0;
    for (int i = 0; i < SAMPLE_SIZE; i++) {
        timestamps[i] = timestamp;
        timestamp += (i % 10 == 0) ? 500000 : 1000000;
    }
    stats = new SensorStats();
    verification = getVerification(1, timestamps);
    try {
        verification.verify(environment, stats);
        fail("Expected an AssertionError");
    } catch (AssertionError e) {
    }
    verifyStats(stats, false, 47.34);
}

8. EventOrderingVerificationTest#testSequentialTimestamp()

Project: CtsVerifier
File: EventOrderingVerificationTest.java
/**
     * Test that the verification passes when the timestamps are increasing.
     */
public void testSequentialTimestamp() {
    SensorStats stats = new SensorStats();
    EventOrderingVerification verification = getVerification(0, 1, 2, 3, 4);
    verification.verify(stats);
    verifyStats(stats, true, 0);
}

9. EventOrderingVerificationTest#testSameTimestamp()

Project: CtsVerifier
File: EventOrderingVerificationTest.java
/**
     * Test that the verification passes when the timestamps are the same.
     */
public void testSameTimestamp() {
    SensorStats stats = new SensorStats();
    EventOrderingVerification verification = getVerification(0, 0, 0, 0, 0);
    verification.verify(stats);
    verifyStats(stats, true, 0);
}

10. EventOrderingVerificationTest#testNoEvents()

Project: CtsVerifier
File: EventOrderingVerificationTest.java
/**
     * Test that the verification passes when there are no results.
     */
public void testNoEvents() {
    SensorStats stats = new SensorStats();
    EventOrderingVerification verification = getVerification();
    verification.verify(stats);
    verifyStats(stats, true, 0);
}

11. EventGapVerificationTest#runVerification()

Project: CtsVerifier
File: EventGapVerificationTest.java
private void runVerification(int expected, long[] timestamps, boolean pass, int[] indices) {
    SensorStats stats = new SensorStats();
    ISensorVerification verification = getVerification(expected, timestamps);
    TestSensorEnvironment environment = new TestSensorEnvironment(null, null, false, 0, 0);
    if (pass) {
        verification.verify(environment, stats);
    } else {
        boolean failed = false;
        try {
            verification.verify(environment, stats);
        } catch (AssertionError e) {
            failed = true;
        }
        assertTrue("Expected an AssertionError", failed);
    }
    assertEquals(pass, stats.getValue(EventGapVerification.PASSED_KEY));
    assertEquals(indices.length, stats.getValue(SensorStats.EVENT_GAP_COUNT_KEY));
    assertNotNull(stats.getValue(SensorStats.EVENT_GAP_POSITIONS_KEY));
    int[] actualIndices = (int[]) stats.getValue(SensorStats.EVENT_GAP_POSITIONS_KEY);
    assertEquals(indices.length, actualIndices.length);
    for (int i = 0; i < indices.length; i++) {
        assertEquals(indices[i], actualIndices[i]);
    }
}