From d7450c77e1af86d2ed7127674994e628ba8906a7 Mon Sep 17 00:00:00 2001 From: Adrian Wilke Date: Sat, 23 Feb 2019 11:01:16 +0100 Subject: [PATCH 1/8] root commit From d6782691769887da0b2b58238e914ce5d86bc80c Mon Sep 17 00:00:00 2001 From: Adrian Wilke Date: Sat, 23 Feb 2019 16:29:10 +0100 Subject: [PATCH 2/8] gitignore --- .gitignore | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..735da4c --- /dev/null +++ b/.gitignore @@ -0,0 +1,102 @@ +### https://github.com/github/gitignore/blob/697a1e236a3ebde2ae68456dc90988bc763c42ac/Java.gitignore + + + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + + + +### https://github.com/github/gitignore/blob/697a1e236a3ebde2ae68456dc90988bc763c42ac/Global/Eclipse.gitignore + + + +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# Eclipse Core +.project + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + + + +### https://github.com/github/gitignore/blob/697a1e236a3ebde2ae68456dc90988bc763c42ac/Maven.gitignore + + + +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties + +# Exclude maven wrapper +!/.mvn/wrapper/maven-wrapper.jar From 9545ba13dd0a4811504b2e36d3c0b4d1f3fde46d Mon Sep 17 00:00:00 2001 From: Adrian Wilke Date: Sat, 23 Feb 2019 16:29:44 +0100 Subject: [PATCH 3/8] Java/Maven template --- README.md | 11 ++++ pom.xml | 24 ++++++++ .../nbraderutils/javatemplate/Exercise1.java | 48 +++++++++++++++ src/main/resources/Exercise1.md | 45 ++++++++++++++ .../javatemplate/AllTestsSuite.java | 10 +++ .../javatemplate/Configuration.java | 11 ++++ .../javatemplate/Exercise1Test.java | 60 ++++++++++++++++++ .../javatemplate/OverallPointsTest.java | 61 +++++++++++++++++++ 8 files changed, 270 insertions(+) create mode 100644 README.md create mode 100644 pom.xml create mode 100644 src/main/java/org/dice_research/nbraderutils/javatemplate/Exercise1.java create mode 100644 src/main/resources/Exercise1.md create mode 100644 src/test/java/org/dice_research/nbraderutils/javatemplate/AllTestsSuite.java create mode 100644 src/test/java/org/dice_research/nbraderutils/javatemplate/Configuration.java create mode 100644 src/test/java/org/dice_research/nbraderutils/javatemplate/Exercise1Test.java create mode 100644 src/test/java/org/dice_research/nbraderutils/javatemplate/OverallPointsTest.java diff --git a/README.md b/README.md new file mode 100644 index 0000000..2551799 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# nbgraderutils: Automatically graded Java web exercises + +This branch provides a Java/Maven template to create new assignments. + +An assignment consists of several exercises. + +With this template, you can provide: + +- Exercises and solutions (src/main/java) +- Tests for auto-grading (src/test/java) +- Instructions for students (src/main/resources) \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..7c79fa3 --- /dev/null +++ b/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + org.dice-research + nbgraderutils-java-template + 0.0.1-SNAPSHOT + nbgraderutils-java-template + + 1.11 + 1.11 + + + + + + org.junit.jupiter + junit-jupiter-api + 5.3.1 + test + + + + \ No newline at end of file diff --git a/src/main/java/org/dice_research/nbraderutils/javatemplate/Exercise1.java b/src/main/java/org/dice_research/nbraderutils/javatemplate/Exercise1.java new file mode 100644 index 0000000..6fedaca --- /dev/null +++ b/src/main/java/org/dice_research/nbraderutils/javatemplate/Exercise1.java @@ -0,0 +1,48 @@ +package org.dice_research.nbraderutils.javatemplate; + +/** + * Exercise 1 - Numeric ASCII representation + * + * @author Adrian Wilke + */ +public class Exercise1 { + + /** + * Converts a String to the numeric ASCII representation of its single + * characters. + */ + int[] toNumericAscii(String string) { + int[] result = new int[string.length()]; + + // BEGIN SOLUTION + + /* + * Notes for lecturers: + * + * Insert your solution inside one or several marked solution blocks. These + * blocks will be removed for students. + * + * If possible, a return variable should be defined before this marked solution + * block. It avoids unnecessary error messages, if the solution block is removed + * for the students. A null value also works. + * + * Please edit the JavaDoc class comment (exercise name, author) and method + * comment(s) as well. + * + * Additionally to this solution, provide a markdown file describing the + * exercise task and a test file for auto-grading. + * + * You can remove this comment. + */ + + char[] chars = string.toCharArray(); + for (int i = 0; i < chars.length; i++) { + result[i] = chars[i]; + } + + // END SOLUTION + + return result; + } + +} \ No newline at end of file diff --git a/src/main/resources/Exercise1.md b/src/main/resources/Exercise1.md new file mode 100644 index 0000000..8cf98ea --- /dev/null +++ b/src/main/resources/Exercise1.md @@ -0,0 +1,45 @@ +Note for lecturers: Markdown examples +https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Working%20With%20Markdown%20Cells.html + + + +# Exercise 1 - Numeric ASCII representation + +(??? points) + +Implement a method which converts a String to the numeric ASCII representation of its single characters. + +#### Example + + + + + + + + + + + + + + + + + +

