Ниже приводится тестовый класс для CleverSearchTimer и CleverSearchTimer интерфейсаНевозможно создать экземпляр типа CleverSearchTimer?
public class CleverSearchTimerTest {
private static SimpleRandomCount srctest;
private static CleverSearchTimer ssttest;
@BeforeClass
public static void setUpBeforeClass() {
srctest = new SimpleRandomCount(25);
ssttest = new CleverSearchTimer();
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
public void findKthElementTestRegular() throws IndexingError{
assertEquals(ssttest.findKthElement(srctest.array(),4),21);
}
public void FindKthElementTestBoundaryLow() throws IndexingError{
assertEquals(ssttest.findKthElement(srctest.array(),25), 0);
}
public void FindKthElementTestBoundaryHigh() throws IndexingError{
assertEquals(ssttest.findKthElement(srctest.array(),1), 24);
}
public void FindKthElementTestErroneous() throws IndexingError{
equals(ssttest.findKthElement(srctest.array(), 30));
}
@Test
public void test() {
fail("Not yet implemented");
}
}
CleverSearchTimer:
public interface CleverSearchTimer {
/**
* Find the kth largest element in an array of ints
* @param array — array of ints
* @param k — index of the element to be found
* @return — kth largest int in array
* @throws IndexingError — if k is not a valid index
*/
public int findKthElement(int[] array, int k)
throws IndexingError;
/** Find the time it takes to find the kth element
* @param array — array of ints
* @param k — the index of the element to be found
* @return — the time taken to find the kth largest element
* @throws IndexingError — if k is not a valid index
*/
public double time(int[] array,int k)
throws IndexingError;
} // end of interface TimedSearch
на линии появляется ошибка "ssttest = новый CleverSearchTimer();" Msgstr "Невозможно создать экземпляр типа CleverSearchTimer.
Я думаю, это связано с тем, что вы не можете создать интерфейс в тестовом классе. Есть ли другой способ сделать это?
Спасибо за любую помощь.