我的程序如下:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.regex.Pattern;
public class MangoDemo
{
public static void main(String[ ] args) throws FileNotFoundException
{
output();
}
public static void output() throws FileNotFoundException{
char[] lineChar = null;
Scanner scanner = new Scanner(new File("src/input.txt"));
while(scanner.hasNextLine()){
String line = scanner.nextLine();
//System.out.println(line);
lineChar = line.toCharArray();
sortStringBubble (lineChar);
int n = lineChar.length-1;
System.out.print(lineChar[n--]);
for (; n >=0; n-- ) {
if(lineChar[n] != ',') {
System.out.print(",");
System.out.print(lineChar[n]);
}
}
System.out.println();
}//end oof while loop
}
public static void sortStringBubble( char x [ ] )
{
int j;
boolean flag = true; // will determine when the sort is finished
char temp;
while ( flag )
{
flag = false;
for ( j = 0; j < x.length - 1; j++ )
{
if ( Character.toString(x[j]).compareToIgnoreCase( Character.toString(x[j+1]) ) > 0 )
{ // sorting in ascending order
temp = x[j];
x [j] = x [j+1]; // swapping here
x [j+1] = temp;
flag = true;
}
}
}
}
}
我试图制作测试用例,这里是:
import static org.junit.Assert.*;
import org.junit.Test;
public class MangoDemoTest {
@Test
public void testoutput() {
MangoDemo m = new MangoDemo();
char[] a = {'a','b','c'};
assertEquals("Result: ","c,b,a",m.output());
}
@Test
public void testSortStringBubble() {
fail("Not yet implemented");
}
}
我对此绝对是新手。我也收到错误消息。有没有办法在不给输出函数提供参数的情况下测试输出?有人可以帮忙吗?
谢谢