mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +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,
|
public String[] lookup(Class<?> clazz, double tolerance, String key,
|
||||||
double... approximateValues) {
|
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 =
|
Map<String, List<String[]>> classData =
|
||||||
lookupCache.computeIfAbsent(clazz.getCanonicalName(), k -> {
|
lookupCache.computeIfAbsent(clazz.getCanonicalName(), k -> {
|
||||||
@@ -90,7 +90,7 @@ public class DatasheetService {
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < keySize; i++) {
|
for (int i = 0; i < keySize; i++) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
sb.append(",");
|
sb.append("|");
|
||||||
}
|
}
|
||||||
sb.append(line[i]);
|
sb.append(line[i]);
|
||||||
}
|
}
|
||||||
@@ -98,10 +98,6 @@ public class DatasheetService {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (classData == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String[]> list = classData.get(key);
|
List<String[]> list = classData.get(key);
|
||||||
|
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
@@ -111,7 +107,7 @@ public class DatasheetService {
|
|||||||
outerloop: for (String[] line : list) {
|
outerloop: for (String[] line : list) {
|
||||||
for (int i = 0; i < approximateValues.length; i++) {
|
for (int i = 0; i < approximateValues.length; i++) {
|
||||||
String valueStr = line[keySize + 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)
|
if (Math.abs(actualValue - approximateValues[i]) / actualValue * 100 > tolerance)
|
||||||
continue outerloop;
|
continue outerloop;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,21 +33,21 @@ public class DatasheetServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLookupExactMatch() {
|
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);
|
assertNotNull(result);
|
||||||
assertEquals("10.0", result[2]);
|
assertEquals("10.0", result[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLookupWithinTolerance() {
|
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);
|
assertNotNull(result);
|
||||||
assertEquals("10.0", result[2]);
|
assertEquals("10.0", result[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLookupOutsideTolerance() {
|
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);
|
assertNull(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,14 +65,14 @@ public class DatasheetServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLookupWithTolerance() {
|
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);
|
assertNotNull(result);
|
||||||
assertEquals("10.0", result[2]);
|
assertEquals("10.0", result[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLookupMultipleValues() {
|
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);
|
assertNotNull(result);
|
||||||
assertEquals("10.0", result[2]);
|
assertEquals("10.0", result[2]);
|
||||||
assertEquals("20.0", result[3]);
|
assertEquals("20.0", result[3]);
|
||||||
|
|||||||
Reference in New Issue
Block a user