78 lines
2.6 KiB
Java
78 lines
2.6 KiB
Java
package ch.epfl.alpano.dem;
|
|
|
|
import static org.junit.Assert.*;
|
|
import static ch.epfl.alpano.Preconditions.checkArgument;
|
|
import java.io.File;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
|
|
import org.junit.Test;
|
|
|
|
public class HgtDiscreteElevationModelTest {
|
|
|
|
@Test
|
|
public void testHgtDiscreteElevationModel() {
|
|
String[] files = {"N45E006.hgt","N45E007.hgt","N45E008.hgt","N45E009.hgt",
|
|
"N45E010.hgt","N45E011.hgt","N46E006.hgt","N46E007.hgt",
|
|
"N46E008.hgt","N46E009.hgt","N46E010.hgt","N46E011.hgt",
|
|
"N47E006.hgt","N47E007.hgt","N47E008.hgt","N47E009.hgt",
|
|
"N47E010.hgt","N47E011.hgt","N00E000.hgt","S89W120"};
|
|
File file;
|
|
for(String txt: files){
|
|
file = new File("HGT"+File.separatorChar+txt);
|
|
if(file.exists())
|
|
new HgtDiscreteElevationModel(file);
|
|
}
|
|
assertTrue(true);
|
|
}
|
|
|
|
@Test(expected=IllegalArgumentException.class)
|
|
public void testHgtDiscreteElevationModelFails() {
|
|
String[] files = {"N45E180.hgt","N45E007.hgt",};
|
|
File file;
|
|
for(String txt: files){
|
|
file = new File("HGT"+File.separatorChar+txt);
|
|
new HgtDiscreteElevationModel(file);
|
|
}
|
|
}
|
|
|
|
@Test
|
|
public void checkFileNameSuccess() {
|
|
assertTrue(checkFileName("S00E000.hgt")!=null);
|
|
assertTrue(checkFileName("N00E000.hgt")!=null);
|
|
assertTrue(checkFileName("S00W129.hgt")!=null);
|
|
assertTrue(checkFileName("N00W000.hgt")!=null);
|
|
assertTrue(checkFileName("S69E139.hgt")!=null);
|
|
assertTrue(checkFileName("S90W180.hgt")!=null);
|
|
assertTrue(checkFileName("N90E180.hgt")!=null);
|
|
assertTrue(checkFileName("S90W180.hgt")!=null);
|
|
}
|
|
|
|
@Test(expected=IllegalArgumentException.class)
|
|
public void checkFileNameFails() {
|
|
checkFileName("E46E006.hgt");
|
|
checkFileName("N4gE006.hgt");
|
|
checkFileName("N46E0g6.hgt");
|
|
checkFileName("N46E006lhgt");
|
|
checkFileName("N46E006.hGT");
|
|
checkFileName("N4gE006.hgt");
|
|
checkFileName("N46E0g6.hgt");
|
|
checkFileName("N46E006phgt");
|
|
checkFileName("Q99E006.hGT");
|
|
}
|
|
|
|
private static final Matcher checkFileName(String txt){
|
|
final Pattern P = Pattern.compile("([NS])(\\d{2})([EW])(\\d{3})\\.hgt");
|
|
|
|
Matcher m = P.matcher(txt);
|
|
|
|
checkArgument((txt.length()==11 && m.find()));
|
|
int lat = Integer.parseInt(m.group(2));
|
|
int lon = Integer.parseInt(m.group(4));
|
|
checkArgument(!(lat>90 || lon>180 ));
|
|
return m;
|
|
}
|
|
|
|
|
|
}
|