gpt4 book ai didi

java - 智能 : Class not found: "" Empty test suite

转载 作者:行者123 更新时间:2023-11-28 21:07:56 25 4
gpt4 key购买 nike

我是java新手。我正在做我的学校项目,我遇到了这个错误消息的问题。

Class not found: ""Empty test suite.

我以前做过这样的测试,他们成功了。

我没有写所有的方法。我试着先运行文件。我一直在寻找解决方案,但没有一个适合我的情况。

这是我的测试代码:

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class TestLab06 {

@Test
public void testIntListInsert() {
int[] arr = {1, 3, 5};
IntList test1 = new IntList(arr);
IntList test2 = new IntList();
test1.insert(2, 1);
test1.insert(4, 3);
assertEquals(5, test1.getSize());
assertEquals(3, test1.get(2));
assertEquals(4, test1.get(3));
test2.insert(1, 1);
assertEquals(1, test2.get(0));
assertEquals(1, test2.getSize());
test2.insert(10, 10);
assertEquals(10, test2.get(1));
}

@Test
public void testIntListMerge() {
int[] arr = {1, 3, 5};
IntList test1 = new IntList(arr);
int[] arr2 = {2, 4, 6, 8};
IntList test2 = new IntList(arr2);
IntList test = IntList.merge(test1, test2);
int[] expected ={1, 2, 3, 4, 5, 6, 8};
for (int i = 0; i < expected.length; i++) {
assertEquals(expected[i], test.get(i));
}
}

@Test
public void testIntListReverse() {
int[] arr = {1, 2, 3, 4, 5, 6, 8};
IntList test1 = new IntList(arr);
test1.reverse();
int[] expected = {8, 6, 5, 4, 3, 2, 1};
for (int i = 0; i < expected.length; i++) {
assertEquals(expected[i], test1.get(i));
}
}

@Test
public void testDLLInsertRemove() {
DLList l = new DLList();
l.insertBack(2);
l.insertFront(1);
assertEquals(1, l.get(0));
l.insert(4, 1);
assertEquals(4, l.get(1));
l.insert(1, 10);
// List is 1, 4, 2, 1
assertEquals(l.sentinel, l.sentinel.next.next.next.next.prev.prev.prev.prev);
l.remove(1);
assertEquals(2, l.size);
l.remove(l.sentinel.next);
assertEquals(1, l.size);
assertEquals(2, l.sentinel.next.item);
}

@Test
public void testDLLDoubleReverse() {
DLList l = new DLList();
l.insertBack(4);
l.insertBack(2);
l.doubleInPlace();
assertEquals(4, l.size);
assertEquals(4, l.get(0));
assertEquals(4, l.get(1));
assertEquals(2, l.get(2));
assertEquals(2, l.get(3));
assertEquals(l.sentinel, l.sentinel.next.next.next.next.prev.prev.prev.prev);
l.reverse();
assertEquals(4, l.size);
assertEquals(4, l.get(3));
assertEquals(4, l.get(2));
assertEquals(2, l.get(1));
assertEquals(2, l.get(0));
assertEquals(l.sentinel, l.sentinel.next.next.next.next.prev.prev.prev.prev);
}
}

这是我的 IntList.java

/** A data structure to represent a Linked List of Integers.
* Each IntList represents one node in the overall Linked List.
* Encapsulated version.
*/
public class IntList {
/** The head of the list is the first node in the list. If the list
is empty, head is null **/
private IntListNode head;
private int size;

/** IntListNode is a nested class. It can be instantiated when associated with an instance of
* IntList.
* **/
public class IntListNode {
int item;
IntListNode next;

public IntListNode(int item, IntListNode next) {
this.item = item;
this.next = next;
}
}

public int getSize() {
return size;
}

public IntList() {}

public IntList(int[] initial) {
for (int i = initial.length - 1; i >= 0; i--) {
head = new IntListNode(initial[i], head);
}
size = initial.length;
}

/**
* Get the value at position pos. If the position does not exist, throw an
* IndexOutOfBoundsException.
* @param position to get from
* @return the int at the position in the list.
*/
public int get(int position) {
if (position >= size) throw new IndexOutOfBoundsException("Position larger than size of list.");
IntListNode curr = head;
while (position > 0) {
curr = curr.next;
position--;
}
return curr.item;
}

@java.lang.Override
public java.lang.String toString() {
return "IntList{" +
"head=" + head +
", size=" + size +
'}';
}

public boolean equals(Object object) {
if (this == object) return true;
if (!(object instanceof IntList)) return false;
if (!super.equals(object)) return false;
IntList intList = (IntList) object;
return size == intList.size &&
java.util.Objects.equals(head, intList.head);
}



/* Fill in below! */

/**
* Insert a new node into the IntList.
* @param x value to insert
* @param position position to insert into. If position exceeds the size of the list, insert into
* the end of the list.
*/
public void insert(int x, int position) {
// Fill me in!
//insert when the size of the list is 0
if (this.size == 0) {
head = new InListNode(x, head);
size++;

}
//insert at the beginning of the list
else if (position == 0) {
IntListNode new_node = new IntListNode(x, head);
head = new_node;
size++;
}
else {
IntListNode point = head;
while (position > 1 && point.next != null) {
point = point.next;
position--;
}
IntListNode newone = new IntListNode(x, point.next);
point.next = newone;
size++;
}


}

/**
* Merge two sorted IntLists a and b into one sorted IntList containing all of their elements.
* @return a new IntList without modifying either parameter
*/
public static IntList merge(IntList a, IntList b) {
// Fill me in!
return null;
}

/**
* Reverse the current list recursively, using a helper method.
*/
public void reverse() {
// Fill me in!
}

/* Optional! */

/**
* Remove the node at position from this list.
* @param position int representing the index of the node to remove. If greater than the size
* of this list, throw an IndexOutOfBoundsException.
*/
public void remove(int position) {
if (position >= size) throw new IndexOutOfBoundsException();
// fill me in
}
}

最佳答案

试试这个:

文件> 无效缓存/重启> 无效并重启

关于java - 智能 : Class not found: "" Empty test suite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50651971/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com