目前正在对我的程序进行强制性的系统测试,目前遇到一个问题,其中说: “ java.lang.ClassFormatError:嵌套成员class_info_index#在类Folder / classname中的常量类型错误”
'#'=一次测试为300,类名=控制器
'#'=另一个测试中的13,类名= TST
搜索错误导致我使用@RunWith(Encoded.class),它没有任何帮助。起初,我以为是因为有一个嵌套的类,但是当我碰到在没有嵌套类的测试中也收到了这个错误,我想那不是问题。
最短测试的展示柜:
import org.junit.Test;
import Model.TST;
import org.junit.Assert;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import java.util.List;
@RunWith(Enclosed.class)
public class TSTTest {
TST tst = new TST();
@Test
public void InsertionAndAutocompleteTest() {
String expected = "åbakken 1, 3700 rønne";
tst.insert("åbakken 1, 3700 rønne", 8.415619f, 55.10369f);
List<String> suggestions = tst.search("åbakken 1");
String actual = suggestions.get(0);
String expected2 = "Sankt Mortens Gade 3, 3700 rønne";
tst.insert("Sankt Mortens Gade 3, 3700 rønne", 14.7009790f, 55.1026200f);
List<String> suggestions2 = tst.search("Sankt Mortens Gade 3");
String actual2 = suggestions2.get(0);
Assert.assertEquals(expected, actual);
Assert.assertEquals(expected2, actual2);
}
@Test
public void sizeTest() {
String address = "åbakken 1, 3700 rønne";
tst.insert("åbakken 1, 3700 rønne", 8.415619f, 55.10369f);
Assert.assertEquals(address.toCharArray().length, tst.size());
}
@Test
public void sizeOfSuggestions() {
tst.insert("åbakken 1, 3700 rønne", 8.415619f, 55.10369f);
tst.insert("åbakken 3, 3700 rønne", 8.415620f, 55.10370f);
tst.insert("åbakken 2, 3700 rønne", 8.413420f, 55.10560f);
tst.insert("Sankt Mortens Gade 3, 3700 rønne", 14.7009790f, 55.1026200f);
List<String> suggestions = tst.search("åbakken ");
int expected = 3;
Assert.assertEquals(expected, suggestions.size());
}
}
这是课程本身:
package Model;
import java.io.Serializable;
import java.util.*;
public class TST implements Serializable {
private int size; // size
private Node root; // root of TST
public Map<String, float[]> mapStringCoords= new HashMap<>();
private static class Node implements Serializable{
private char c; // Character
private Node left, mid, right; // Subtries
private boolean isEnd;
}
public int size() { return size; }
public void insert(String key, float x, float y) {
if (key == null) {
throw new IllegalArgumentException("calls put() with null key");
}
mapStringCoords.put(key,new float[]{x,y});
root = insert(root, key, 0);
}
private Node insert(Node x, String key, int d) {
char c = key.charAt(d);
if (x == null) {
x = new Node();
size++;
x.c = c;
}
if (c < x.c) x.left = insert(x.left, key, d);
else if (c > x.c) x.right = insert(x.right, key, d);
else if (d < key.length() - 1) x.mid = insert(x.mid, key, d + 1);
else x.isEnd = true;
return x;
}
public List<String> search(String query) {
List<String> suggestions = new ArrayList<>();
Node endNode = getQueryEndNode(root, query.toCharArray(), 0);
if (endNode != null) {
if (endNode.isEnd) {
suggestions.add(query);
}
findSuggestions(endNode.mid, query, suggestions, "");
}
return suggestions;
}
private Node getQueryEndNode(Node node, char[] query, int charPos) {
if (node == null || query.length == 0) {
return null;
}
if (query[charPos] < node.c) {
return getQueryEndNode(node.left, query, charPos);
} else if (query[charPos] > node.c) {
return getQueryEndNode(node.right, query, charPos);
} else {
if (charPos == query.length - 1) {
return node;
} else {
return getQueryEndNode(node.mid, query, charPos + 1);
}
}
}
private void findSuggestions(Node node, String query, List<String> dest, String str) {
if (node != null) {
if (node.isEnd) {
dest.add(query + str + node.c);
}
findSuggestions(node.left, query, dest, str);
findSuggestions(node.mid, query, dest, str + node.c);
findSuggestions(node.right, query, dest, str);
}
}
}
我真的不知道。如果有人可以提出解决方案,那就太好了:)
谢谢!