华为java机试题限时多久_华为练习题,用了10几个小时。。。

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

测试用例的代码:

package testcase;

import huawei.Demo;

import junit.framework.TestCase;

import java.io.*;

import java.util.Vector;

public class DemoTest extends TestCase {

private Demo demo;

private final static String USER_DIR = System.getProperty("user.dir");

private final static String TEST_FOLDER_PATH = USER_DIR + "\\testCase\\";

private final static String TEST_FOLDER_TARGET = TEST_FOLDER_PATH + "target\\";

public void setUp() {

demo = new Demo();

}

private Vector readOutputFile(String filePath) {

Vector vector = new Vector();

try {

FileInputStream fs = new FileInputStream(filePath);

InputStreamReader isr = new InputStreamReader(fs);

BufferedReader br = new BufferedReader(isr);

String data = "";

while ((data = br.readLine()) != null) {

if (data.length() == 0) {

continue;

}

vector.add(data);

}

} catch (FileNotFoundException e) {

throw new RuntimeException("文件路径错误!");

} catch (IOException e) {

throw new RuntimeException("文件读取失败!");

}

return vector;

}

private boolean isSame(String output, String targetPath) {

Vector vector = this.readOutputFile(output);

Vector tgVector = this.readOutputFile(targetPath);

if (vector.size() != tgVector.size()) {

return false;

}

for (int i = 0; i < vector.size(); i++) {

if (!vector.get(i).equals(tgVector.get(i))) {

return false;

}

}

return true;

}

private void testcaseHelper_Should_Fail(String inFilePath, String outFilePath) {

try {

boolean result = demo.attandentSystem(inFilePath, outFilePath);

assertFalse(result);

} catch (Exception e) {

assertTrue(true);

}

}

private void testcaseHelper_Should_Success(String inFilePath, String outFilePath, String targetPath) {

try {

boolean result = demo.attandentSystem(inFilePath, outFilePath);

assertTrue(result);

assertTrue(isSame(outFilePath, targetPath));

} catch (Exception e) {

assertTrue(false);

}

}

public void testcaseSortDate_Case_01() {

testcaseHelper_Should_Success(TEST_FOLDER_PATH + "in.txt", TEST_FOLDER_PATH + "out.txt", TEST_FOLDER_TARGET + "check.txt");

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值