planetiler/planetiler-core/src/test/java/com/onthegomap/planetiler/util/ParseTest.java

103 wiersze
2.7 KiB
Java
Czysty Zwykły widok Historia

package com.onthegomap.planetiler.util;
2021-06-11 01:15:27 +00:00
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
2021-06-11 01:15:27 +00:00
import static org.junit.jupiter.api.DynamicTest.dynamicTest;
import java.util.Map;
import java.util.stream.Stream;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
2021-06-11 01:15:27 +00:00
2022-04-23 10:36:24 +00:00
class ParseTest {
2021-06-11 01:15:27 +00:00
@ParameterizedTest
@CsvSource({
"0, false, 0",
"false, false, 0",
"no, false, 0",
"yes, true, 1",
"true, true, 1",
"ok, true, 1",
})
2022-04-23 10:36:24 +00:00
void testBoolean(String in, boolean out, int boolint) {
2021-06-11 01:15:27 +00:00
assertEquals(out, Parse.bool(in));
assertEquals(boolint, Parse.boolInt(in));
}
@ParameterizedTest
@CsvSource(value = {
"0, 0, 0",
"false, 0, null",
"123, 123, 123"
}, nullValues = {"null"})
2022-04-23 10:36:24 +00:00
void testLong(String in, long out, Long obj) {
2021-06-11 01:15:27 +00:00
assertEquals(out, Parse.parseLong(in));
assertEquals(obj, Parse.parseLongOrNull(in));
}
@ParameterizedTest
@CsvSource({
"1, 1",
"yes, 1",
"true, 1",
"-1, -1",
"2, 0",
"0, 0"
})
2022-04-23 10:36:24 +00:00
void testDirection(String in, int out) {
2021-06-11 01:15:27 +00:00
assertEquals(out, Parse.direction(in));
}
2021-06-14 11:04:03 +00:00
@ParameterizedTest
@CsvSource(value = {
"1, 1",
"0, 0",
"-1, -1",
"1.1, 1",
"-1.1, -1",
"-1.23 m, -1",
"one meter, null",
"null, null"
}, nullValues = {"null"})
2022-04-23 10:36:24 +00:00
void testIntSubstring(String in, Integer out) {
2021-06-14 11:04:03 +00:00
assertEquals(out, Parse.parseIntSubstring(in));
}
2021-06-11 01:15:27 +00:00
@TestFactory
2022-04-23 10:36:24 +00:00
Stream<DynamicTest> testWayzorder() {
2021-06-11 01:15:27 +00:00
return Stream.<Map.Entry<Map<String, Object>, Integer>>of(
Map.entry(Map.of(), 0),
Map.entry(Map.of("layer", 1), 10),
Map.entry(Map.of("layer", -3), -30),
Map.entry(Map.of("highway", "motorway"), 9),
Map.entry(Map.of("railway", "anything"), 7),
Map.entry(Map.of("railway", "anything", "tunnel", "1"), -3),
Map.entry(Map.of("railway", "anything", "bridge", "1"), 17)
).map(entry -> dynamicTest(entry.getKey().toString(),
() -> assertEquals(entry.getValue(), Parse.wayzorder(entry.getKey()))));
}
@ParameterizedTest
@CsvSource(value = {
"0, 0",
"1, 1",
"999999999999, 999999999999",
"2k, 2048",
"4M, 4194304",
"8G, 8589934592"
})
2022-04-23 10:36:24 +00:00
void testParseJvmSize(String input, long expectedOutput) {
assertEquals(expectedOutput, Parse.jvmMemoryStringToBytes(input));
}
@ParameterizedTest
@ValueSource(strings = {"123p", "123gk", "garbage"})
2022-04-23 10:36:24 +00:00
void testParseInvalidJvmSize(String input) {
assertThrows(IllegalArgumentException.class, () -> Parse.jvmMemoryStringToBytes(input));
}
2021-06-11 01:15:27 +00:00
}