forked from ucsd-cse15l-w23/grader-skill-demo2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
86 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,46 @@ | ||
import static org.junit.Assert.*; | ||
import org.junit.*; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
class IsMoon implements StringChecker { | ||
public boolean checkString(String s) { | ||
return s.equalsIgnoreCase("moon"); | ||
} | ||
} | ||
|
||
public class TestListExamples { | ||
@Test(timeout = 8000) | ||
public void testTimeout() { | ||
while(true) {} | ||
@Test(timeout = 500) | ||
public void testMergeRightEnd() { | ||
List<String> left = Arrays.asList("a", "b", "c"); | ||
List<String> right = Arrays.asList("a", "d"); | ||
List<String> merged = ListExamples.merge(left, right); | ||
List<String> expected = Arrays.asList("a", "a", "b", "c", "d"); | ||
assertEquals(expected, merged); | ||
} | ||
|
||
@Test(timeout = 500) | ||
public void testMergeLeftEnd() { | ||
List<String> left = Arrays.asList("a", "b", "z"); | ||
List<String> right = Arrays.asList("a", "d"); | ||
List<String> merged = ListExamples.merge(left, right); | ||
List<String> expected = Arrays.asList("a", "a", "b", "d", "z"); | ||
assertEquals(expected, merged); | ||
} | ||
|
||
@Test(timeout = 500) | ||
public void testFilterSingle() { | ||
List<String> input = Arrays.asList("Moon", "MOO", "moo"); | ||
List<String> expect = Arrays.asList("Moon"); | ||
List<String> filtered = ListExamples.filter(input, new IsMoon()); | ||
assertEquals(expect, filtered); | ||
} | ||
|
||
@Test(timeout = 500) | ||
public void testFilterMulti() { | ||
List<String> input = Arrays.asList("Moon", "MOO", "moon", "MOON"); | ||
List<String> expect = Arrays.asList("Moon", "moon", "MOON"); | ||
List<String> filtered = ListExamples.filter(input, new IsMoon()); | ||
assertEquals(expect, filtered); | ||
} | ||
// Write your grading tests here! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,56 @@ | ||
# Create your grading script here | ||
|
||
CPATH='.:lib/hamcrest-core-1.3.jar:lib/junit-4.13.2.jar' | ||
|
||
rm -rf student-submission | ||
git clone $1 student-submission | ||
echo 'Finished cloning' | ||
|
||
if [[ -f student-submission/ListExamples.java ]] | ||
then | ||
echo 'ListExamples.java found' | ||
else | ||
echo 'ListExamples.java not found' | ||
echo 'Score: 0/4' | ||
fi | ||
|
||
cp student-submission/ListExamples.java ./ | ||
|
||
javac -cp $CPATH *.java | ||
java -cp $CPATH org.junit.runner.JUnitCore TestListExamples | ||
|
||
java -cp $CPATH org.junit.runner.JUnitCore TestListExamples > junit-output.txt | ||
|
||
# The strategy used here relies on the last few lines of JUnit output, which | ||
# looks like: | ||
|
||
# FAILURES!!! | ||
# Tests run: 4, Failures: 2 | ||
|
||
# We check for "FAILURES!!!" and then do a bit of parsing of the last line to | ||
# get the count | ||
FAILURES=`grep -c FAILURES!!! junit-output.txt` | ||
|
||
if [[ $FAILURES -eq 0 ]] | ||
then | ||
echo 'All tests passed' | ||
echo '4/4' | ||
else | ||
# The ${VAR:N:M} syntax gets a substring of length M starting at index N | ||
# Note that since this is a precise character count into the "Tests run:..." | ||
# string, we'd need to update it if, say, we had a double-digit number of | ||
# tests. But it's nice and simple for the purposes of this script. | ||
|
||
# See, for example: | ||
# https://stackoverflow.com/questions/16484972/how-to-extract-a-substring-in-bash | ||
# https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion | ||
|
||
RESULT_LINE=`grep "Tests run:" junit-output.txt` | ||
COUNT=${RESULT_LINE:25:1} | ||
|
||
echo "JUnit output was:" | ||
cat junit-output.txt | ||
echo "" | ||
echo "--------------" | ||
echo "| Score: $COUNT/4 |" | ||
echo "--------------" | ||
echo "" | ||
fi | ||
|