Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add check for ListExamples.java in grade.sh #8

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/libraries/lib.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added ExecExamples.class
Binary file not shown.
Binary file added ExecHelpers.class
Binary file not shown.
Binary file added GradeServer.class
Binary file not shown.
Binary file added Handler.class
Binary file not shown.
Binary file added Server.class
Binary file not shown.
Binary file added ServerHttpHandler.class
Binary file not shown.
Binary file added URLHandler.class
Binary file not shown.
30 changes: 30 additions & 0 deletions grade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Binary file added grading-area/IsMoon.class
Binary file not shown.
Binary file added grading-area/ListExamples.class
Binary file not shown.
57 changes: 57 additions & 0 deletions grading-area/ListExamples.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import java.util.ArrayList;
import java.util.List;

interface StringChecker { boolean checkString(String s); }

class ListExamples {

static List<String> 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<String> filter(List<String> 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<String> merge(List<String> list1, List<String> list2) {
List<String> 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;
}


}
Binary file added grading-area/StringChecker.class
Binary file not shown.
Binary file added grading-area/TestListExamples.class
Binary file not shown.
21 changes: 21 additions & 0 deletions grading-area/TestListExamples.java
Original file line number Diff line number Diff line change
@@ -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<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);
}
}
Empty file.
Binary file added grading-area/lib/hamcrest-core-1.3.jar
Binary file not shown.
Binary file added grading-area/lib/junit-4.13.2.jar
Binary file not shown.
15 changes: 15 additions & 0 deletions grading-area/test-results.txt
Original file line number Diff line number Diff line change
@@ -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

12 changes: 12 additions & 0 deletions list-examples-grader.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" />
</component>
</module>
1 change: 1 addition & 0 deletions student-submission
Submodule student-submission added at e60595