Files
ucvl-home-vision/android-display/tests/LocationCadenceTest.java
T

32 lines
2.5 KiB
Java
Raw Permalink Normal View History

package cn.ucvl.zhaodisplay;
/** Run with javac/java; requires no emulator and does not collect coordinates. */
public class LocationCadenceTest {
static void require(boolean value){if(!value)throw new AssertionError();}
public static void main(String[] args){
int assertions=0;
for(int seconds:new int[]{10,60,300,3600,7200,10800,14400,18000,23*3600,86400,172800,259200,30*86400}){
require(LocationCadence.seconds(seconds)==seconds);assertions++;
require(LocationCadence.due(100000,0,seconds,false));assertions++;
require(!LocationCadence.due(1000+seconds*1000L-1,1000,seconds,false));assertions++;
require(LocationCadence.due(1000+seconds*1000L,1000,seconds,false));assertions++;
require(!LocationCadence.due(10999,1000,seconds,true));assertions++;
require(LocationCadence.due(11000,1000,seconds,true));assertions++;
}
for(int invalid:new int[]{-1,0,9,59,301,3601,31*86400,Integer.MAX_VALUE}){require(LocationCadence.seconds(invalid)==300);assertions++;}
require(LocationCadence.custom(3,true)==259200);assertions++;
require(LocationCadence.custom(5,false)==18000);assertions++;
for(int invalid:new int[]{-1,0,721,Integer.MAX_VALUE}){try{LocationCadence.custom(invalid,false);throw new AssertionError();}catch(IllegalArgumentException expected){assertions++;}}
for(int seconds:new int[]{10,11,30,60,120,300,900,1800,3600,7200,10800,14400,18000,21600,43200,86399,86400}){
require(LocationCadence.sample(seconds)==seconds);assertions++;
require(LocationCadence.sampleDue(10000,0,seconds));assertions++;
require(!LocationCadence.sampleDue(1000+seconds*1000L-1,1000,seconds));assertions++;
require(LocationCadence.sampleDue(1000+seconds*1000L,1000,seconds));assertions++;
}
for(int invalid:new int[]{-1,0,9,86401,604800,Integer.MAX_VALUE}){require(!LocationCadence.sampleValid(invalid));assertions++;}
for(int[] period:new int[][]{{30,1,30},{7,60,420},{7,3600,25200},{24,3600,86400},{1,86400,86400}}){require(LocationCadence.customSample(period[0],period[1])==period[2]);assertions++;}
for(int[] period:new int[][]{{0,60},{9,1},{25,3600},{2,86400},{7,86400},{1,17},{Integer.MAX_VALUE,86400}}){try{LocationCadence.customSample(period[0],period[1]);throw new AssertionError();}catch(IllegalArgumentException expected){assertions++;}}
System.out.println("Location cadence: "+assertions+" assertions passed");
}
}