Input

Output

Type

String

int array

Value

Hi

72, 105

+ +#### Hints + +- The [String class](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#toCharArray()) provides methods for conversion. + +#### Notes + +- Do not add additional external libraries. +- Interface + - You can use _[TAB]_ for auto-completion and _[SHIFT]_+_[TAB]_ for code inspection. + - Check _Menu_ -> _Help_ -> _Keyboard Shortcuts_. +- Finish + - Save your solution by clicking on the _disk icon_. + - Finally, choose _Menu_ -> _File_ -> _Close and Halt_. + - Do not forget to _Submit_ your solution in the _Assignments_ view. \ No newline at end of file diff --git a/src/test/java/org/dice_research/nbraderutils/javatemplate/AllTestsSuite.java b/src/test/java/org/dice_research/nbraderutils/javatemplate/AllTestsSuite.java new file mode 100644 index 0000000..ae18f30 --- /dev/null +++ b/src/test/java/org/dice_research/nbraderutils/javatemplate/AllTestsSuite.java @@ -0,0 +1,10 @@ +package org.dice_research.nbraderutils.javatemplate; + +import org.junit.platform.runner.JUnitPlatform; +import org.junit.platform.suite.api.SelectPackages; +import org.junit.runner.RunWith; + +@RunWith(JUnitPlatform.class) +@SelectPackages({ "org.dice_research.nbraderutils.javatemplate" }) +public class AllTestsSuite { +} \ No newline at end of file diff --git a/src/test/java/org/dice_research/nbraderutils/javatemplate/Configuration.java b/src/test/java/org/dice_research/nbraderutils/javatemplate/Configuration.java new file mode 100644 index 0000000..ad7240c --- /dev/null +++ b/src/test/java/org/dice_research/nbraderutils/javatemplate/Configuration.java @@ -0,0 +1,11 @@ +package org.dice_research.nbraderutils.javatemplate; + +public abstract class Configuration { + + // If true, it is checked if exercise points sum up to assignment points. + public static final boolean EQUAL_POINTS_FOR_ASSIGNMENTS = true; + + // 12 or 24 overall points for an assignment are fine for equal points + // distribution of 1/2/3/4 exercises. + public static final int POINTS_PER_ASSIGNMENT = 24; +} \ No newline at end of file diff --git a/src/test/java/org/dice_research/nbraderutils/javatemplate/Exercise1Test.java b/src/test/java/org/dice_research/nbraderutils/javatemplate/Exercise1Test.java new file mode 100644 index 0000000..a7748ab --- /dev/null +++ b/src/test/java/org/dice_research/nbraderutils/javatemplate/Exercise1Test.java @@ -0,0 +1,60 @@ +package org.dice_research.nbraderutils.javatemplate; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.opentest4j.AssertionFailedError; + +/** + * Feel free to change the parameters of the method test(...). + * + * Overview of Assertions: + * https://junit.org/junit5/docs/current/api/org/junit/jupiter/api/Assertions.html + */ +class Exercise1Test { + + void test(String inputString, int[] expectedResult) { + try { + long time = System.currentTimeMillis(); + + Assertions.assertArrayEquals(expectedResult, new Exercise1().toNumericAscii(inputString)); + + time = System.currentTimeMillis() - time; + System.out.println("Test(s) successfully completed. Calculation took " + time + " ms."); + } catch (AssertionFailedError e) { + System.err.println("Your solution returned an unexpected result. "); + throw e; + } catch (Throwable e) { + System.err.println("Your solution caused an unexpected error. "); + throw e; + } + } + + @Test + void testVisible() { + + test("Hi", new int[] { 72, 105 }); + + } + + @Test + void testHidden1() { + + // The first hidden test should be similar to the visible test. + test("Ho", new int[] { 72, 111 }); + + // Set the points for this test. + OverallPointsTest.addPoints(14, this.getClass()); + + } + + @Test + void testHidden2() { + + // An additional test. + test("HiHo", new int[] { 72, 105, 72, 111 }); + + // Set the points for this test. + OverallPointsTest.addPoints(10, this.getClass()); + + } +} \ No newline at end of file diff --git a/src/test/java/org/dice_research/nbraderutils/javatemplate/OverallPointsTest.java b/src/test/java/org/dice_research/nbraderutils/javatemplate/OverallPointsTest.java new file mode 100644 index 0000000..79d3e1e --- /dev/null +++ b/src/test/java/org/dice_research/nbraderutils/javatemplate/OverallPointsTest.java @@ -0,0 +1,61 @@ +package org.dice_research.nbraderutils.javatemplate; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class OverallPointsTest { + + private static Map> pointsMap = new TreeMap<>(); + + public static void addPoints(int points, Class exerciseTestClass) { + if (!pointsMap.containsKey(exerciseTestClass.getSimpleName())) { + pointsMap.put(exerciseTestClass.getSimpleName(), new LinkedList<>()); + } + pointsMap.get(exerciseTestClass.getSimpleName()).add(points); + } + + @Test + void test() { + + // Print point overview + + int pointsAssignment = 0; + int pointsExercise; + StringBuilder exerciseBuilder = new StringBuilder(); + StringBuilder testBuilder; + for (Entry> exercise : pointsMap.entrySet()) { + pointsExercise = 0; + testBuilder = new StringBuilder(); + for (int i = 0; i < exercise.getValue().size(); i++) { + if (i != 0) { + testBuilder.append(" + "); + } + testBuilder.append(exercise.getValue().get(i)); + pointsExercise += exercise.getValue().get(i); + } + exerciseBuilder.append("Points for "); + exerciseBuilder.append(exercise.getKey()); + exerciseBuilder.append(": "); + exerciseBuilder.append(pointsExercise); + exerciseBuilder.append(" = "); + exerciseBuilder.append(testBuilder); + pointsAssignment += pointsExercise; + } + System.out.println(exerciseBuilder.toString()); + System.out.println("Overall points for assignment: " + pointsAssignment); + + // Check final points + + if (Configuration.EQUAL_POINTS_FOR_ASSIGNMENTS) { + Assertions.assertEquals(Configuration.POINTS_PER_ASSIGNMENT, pointsAssignment, + "Please check your point configuration."); + } + } + +} \ No newline at end of file From 36d730a1e6f2e378ffa62f5c05843f0cf7deb217 Mon Sep 17 00:00:00 2001 From: Adrian Wilke Date: Sun, 24 Feb 2019 09:47:23 +0100 Subject: [PATCH 4/8] junit platform --- pom.xml | 10 +++++++++- .../nbraderutils/javatemplate/Exercise1.java | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 7c79fa3..3724b4b 100644 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,14 @@ + + + org.junit.platform + junit-platform-runner + 1.4.0 + test + + org.junit.jupiter @@ -19,6 +27,6 @@ 5.3.1 test + - \ No newline at end of file diff --git a/src/main/java/org/dice_research/nbraderutils/javatemplate/Exercise1.java b/src/main/java/org/dice_research/nbraderutils/javatemplate/Exercise1.java index 6fedaca..0bab420 100644 --- a/src/main/java/org/dice_research/nbraderutils/javatemplate/Exercise1.java +++ b/src/main/java/org/dice_research/nbraderutils/javatemplate/Exercise1.java @@ -11,7 +11,7 @@ public class Exercise1 { * Converts a String to the numeric ASCII representation of its single * characters. */ - int[] toNumericAscii(String string) { + public int[] toNumericAscii(String string) { int[] result = new int[string.length()]; // BEGIN SOLUTION From bab51309e5b348ff6931d27d38722f4baa085dc9 Mon Sep 17 00:00:00 2001 From: Adrian Wilke Date: Sun, 24 Feb 2019 10:12:34 +0100 Subject: [PATCH 5/8] junit engine --- pom.xml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 3724b4b..debc048 100644 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,16 @@ + + + + + org.junit.jupiter + junit-jupiter-engine + 5.4.0 + test + + org.junit.platform @@ -20,13 +30,5 @@ test - - - org.junit.jupiter - junit-jupiter-api - 5.3.1 - test - - \ No newline at end of file From 95c4e3fcdf36a43df3ce78d164e1661a72bb049f Mon Sep 17 00:00:00 2001 From: Adrian Wilke Date: Sun, 24 Feb 2019 11:46:22 +0100 Subject: [PATCH 6/8] Test description --- .../nbraderutils/javatemplate/Exercise1Test.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/dice_research/nbraderutils/javatemplate/Exercise1Test.java b/src/test/java/org/dice_research/nbraderutils/javatemplate/Exercise1Test.java index a7748ab..8a8b668 100644 --- a/src/test/java/org/dice_research/nbraderutils/javatemplate/Exercise1Test.java +++ b/src/test/java/org/dice_research/nbraderutils/javatemplate/Exercise1Test.java @@ -12,11 +12,11 @@ */ class Exercise1Test { - void test(String inputString, int[] expectedResult) { + void test(String inputString, int[] expectedResult, String testDescription) { try { long time = System.currentTimeMillis(); - Assertions.assertArrayEquals(expectedResult, new Exercise1().toNumericAscii(inputString)); + Assertions.assertArrayEquals(expectedResult, new Exercise1().toNumericAscii(inputString), testDescription); time = System.currentTimeMillis() - time; System.out.println("Test(s) successfully completed. Calculation took " + time + " ms."); @@ -32,7 +32,7 @@ void test(String inputString, int[] expectedResult) { @Test void testVisible() { - test("Hi", new int[] { 72, 105 }); + test("Hi", new int[] { 72, 105 }, "Testing 'Hi'"); } @@ -40,7 +40,7 @@ void testVisible() { void testHidden1() { // The first hidden test should be similar to the visible test. - test("Ho", new int[] { 72, 111 }); + test("Ho", new int[] { 72, 111 }, "Testing 'Ho'"); // Set the points for this test. OverallPointsTest.addPoints(14, this.getClass()); @@ -51,7 +51,7 @@ void testHidden1() { void testHidden2() { // An additional test. - test("HiHo", new int[] { 72, 105, 72, 111 }); + test("HiHo", new int[] { 72, 105, 72, 111 }, "Testing 'HiHo'"); // Set the points for this test. OverallPointsTest.addPoints(10, this.getClass()); From 551cb014a0fa50cf3ad2e23d6c1df4d7c3e409ae Mon Sep 17 00:00:00 2001 From: Adrian Wilke Date: Mon, 25 Feb 2019 16:53:43 +0100 Subject: [PATCH 7/8] Removing notes --- src/main/resources/Exercise1.md | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/main/resources/Exercise1.md b/src/main/resources/Exercise1.md index 8cf98ea..00c904d 100644 --- a/src/main/resources/Exercise1.md +++ b/src/main/resources/Exercise1.md @@ -32,14 +32,3 @@ Implement a method which converts a String to the numeric ASCII representation o #### Hints - The [String class](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#toCharArray()) provides methods for conversion. - -#### Notes - -- Do not add additional external libraries. -- Interface - - You can use _[TAB]_ for auto-completion and _[SHIFT]_+_[TAB]_ for code inspection. - - Check _Menu_ -> _Help_ -> _Keyboard Shortcuts_. -- Finish - - Save your solution by clicking on the _disk icon_. - - Finally, choose _Menu_ -> _File_ -> _Close and Halt_. - - Do not forget to _Submit_ your solution in the _Assignments_ view. \ No newline at end of file From 1c74703da026f3b293cdaee6dbf577e7a9fbea5d Mon Sep 17 00:00:00 2001 From: Adrian Wilke Date: Mon, 18 Mar 2019 07:45:15 +0100 Subject: [PATCH 8/8] Test order, hidden test comment, output line break --- .../nbraderutils/javatemplate/AllTestsSuite.java | 7 +++++++ .../nbraderutils/javatemplate/Exercise1Test.java | 8 ++++++++ .../nbraderutils/javatemplate/OverallPointsTest.java | 1 + 3 files changed, 16 insertions(+) diff --git a/src/test/java/org/dice_research/nbraderutils/javatemplate/AllTestsSuite.java b/src/test/java/org/dice_research/nbraderutils/javatemplate/AllTestsSuite.java index ae18f30..1516ad4 100644 --- a/src/test/java/org/dice_research/nbraderutils/javatemplate/AllTestsSuite.java +++ b/src/test/java/org/dice_research/nbraderutils/javatemplate/AllTestsSuite.java @@ -4,7 +4,14 @@ import org.junit.platform.suite.api.SelectPackages; import org.junit.runner.RunWith; +// Alternative to set order of tests: +// import org.junit.platform.suite.api.SelectClasses; + @RunWith(JUnitPlatform.class) @SelectPackages({ "org.dice_research.nbraderutils.javatemplate" }) + +// Alternative to set order of tests: +// @SelectClasses({ Exercise1Test.class, OverallPointsTest.class }) + public class AllTestsSuite { } \ No newline at end of file diff --git a/src/test/java/org/dice_research/nbraderutils/javatemplate/Exercise1Test.java b/src/test/java/org/dice_research/nbraderutils/javatemplate/Exercise1Test.java index 8a8b668..d55342b 100644 --- a/src/test/java/org/dice_research/nbraderutils/javatemplate/Exercise1Test.java +++ b/src/test/java/org/dice_research/nbraderutils/javatemplate/Exercise1Test.java @@ -38,10 +38,14 @@ void testVisible() { @Test void testHidden1() { + // Ignore this cell + // BEGIN HIDDEN TESTS // The first hidden test should be similar to the visible test. test("Ho", new int[] { 72, 111 }, "Testing 'Ho'"); + // END HIDDEN TESTS + // Set the points for this test. OverallPointsTest.addPoints(14, this.getClass()); @@ -49,10 +53,14 @@ void testHidden1() { @Test void testHidden2() { + // Ignore this cell + // BEGIN HIDDEN TESTS // An additional test. test("HiHo", new int[] { 72, 105, 72, 111 }, "Testing 'HiHo'"); + // END HIDDEN TESTS + // Set the points for this test. OverallPointsTest.addPoints(10, this.getClass()); diff --git a/src/test/java/org/dice_research/nbraderutils/javatemplate/OverallPointsTest.java b/src/test/java/org/dice_research/nbraderutils/javatemplate/OverallPointsTest.java index 79d3e1e..f5510ef 100644 --- a/src/test/java/org/dice_research/nbraderutils/javatemplate/OverallPointsTest.java +++ b/src/test/java/org/dice_research/nbraderutils/javatemplate/OverallPointsTest.java @@ -45,6 +45,7 @@ void test() { exerciseBuilder.append(pointsExercise); exerciseBuilder.append(" = "); exerciseBuilder.append(testBuilder); + exerciseBuilder.append(System.lineSeparator()); pointsAssignment += pointsExercise; } System.out.println(exerciseBuilder.toString());