mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
fix tests
This commit is contained in:
@@ -78,7 +78,7 @@ public class DatasheetService {
|
||||
|
||||
public String[] lookup(Class<?> clazz, double tolerance, String key,
|
||||
double... approximateValues) {
|
||||
int keySize = (int) (key.chars().filter(i -> i == ',').count() + 1);
|
||||
int keySize = (int) (key.chars().filter(i -> i == '|').count() + 1);
|
||||
|
||||
Map<String, List<String[]>> classData =
|
||||
lookupCache.computeIfAbsent(clazz.getCanonicalName(), k -> {
|
||||
@@ -90,7 +90,7 @@ public class DatasheetService {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < keySize; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
sb.append("|");
|
||||
}
|
||||
sb.append(line[i]);
|
||||
}
|
||||
@@ -98,10 +98,6 @@ public class DatasheetService {
|
||||
}));
|
||||
});
|
||||
|
||||
if (classData == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<String[]> list = classData.get(key);
|
||||
|
||||
if (list == null) {
|
||||
@@ -111,7 +107,7 @@ public class DatasheetService {
|
||||
outerloop: for (String[] line : list) {
|
||||
for (int i = 0; i < approximateValues.length; i++) {
|
||||
String valueStr = line[keySize + i];
|
||||
double actualValue = Double.parseDouble(valueStr);
|
||||
double actualValue = Double.parseDouble(valueStr.split(" ")[0]);
|
||||
if (Math.abs(actualValue - approximateValues[i]) / actualValue * 100 > tolerance)
|
||||
continue outerloop;
|
||||
}
|
||||
|
||||
@@ -33,21 +33,21 @@ public class DatasheetServiceTest {
|
||||
|
||||
@Test
|
||||
public void testLookupExactMatch() {
|
||||
String[] result = service.lookup(TEST_CLASS, 0.0, "TEST,KEY", 10.0);
|
||||
String[] result = service.lookup(TEST_CLASS, 0.0, "TEST|KEY", 10.0);
|
||||
assertNotNull(result);
|
||||
assertEquals("10.0", result[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithinTolerance() {
|
||||
String[] result = service.lookup(TEST_CLASS, 5.0, "TEST,KEY", 10.5);
|
||||
String[] result = service.lookup(TEST_CLASS, 5.0, "TEST|KEY", 10.5);
|
||||
assertNotNull(result);
|
||||
assertEquals("10.0", result[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupOutsideTolerance() {
|
||||
String[] result = service.lookup(TEST_CLASS, 5.0, "TEST,KEY", 12.0);
|
||||
String[] result = service.lookup(TEST_CLASS, 5.0, "TEST|KEY", 12.0);
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@@ -65,14 +65,14 @@ public class DatasheetServiceTest {
|
||||
|
||||
@Test
|
||||
public void testLookupWithTolerance() {
|
||||
String[] result = service.lookup(TEST_CLASS, 50.0, "TEST,KEY", 15.0);
|
||||
String[] result = service.lookup(TEST_CLASS, 50.0, "TEST|KEY", 15.0);
|
||||
assertNotNull(result);
|
||||
assertEquals("10.0", result[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupMultipleValues() {
|
||||
String[] result = service.lookup(TEST_CLASS, 0.0, "TEST,KEY", 10.0, 20.0);
|
||||
String[] result = service.lookup(TEST_CLASS, 0.0, "TEST|KEY", 10.0, 20.0);
|
||||
assertNotNull(result);
|
||||
assertEquals("10.0", result[2]);
|
||||
assertEquals("20.0", result[3]);
|
||||
|
||||
Reference in New Issue
Block a user