diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/libraries/lib.xml b/.idea/libraries/lib.xml new file mode 100644 index 0000000..89a750c --- /dev/null +++ b/.idea/libraries/lib.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..90a728d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ff53593 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..1c48a20 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ExecExamples.class b/ExecExamples.class new file mode 100644 index 0000000..7482c5c Binary files /dev/null and b/ExecExamples.class differ diff --git a/ExecHelpers.class b/ExecHelpers.class new file mode 100644 index 0000000..23a4938 Binary files /dev/null and b/ExecHelpers.class differ diff --git a/GradeServer.class b/GradeServer.class new file mode 100644 index 0000000..b57f90c Binary files /dev/null and b/GradeServer.class differ diff --git a/Handler.class b/Handler.class new file mode 100644 index 0000000..6f6e76f Binary files /dev/null and b/Handler.class differ diff --git a/Server.class b/Server.class new file mode 100644 index 0000000..906c276 Binary files /dev/null and b/Server.class differ diff --git a/ServerHttpHandler.class b/ServerHttpHandler.class new file mode 100644 index 0000000..8aba598 Binary files /dev/null and b/ServerHttpHandler.class differ diff --git a/URLHandler.class b/URLHandler.class new file mode 100644 index 0000000..21c4eaf Binary files /dev/null and b/URLHandler.class differ diff --git a/grade.sh b/grade.sh index 13e1827..d130eed 100644 --- a/grade.sh +++ b/grade.sh @@ -8,9 +8,39 @@ mkdir grading-area git clone $1 student-submission echo 'Finished cloning' +if [[ -f student-submission/ListExamples.java ]] +then + echo "ListExamples.java file found." +else + echo "ListExamples.java file not found" + echo "Grade: 0" + exit +fi +mv student-submission/ListExamples.java grading-area +cp -r TestListExamples.java grading-area +cp -r lib grading-area +cd grading-area || exit +javac -cp .:lib/hamcrest-core-1.3.jar:lib/junit-4.13.2.jar *.java &> compliation-results.txt +java -cp .:lib/hamcrest-core-1.3.jar:lib/junit-4.13.2.jar org.junit.runner.JUnitCore TestListExamples > test-results.txt +error=$? + +cd .. || exit +if [[ error -ne 0 ]] +then + echo "Error code " $error +else + echo "All tests passed" + exit +fi # Draw a picture/take notes on the directory structure that's set up after # getting to this point # Then, add here code to compile and run, and do any post-processing of the # tests + +test_failures=$(tail -4 grading-area/test-results.txt | grep Failures | cut -d " " -f 6) +compilation_errors=$(tail -2 grading-area/compliation-results.txt | grep error | cut -d " " -f 1 ) + +score=$((100 - test_failures * 10 - compilation_errors * 10)) +echo "Score: $score" \ No newline at end of file diff --git a/grading-area/IsMoon.class b/grading-area/IsMoon.class new file mode 100644 index 0000000..d82f901 Binary files /dev/null and b/grading-area/IsMoon.class differ diff --git a/grading-area/ListExamples.class b/grading-area/ListExamples.class new file mode 100644 index 0000000..cece4bf Binary files /dev/null and b/grading-area/ListExamples.class differ diff --git a/grading-area/ListExamples.java b/grading-area/ListExamples.java new file mode 100644 index 0000000..b79d150 --- /dev/null +++ b/grading-area/ListExamples.java @@ -0,0 +1,57 @@ +import java.util.ArrayList; +import java.util.List; + +interface StringChecker { boolean checkString(String s); } + +class ListExamples { + + static List result = new ArrayList<>(); + // Returns a new list that has all the elements of the input list for which + // the StringChecker returns true, and not the elements that return false, in + // the same order they appeared in the input list; + static List filter(List list, StringChecker sc) { + if(list.size() == 0) { return list; } + result.clear(); + for(String s: list) { + if(sc.checkString(s)) { + result.add(s); + } + } + return result; + } + + + // Takes two sorted list of strings (so "a" appears before "b" and so on), + // and return a new list that has all the strings in both list in sorted order. + static List merge(List list1, List list2) { + List result = new ArrayList<>(); + int index1 = 0, index2 = 0; + while(index1 < list1.size() && index2 < list2.size()) { + int compared = list1.get(index1).compareTo(list2.get(index2)); + if(compared == 0) { + result.add(list1.get(index1)); + index1 += 1; + index2 += 1; + } + else if(compared < 0) { + result.add(list1.get(index1)); + index1 += 1; + } + else { + result.add(list2.get(index2)); + index2 += 1; + } + } + while(index1 < list1.size()) { + result.add(list1.get(index1)); + index1 += 1; + } + while(index2 < list2.size()) { + result.add(list2.get(index2)); + index2 += 1; + } + return result; + } + + +} diff --git a/grading-area/StringChecker.class b/grading-area/StringChecker.class new file mode 100644 index 0000000..a247629 Binary files /dev/null and b/grading-area/StringChecker.class differ diff --git a/grading-area/TestListExamples.class b/grading-area/TestListExamples.class new file mode 100644 index 0000000..b4868d9 Binary files /dev/null and b/grading-area/TestListExamples.class differ diff --git a/grading-area/TestListExamples.java b/grading-area/TestListExamples.java new file mode 100644 index 0000000..fb472f4 --- /dev/null +++ b/grading-area/TestListExamples.java @@ -0,0 +1,21 @@ +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 = 500) + public void testMergeRightEnd() { + List left = Arrays.asList("a", "b", "c"); + List right = Arrays.asList("a", "d"); + List merged = ListExamples.merge(left, right); + List expected = Arrays.asList("a", "a", "b", "c", "d"); + assertEquals(expected, merged); + } +} diff --git a/grading-area/compliation-results.txt b/grading-area/compliation-results.txt new file mode 100644 index 0000000..e69de29 diff --git a/grading-area/lib/hamcrest-core-1.3.jar b/grading-area/lib/hamcrest-core-1.3.jar new file mode 100644 index 0000000..9d5fe16 Binary files /dev/null and b/grading-area/lib/hamcrest-core-1.3.jar differ diff --git a/grading-area/lib/junit-4.13.2.jar b/grading-area/lib/junit-4.13.2.jar new file mode 100644 index 0000000..6da55d8 Binary files /dev/null and b/grading-area/lib/junit-4.13.2.jar differ diff --git a/grading-area/test-results.txt b/grading-area/test-results.txt new file mode 100644 index 0000000..0d6ff21 --- /dev/null +++ b/grading-area/test-results.txt @@ -0,0 +1,15 @@ +JUnit version 4.13.2 +.E +Time: 0.007 +There was 1 failure: +1) testMergeRightEnd(TestListExamples) +java.lang.AssertionError: expected:<[a, a, b, c, d]> but was:<[a, b, c, d]> + at org.junit.Assert.fail(Assert.java:89) + at org.junit.Assert.failNotEquals(Assert.java:835) + at org.junit.Assert.assertEquals(Assert.java:120) + at org.junit.Assert.assertEquals(Assert.java:146) + at TestListExamples.testMergeRightEnd(TestListExamples.java:19) + +FAILURES!!! +Tests run: 1, Failures: 1 + diff --git a/list-examples-grader.iml b/list-examples-grader.iml new file mode 100644 index 0000000..b15416f --- /dev/null +++ b/list-examples-grader.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/student-submission b/student-submission new file mode 160000 index 0000000..e605952 --- /dev/null +++ b/student-submission @@ -0,0 +1 @@ +Subproject commit e605952a9a592f9dd5c5923ca1792e7684dda7bd