Skip to content

Commit

Permalink
Fix issue #50.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzxie committed Apr 30, 2019
1 parent 968187a commit 044e69f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
9 changes: 2 additions & 7 deletions judger/src/main/cpp/unix/Judger.Core.Runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ char** getCommandArgs(const std::string& commandLine) {
*/
bool isCurrentUsedMemoryIgnored(int currentUsedMemory) {
int jvmUsedMemory = getCurrentUsedMemory(getpid());
std::cout << "[DEBUG] Current Memory of JVM: " << jvmUsedMemory << " KB" << std::endl;

// std::cout << "[DEBUG] Current Memory of JVM: " << jvmUsedMemory << " KB" << std::endl;
if ( currentUsedMemory >= jvmUsedMemory / 2 &&
currentUsedMemory <= jvmUsedMemory * 2 ) {
return true;
Expand All @@ -307,8 +306,7 @@ int getMaxUsedMemory(pid_t pid, int memoryLimit) {
currentUsedMemory = 0;
do {
currentUsedMemory = getCurrentUsedMemory(pid);
std::cout << "[DEBUG] Current Memory of PID# " << pid << ": " << currentUsedMemory << " KB" << std::endl;

// std::cout << "[DEBUG] Current Memory of PID# " << pid << ": " << currentUsedMemory << " KB" << std::endl;
if ( currentUsedMemory > maxUsedMemory &&
!isCurrentUsedMemoryIgnored(currentUsedMemory) ) {
maxUsedMemory = currentUsedMemory;
Expand Down Expand Up @@ -344,9 +342,6 @@ int getCurrentUsedMemory(pid_t pid) {
}
}
fclose(fp);
} else {
std::cout << "[DEBUG] Memory file path = " << cFilePath << std::endl;
std::cout << "[DEBUG] fp == NULL in getCurrentUsedMemory(pid_t)" << std::endl;
}
return currentUsedMemory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ private boolean isFileOutputTheSame(LineIterator stdFileItr, LineIterator fileIt
* @return 某行的标准输出和用户输出是否相同
*/
private boolean isLineOutputTheSame(String stdLine, String line) {
for ( int i = 0, j = 0; i < stdLine.length() && j < line.length(); ++ i, ++ j ) {
int i = 0, j = 0;
for ( ; i < stdLine.length() && j < line.length(); ++ i, ++ j ) {
if ( stdLine.charAt(i) != line.charAt(j) ) {
if ( stdLine.charAt(i) == '\n' ) {
if ( !isLineEmpty(line, j) ) {
Expand All @@ -133,6 +134,18 @@ private boolean isLineOutputTheSame(String stdLine, String line) {
return false;
}
}
while ( i < stdLine.length() ) {
if ( !isLineEmpty(stdLine, i) ) {
return false;
}
++ i;
}
while ( j < line.length() ) {
if ( !isLineEmpty(line, j) ) {
return false;
}
++ j;
}
return true;
}

Expand All @@ -143,7 +156,7 @@ private boolean isLineOutputTheSame(String stdLine, String line) {
* @return 该行内容中是否只包含空格和换行符
*/
private boolean isLineEmpty(String line, int startIndex) {
for ( int i = 0; i < line.length(); ++ i ) {
for ( int i = startIndex; i < line.length(); ++ i ) {
if ( !(line.charAt(i) == ' ' || line.charAt(i) == '\n') ) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,18 @@ public static void setUp() throws IOException {
IOUtils.write(matchWithSpacesString + " \n \n", outputStream);
// TestCase: Mismatch
stdOutputStream = new FileOutputStream(new File(
"/tmp/voj-matcher-tests/mimatch-std.txt"));
"/tmp/voj-matcher-tests/mismatch-std.txt"));
outputStream = new FileOutputStream(new File(
"/tmp/voj-matcher-tests/mimatch.txt"));
"/tmp/voj-matcher-tests/mismatch.txt"));
String mismatchString1 = "45652 \n\n";
String mismatchString2 = "24334";
IOUtils.write(mismatchString1, stdOutputStream);
IOUtils.write(mismatchString2, outputStream);
// TestCase: MismatchEmptyString
outputStream = new FileOutputStream(new File(
"/tmp/voj-matcher-tests/mismatch-empty.txt"));
String mismatchString3 = "\n";
IOUtils.write(mismatchString3, outputStream);
}

/**
Expand Down Expand Up @@ -147,8 +152,20 @@ public void testMatchWithSpaces() throws IOException {
*/
@Test
public void testMismatch() throws IOException {
String standardOutputFilePath = "/tmp/voj-matcher-tests/mimatch-std.txt";
String outputFilePath = "/tmp/voj-matcher-tests/mimatch.txt";
String standardOutputFilePath = "/tmp/voj-matcher-tests/mismatch-std.txt";
String outputFilePath = "/tmp/voj-matcher-tests/mismatch.txt";
Assertions.assertFalse(comparator.isOutputTheSame(standardOutputFilePath, outputFilePath));
}

/**
* 测试用例: 测试isOutputTheSame(String, String)方法
* 测试数据: 输入和输出不完全相同
* 测试结果: 返回false, 表示输出结果不正确
*/
@Test
public void testMismatchEmptyString() throws IOException {
String standardOutputFilePath = "/tmp/voj-matcher-tests/mismatch-std.txt";
String outputFilePath = "/tmp/voj-matcher-tests/mismatch-empty.txt";
Assertions.assertFalse(comparator.isOutputTheSame(standardOutputFilePath, outputFilePath));
}

Expand Down

0 comments on commit 044e69f

Please sign in to comment.