aboutsummaryrefslogtreecommitdiff
path: root/test/org/traccar/reports/ReportUtilsTest.java
blob: 9a30ce3a78aa38a366714484195264957b48e5cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package org.traccar.reports;

import org.junit.Assert;
import org.junit.Test;
import org.traccar.model.Position;

public class ReportUtilsTest {

    @Test
    public void testCalculateDistance() {
        Position startPosition = new Position();
        startPosition.set(Position.KEY_TOTAL_DISTANCE, 500.0);
        Position endPosition = new Position();
        endPosition.set(Position.KEY_TOTAL_DISTANCE, 700.0);
        Assert.assertEquals(ReportUtils.calculateDistance(startPosition, endPosition), 200.0, 10);
        startPosition.set(Position.KEY_ODOMETER, 50000);
        endPosition.set(Position.KEY_ODOMETER, 51000);
        Assert.assertEquals(ReportUtils.calculateDistance(startPosition, endPosition), 1000.0, 10);
    }

    @Test
    public void testCalculateSpentFuel() {
        Position startPosition = new Position();
        Position endPosition = new Position();
        Assert.assertEquals(ReportUtils.calculateFuel(startPosition, endPosition), "-");
        startPosition.setProtocol("meitrack");
        startPosition.set(Position.KEY_FUEL, 0.07);
        endPosition.set(Position.KEY_FUEL, 0.05);
        Assert.assertEquals(ReportUtils.calculateFuel(startPosition, endPosition), "0.02 %");
        startPosition.setProtocol("galileo");
        Assert.assertEquals(ReportUtils.calculateFuel(startPosition, endPosition), "0.02 %");
        startPosition.setProtocol("noran");
        Assert.assertEquals(ReportUtils.calculateFuel(startPosition, endPosition), "0.02 %");
    }

}