From da084deb7d6efa2172827bfef6fa4abcd1b15dae Mon Sep 17 00:00:00 2001 From: Martin Goik <goik@hdm-stuttgart.de> Date: Mon, 12 Dec 2016 18:13:25 +0100 Subject: [PATCH] IntMax project revisited --- Exam/Sd1/IntMax/Solution/pom.xml | 40 -------- .../de/hdm_stuttgart/mi/sd1/intmax/Max.java | 92 ------------------ .../hdm_stuttgart/mi/sd1/intmax/AppTest.java | 53 ---------- Exam/Sd1/IntMax/Test/pom.xml | 38 -------- .../de/hdm_stuttgart/mi/sd1/intmax/Max.java | 53 ---------- .../hdm_stuttgart/mi/sd1/intmax/AppTest.java | 16 --- .../Sd1/Tests/IntMax/Exam}/.gitignore | 0 Klausuren/Sd1/Tests/IntMax/Exam/pom.xml | 54 +++++++++++ .../de/hdm_stuttgart/mi/sd1/intmax/Max.java | 54 +++++++++++ .../hdm_stuttgart/mi/sd1/intmax/MaxTest.java | 79 +++++++++++++++ .../mein_ergebnis/ShowReachedPoints.java | 16 +++ .../Sd1/Tests/IntMax/Solution}/.gitignore | 0 .../Sd1/Tests/IntMax/Solution/Doc/a.xhtml | 65 +++++++++++++ Klausuren/Sd1/Tests/IntMax/Solution/pom.xml | 54 +++++++++++ .../de/hdm_stuttgart/mi/sd1/intmax/Max.java | 97 +++++++++++++++++++ .../hdm_stuttgart/mi/sd1/intmax/MaxTest.java | 79 +++++++++++++++ .../mein_ergebnis/ShowReachedPoints.java | 16 +++ .../Sd1/Tests/MaxThreeValueDiff/Exam/pom.xml | 15 ++- .../Tests/MaxThreeValueDiff/Solution/pom.xml | 11 +++ 19 files changed, 538 insertions(+), 294 deletions(-) delete mode 100644 Exam/Sd1/IntMax/Solution/pom.xml delete mode 100644 Exam/Sd1/IntMax/Solution/src/main/java/de/hdm_stuttgart/mi/sd1/intmax/Max.java delete mode 100644 Exam/Sd1/IntMax/Solution/src/test/java/de/hdm_stuttgart/mi/sd1/intmax/AppTest.java delete mode 100644 Exam/Sd1/IntMax/Test/pom.xml delete mode 100644 Exam/Sd1/IntMax/Test/src/main/java/de/hdm_stuttgart/mi/sd1/intmax/Max.java delete mode 100644 Exam/Sd1/IntMax/Test/src/test/java/de/hdm_stuttgart/mi/sd1/intmax/AppTest.java rename {Exam/Sd1/IntMax/Solution => Klausuren/Sd1/Tests/IntMax/Exam}/.gitignore (100%) create mode 100644 Klausuren/Sd1/Tests/IntMax/Exam/pom.xml create mode 100644 Klausuren/Sd1/Tests/IntMax/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/intmax/Max.java create mode 100644 Klausuren/Sd1/Tests/IntMax/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/intmax/MaxTest.java create mode 100644 Klausuren/Sd1/Tests/IntMax/Exam/src/test/java/de/hdm_stuttgart/sw1/klausur/mein_ergebnis/ShowReachedPoints.java rename {Exam/Sd1/IntMax/Test => Klausuren/Sd1/Tests/IntMax/Solution}/.gitignore (100%) create mode 100644 Klausuren/Sd1/Tests/IntMax/Solution/Doc/a.xhtml create mode 100644 Klausuren/Sd1/Tests/IntMax/Solution/pom.xml create mode 100644 Klausuren/Sd1/Tests/IntMax/Solution/src/main/java/de/hdm_stuttgart/mi/sd1/intmax/Max.java create mode 100644 Klausuren/Sd1/Tests/IntMax/Solution/src/test/java/de/hdm_stuttgart/mi/sd1/intmax/MaxTest.java create mode 100644 Klausuren/Sd1/Tests/IntMax/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/mein_ergebnis/ShowReachedPoints.java diff --git a/Exam/Sd1/IntMax/Solution/pom.xml b/Exam/Sd1/IntMax/Solution/pom.xml deleted file mode 100644 index 4dc3781de..000000000 --- a/Exam/Sd1/IntMax/Solution/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>de.hdm_stuttgart.mi.sd1</groupId> - <artifactId>intmax</artifactId> - <version>2.0</version> - <packaging>jar</packaging> - - <name>intmax</name> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.2</version> - <configuration> - <source>1.8</source> - <target>1.8</target> - </configuration> - </plugin> - - </plugins> - </build> - - <dependencies> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.12</version> - <scope>test</scope> - </dependency> - - </dependencies> - - - -</project> diff --git a/Exam/Sd1/IntMax/Solution/src/main/java/de/hdm_stuttgart/mi/sd1/intmax/Max.java b/Exam/Sd1/IntMax/Solution/src/main/java/de/hdm_stuttgart/mi/sd1/intmax/Max.java deleted file mode 100644 index 2c4a9b11f..000000000 --- a/Exam/Sd1/IntMax/Solution/src/main/java/de/hdm_stuttgart/mi/sd1/intmax/Max.java +++ /dev/null @@ -1,92 +0,0 @@ -package de.hdm_stuttgart.mi.sd1.intmax; - -/** - * Dealing with array values - * - */ -public class Max { - - /** - * An array may contain multiple values being equal to the maximum. - * The sample [-4, 5, 2, 5, 4] contains two elements being equal to - * the array's maximum value 5. This method retrieves the first index - * of an array element being equal to the maximum. In the current - * example the desired index is 1 pointing to the second array element. - * - * @param values An array of arbitrary values. - * - * @return The smallest index of an array member being equal to the maximum. - * <dl> - <dt><b>Precondition:</b></dt> - <dd>0 < values.length</dd> - <dt><b>Postcondition:</b></dt> - <dd>0 <= return value < values.length</dd> - </dl> - */ - public static int getFirstMaxIndex(int[] values) { - int - firstMaxIndex = 0; // The index of the first array element being equal to the maximum value - - for (int i = 1; i < values.length; i++) { - if (values[firstMaxIndex] < values[i]) {// Another value larger than the current maximum candidate - firstMaxIndex = i; // New index to possible first maximum value - } - } - return firstMaxIndex; - } - - /** - * An array may contain multiple values being equal to the maximum. - * The sample [-4, 5, 2, 5, 4] contains two elements being equal to - * the array's maximum value 5. This method retrieves all index - * values of array element being equal to the maximum and returns - * them as an array in ascending order. In the current example the - * returned array will contain the indices [1, 3] pointing to the - * second and fourth array elements. - * - * @param values An array of arbitrary values. - * - * @return All index values in ascending order of any array member's - * being equal to the maximum. - * <dl> - <dt><b>Precondition:</b></dt> - <dd>0 < values.length</dd> - <dt><b>Postcondition:</b></dt> - <dd>0 < length of returned array</dd> - </dl> - */ - public static int[] getMaxIndexValues(int[] values) { - int - numberOfMaxValues = 1, // The number of array elements being equal to the maximum. - firstMaxIndex = 0; // The index of the first array element being equal to the maximum value. - - for (int i = 1; i < values.length; i++) { - if (values[firstMaxIndex] == values[i]) { // Another value being identical to the maximum? - numberOfMaxValues++; - } else if (values[firstMaxIndex] < values[i]) {// Even greater than the maximum? - values[firstMaxIndex] = values[i]; // Raise the maximum candidate value - firstMaxIndex = i; // New index to possible first maximum value - numberOfMaxValues = 1; // No luck so far, redo from Start! - } - } - // Now we do know: - // 1. The first max value's index aka firstMaxIndex - // 2. the number of array members being equal to the array's maximum value. - // We can this allocate an array of required size: - // - final int[] ascendingIndexList = new int[numberOfMaxValues]; - - // .. and fill in the corresponding index values - int ascendingArrayIndex = 0; - // We already know the array's first element: - ascendingIndexList[ascendingArrayIndex++] = firstMaxIndex; - // Let's fill in the remaining index values - // - for (int i = firstMaxIndex + 1; i < values.length; i++) { - if (values[firstMaxIndex] == values[i]) { - ascendingIndexList[ascendingArrayIndex++] = i; - } - } - return ascendingIndexList; - } -} \ No newline at end of file diff --git a/Exam/Sd1/IntMax/Solution/src/test/java/de/hdm_stuttgart/mi/sd1/intmax/AppTest.java b/Exam/Sd1/IntMax/Solution/src/test/java/de/hdm_stuttgart/mi/sd1/intmax/AppTest.java deleted file mode 100644 index f45ea0b2b..000000000 --- a/Exam/Sd1/IntMax/Solution/src/test/java/de/hdm_stuttgart/mi/sd1/intmax/AppTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package de.hdm_stuttgart.mi.sd1.intmax; - -import org.junit.Assert; -import org.junit.Test; - -/** - * Unit test array max values. - */ -@SuppressWarnings("javadoc") -public class AppTest { - - @Test - public void testSingleValue() { - final int[] v = {-3}; - Assert.assertEquals(0, Max.getFirstMaxIndex(v)); - Assert.assertArrayEquals(new int[] {0}, Max.getMaxIndexValues(v)); - } - - @Test - public void testUniqueValues() { - final int[] v = {-3, 4, 100, 7, 11, 20}; - Assert.assertEquals(2, Max.getFirstMaxIndex(v)); - Assert.assertArrayEquals(new int[] {2}, Max.getMaxIndexValues(v)); - } - - @Test - public void testDuplicateStartValues() { - final int[] v = {40, 40, -0, 1, 7, 1, 12}; - Assert.assertEquals(0, Max.getFirstMaxIndex(v)); - Assert.assertArrayEquals(new int[] {0, 1}, Max.getMaxIndexValues(v)); - } - - @Test - public void testDuplicateEndValues() { - final int[] v = {-4, -4, 3, 7, 20, 20, 20}; - Assert.assertEquals(4, Max.getFirstMaxIndex(v)); - Assert.assertArrayEquals(new int[] {4, 5, 6}, Max.getMaxIndexValues(v)); - } - - @Test - public void testDuplicateCenterValues() { - final int[] v = {-4, -4, 3, 20, 20, 20, -6, 3}; - Assert.assertEquals(3, Max.getFirstMaxIndex(v)); - Assert.assertArrayEquals(new int[] {3, 4, 5}, Max.getMaxIndexValues(v)); - } - - @Test - public void testMultipleGroupsValues() { - final int[] v = {20, 20, -4, -4, 3, 20, 20, 20, -6, 3, 20, 20}; - Assert.assertEquals(0, Max.getFirstMaxIndex(v)); - Assert.assertArrayEquals(new int[] {0, 1, 5, 6, 7, 10, 11}, Max.getMaxIndexValues(v)); - } -} diff --git a/Exam/Sd1/IntMax/Test/pom.xml b/Exam/Sd1/IntMax/Test/pom.xml deleted file mode 100644 index 369bc5df0..000000000 --- a/Exam/Sd1/IntMax/Test/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>de.hdm_stuttgart.mi.sd1</groupId> - <artifactId>intmax</artifactId> - <version>1.0</version> - <packaging>jar</packaging> - - <name>intmax</name> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.2</version> - <configuration> - <source>1.8</source> - <target>1.8</target> - </configuration> - </plugin> - - </plugins> - </build> - - - <dependencies> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.12</version> - <scope>test</scope> - </dependency> - - </dependencies> -</project> diff --git a/Exam/Sd1/IntMax/Test/src/main/java/de/hdm_stuttgart/mi/sd1/intmax/Max.java b/Exam/Sd1/IntMax/Test/src/main/java/de/hdm_stuttgart/mi/sd1/intmax/Max.java deleted file mode 100644 index 9b2315236..000000000 --- a/Exam/Sd1/IntMax/Test/src/main/java/de/hdm_stuttgart/mi/sd1/intmax/Max.java +++ /dev/null @@ -1,53 +0,0 @@ -package de.hdm_stuttgart.mi.sd1.intmax; - -/** - * Dealing with array values - * - */ -public class Max { - - /** - * An array may contain multiple values being equal to the maximum. - * The sample [-4, 5, 2, 5, 4] contains two elements being equal to - * the array's maximum value 5. This method retrieves the first index - * of an array element being equal to the maximum. In the current - * example the desired index is 1 pointing to the second array element. - * - * @param values An array of arbitrary values. - * - * @return The smallest index of an array member being equal to the maximum. - * <dl> - <dt><b>Precondition:</b></dt> - <dd>0 < values.length</dd> - <dt><b>Postcondition:</b></dt> - <dd>0 <= return value < values.length</dd> - </dl> - */ - public static int getFirstMaxIndex(int[] values) { - return 0; // TODO - } - - /** - * An array may contain multiple values being equal to the maximum. - * The sample [-4, 5, 2, 5, 4] contains two elements being equal to - * the array's maximum value 5. This method retrieves all index - * values of array element being equal to the maximum and returns - * them as an array in ascending order. In the current example the - * returned array will contain the indices [1, 3] pointing to the - * second and fourth array elements. - * - * @param values An array of arbitrary values. - * - * @return All index values in ascending order of any array member's - * being equal to the maximum. - * <dl> - <dt><b>Precondition:</b></dt> - <dd>0 < values.length</dd> - <dt><b>Postcondition:</b></dt> - <dd>0 < length of returned array</dd> - </dl> - */ - public static int[] getMaxIndexValues(int[] values) { - return new int[] {0}; // TODO - } -} \ No newline at end of file diff --git a/Exam/Sd1/IntMax/Test/src/test/java/de/hdm_stuttgart/mi/sd1/intmax/AppTest.java b/Exam/Sd1/IntMax/Test/src/test/java/de/hdm_stuttgart/mi/sd1/intmax/AppTest.java deleted file mode 100644 index 55e1077d3..000000000 --- a/Exam/Sd1/IntMax/Test/src/test/java/de/hdm_stuttgart/mi/sd1/intmax/AppTest.java +++ /dev/null @@ -1,16 +0,0 @@ -package de.hdm_stuttgart.mi.sd1.intmax; - -import org.junit.Assert; -import org.junit.Test; - -/** - * Unit test array max values. - */ -@SuppressWarnings("javadoc") -public class AppTest { - - @Test - public void testMe() { - Assert.assertEquals(1, 1); // TODO - } -} diff --git a/Exam/Sd1/IntMax/Solution/.gitignore b/Klausuren/Sd1/Tests/IntMax/Exam/.gitignore similarity index 100% rename from Exam/Sd1/IntMax/Solution/.gitignore rename to Klausuren/Sd1/Tests/IntMax/Exam/.gitignore diff --git a/Klausuren/Sd1/Tests/IntMax/Exam/pom.xml b/Klausuren/Sd1/Tests/IntMax/Exam/pom.xml new file mode 100644 index 000000000..0843aa242 --- /dev/null +++ b/Klausuren/Sd1/Tests/IntMax/Exam/pom.xml @@ -0,0 +1,54 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>de.hdm_stuttgart.mi.sd1</groupId> + <artifactId>intmax</artifactId> + <version>2.0</version> + <packaging>jar</packaging> + + <name>Intmax</name> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <repositories> + <repository> + <id>hdm-mi-internal-maven-repo</id> + <url>https://maven.mi.hdm-stuttgart.de/artifacts</url> + </repository> + </repositories> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.2</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + + </plugins> + </build> + + <dependencies> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>de.hdm_stuttgart.mi.exam</groupId> + <artifactId>unitmarking</artifactId> + <version>0.9</version> + </dependency> + </dependencies> + +</project> diff --git a/Klausuren/Sd1/Tests/IntMax/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/intmax/Max.java b/Klausuren/Sd1/Tests/IntMax/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/intmax/Max.java new file mode 100644 index 000000000..3ea88aea2 --- /dev/null +++ b/Klausuren/Sd1/Tests/IntMax/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/intmax/Max.java @@ -0,0 +1,54 @@ +package de.hdm_stuttgart.mi.sd1.intmax; + +/** + * Dealing with array values + * + */ +public class Max { + + /** + * An array may contain multiple values being equal to the maximum. + * The sample {-4, 5, 2, 5, 4} contains two elements being equal to + * the array's maximum value 5 at index positions 1 and 3. This method + * retrieves the first index of an array element being equal to the + * maximum. In the current example the desired index is 1 pointing + * to the second array element. + * + * @param values An array of arbitrary values. + * + * @return The smallest index of an array member being equal to the maximum. + * <dl> + * <dt><b>Precondition:</b></dt> + * <dd>0 < values.length</dd> + * + * <dt><b>Postcondition:</b></dt> + * <dd>0 <= return value < values.length</dd> + * </dl> + */ + public static int getFirstMaxIndex(int[] values) { + return 0; // TODO + } + + /** + * <p>An array may contain multiple values being equal to the maximum. + * The sample {-4, 5, 2, 5, 4} contains two elements being equal to + * the array's maximum value 5 at index positions 1 and 3 + * respectively. This method retrieves all index values of array + * elements being equal to the maximum and returns + * them as an array in ascending order.</p> + * <p>In the current example the returned array equals {1, 3} + * pointing to the second and fourth array elements.</p> + * + * @param values An array of arbitrary values. + * + * @return + * <ul> + * <li>An empty array if null == values or 0 == values.length</li> + * <li>All index values in ascending order of any array member being equal to the + * maximum otherwise</li> + * </ul> + */ + public static int[] getMaxIndexValues(int[] values) { + return new int[] {13}; // TODO + } +} \ No newline at end of file diff --git a/Klausuren/Sd1/Tests/IntMax/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/intmax/MaxTest.java b/Klausuren/Sd1/Tests/IntMax/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/intmax/MaxTest.java new file mode 100644 index 000000000..84c10fa06 --- /dev/null +++ b/Klausuren/Sd1/Tests/IntMax/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/intmax/MaxTest.java @@ -0,0 +1,79 @@ +package de.hdm_stuttgart.mi.sd1.intmax; + +import java.util.Arrays; + +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.DisableOnDebug; +import org.junit.rules.TestRule; +import org.junit.rules.Timeout; +import org.junit.runners.MethodSorters; + +/** + * Unit test array max values. + */ +@SuppressWarnings({ "javadoc" }) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class MaxTest { + + + @Rule // Kill test if lasting longer than 1000 milliseconds unless in debugging mode + public final TestRule timeout = new DisableOnDebug(Timeout.millis(1000)); + + @Test + public void test01SingleValue() { + final int[] v = {-3}, + vCopy = Arrays.copyOf(v, v.length); + + Assert.assertEquals(0, Max.getFirstMaxIndex(v)); + Assert.assertArrayEquals(new int[] {0}, Max.getMaxIndexValues(v)); + Assert.assertArrayEquals(vCopy, v); // Don't touch original! + } + + @Test + public void test02UniqueValues() { + final int[] v = {-3, 4, 100, 7, 11, 20}, + vCopy = Arrays.copyOf(v, v.length); + Assert.assertEquals(2, Max.getFirstMaxIndex(v)); + Assert.assertArrayEquals(new int[] {2}, Max.getMaxIndexValues(v)); + Assert.assertArrayEquals(vCopy, v); // Don't touch original! + } + + @Test + public void test03DuplicateStartValues() { + final int[] v = {40, 40, -0, 1, 7, 1, 12}, + vCopy = Arrays.copyOf(v, v.length); + Assert.assertEquals(0, Max.getFirstMaxIndex(v)); + Assert.assertArrayEquals(new int[] {0, 1}, Max.getMaxIndexValues(v)); + Assert.assertArrayEquals(vCopy, v); // Don't touch original! + } + + @Test + public void test04DuplicateEndValues() { + final int[] v = {-4, -4, 3, 7, 20, 20, 20}, + vCopy = Arrays.copyOf(v, v.length); + Assert.assertEquals(4, Max.getFirstMaxIndex(v)); + Assert.assertArrayEquals(new int[] {4, 5, 6}, Max.getMaxIndexValues(v)); + Assert.assertArrayEquals(vCopy, v); // Don't touch original! + } + + @Test + public void test05DuplicateCenterValues() { + final int[] v = {-4, -4, 3, 20, 20, 20, -6, 3}, + vCopy = Arrays.copyOf(v, v.length); + Assert.assertEquals(3, Max.getFirstMaxIndex(v)); + Assert.assertArrayEquals(new int[] {3, 4, 5}, Max.getMaxIndexValues(v)); + Assert.assertArrayEquals(vCopy, v); // Don't touch original! + } + + @Test + public void test06MultipleGroupsValues() { + final int[] v = {20, 20, -4, -4, 3, 20, 20, 20, -6, 3, 20, 20}, + vCopy = Arrays.copyOf(v, v.length); + Assert.assertEquals(0, Max.getFirstMaxIndex(v)); + Assert.assertArrayEquals(new int[] {0, 1, 5, 6, 7, 10, 11}, Max.getMaxIndexValues(v)); + Assert.assertArrayEquals(vCopy, v); // Don't touch original! + } +} diff --git a/Klausuren/Sd1/Tests/IntMax/Exam/src/test/java/de/hdm_stuttgart/sw1/klausur/mein_ergebnis/ShowReachedPoints.java b/Klausuren/Sd1/Tests/IntMax/Exam/src/test/java/de/hdm_stuttgart/sw1/klausur/mein_ergebnis/ShowReachedPoints.java new file mode 100644 index 000000000..4cd79ff2e --- /dev/null +++ b/Klausuren/Sd1/Tests/IntMax/Exam/src/test/java/de/hdm_stuttgart/sw1/klausur/mein_ergebnis/ShowReachedPoints.java @@ -0,0 +1,16 @@ +package de.hdm_stuttgart.sw1.klausur.mein_ergebnis; + +import de.hdm_stuttgart.mi.exam.unitmarking.RunTests; +import de.hdm_stuttgart.mi.sd1.intmax.MaxTest; + +public class ShowReachedPoints { + + /** + * Execution reveals the number of reached points. + * + * @param args Unused + */ + public static void main(String[] args) { + RunTests.exec(MaxTest.class); + } +} diff --git a/Exam/Sd1/IntMax/Test/.gitignore b/Klausuren/Sd1/Tests/IntMax/Solution/.gitignore similarity index 100% rename from Exam/Sd1/IntMax/Test/.gitignore rename to Klausuren/Sd1/Tests/IntMax/Solution/.gitignore diff --git a/Klausuren/Sd1/Tests/IntMax/Solution/Doc/a.xhtml b/Klausuren/Sd1/Tests/IntMax/Solution/Doc/a.xhtml new file mode 100644 index 000000000..95076d6c5 --- /dev/null +++ b/Klausuren/Sd1/Tests/IntMax/Solution/Doc/a.xhtml @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html> +<html lang="de" xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title>Helper Methoden</title> + </head> + + <body><h2>Vorbereitung</h2><p>Entpacken Sie das oben sichtbare Archiv + <b>exam.zip</b> und importieren Sie den resultierenden Ordner + <code>Exam</code> als <span lang="en">Maven</span> Projekt in Ihren<span + lang="en"> Workspace</span>.</p><h2>Aufgabe</h2><p>Implementieren Sie die + beiden Methoden in der Klasse + <code>de.hdm_stuttgart.mi.sd1.intmax.Max</code>.</p><h2>Allgemeine + Hinweise</h2><ul> + <li><p>Die Javadoc Kommentare der Methode beschreiben das gewünschte + Verhalten. Wählen Sie im Package Explorer die Projektwurzel und + generieren Sie die HTML Dokumentation über die Menüpunkte <code>Run + -> Run As... -> Maven build</code> mit dem Parameter + <code>javadoc:javadoc</code> im Eingabefeld „Goals:â€. Die generierte + HTML Dokumentation wird im Unterordner <code>target/site/apidocs</code> + Ihres Projekts angelegt und kann durch einen Web Browser Ihrer Wahl + betrachtet werden.</p><p>Lesen Sie diese Dokumentation <b>sehr + genau</b>.</p></li> + + <li><p>Für die beiden Methoden stehen Ihnen in der Junit Testklasse + <code>de.hdm_stuttgart.sw1.klausur.test.Test_MaxDiff</code> im + <code>src/test/java</code> Zweig Ihres Projekts korrespondierende Tests + zur Verfügung. Nutzen Sie diese!</p><p>Die von Ihnen erreichte Punktzahl + richtet sich nach der Anzahl positiv bestandener Tests. Sie bekommen + keine Punkte für Tests, bei denen Ihre Implementierung „fast richtig“ + ist. Implementieren Sie daher im Zweifelsfall weniger Methoden, diese + dafür aber vollständig.</p><p>Die Ausführung der Klasse + <code>de.hdm_stuttgart.sw1.klausur.mein_ergebnis.ShowReachedPoints</code> + <b>als Java Programm</b> (nicht als Junit Test!) aus dem + <code>src/test/java</code> Zweig Ihres Projekts liefert Ihnen die Zahl + der insgesamt erreichten und erreichbaren Punkte.</p></li> + + <li><p>Nutzen Sie den Debugger oder logging Statements im Fall + fehlgeschlagener Testfälle, falls Sie das zugrundeliegende Problem nicht + unmittelbar lösen können.</p></li> + </ul><h2 id="upload">Hochladen Ihrer Lösung in das + Klausursystem</h2><p>Exportieren Sie Ihre Implementierung dieser und + weiterer Programmieraufgaben per Rechtsklick im Package Explorer Ihres + Eclipse Projekts. Wählen Sie im Kontextmenü unter + »Export-->General-->Archive File« einen auf <code>.zip</code> endenden + Archivnamen. Exportieren Sie Ihr Projekt in dieses <code>.zip</code> Archiv + und laden Sie es in das Ilias Klausursystem hoch (unteres Seitenende) und + beachten Sie:</p><ul> + <li style="color: red;">Die hochgeladene .zip Datei muss im + Klausursystem sichtbar sein.</li> + + <li style="color: red;">Reservieren Sie ausreichend Zeit vor Klausurende + für den Vorgang des Hochladens. Projekte, welche sich lediglich auf dem + Arbeitsplatzrechner befinden, werden nicht gewertet.</li> + + <li style="color: red;">Laden Sie keine Projekte mit Java Syntaxfehlern + hoch, diese werden nicht bewertet!</li> + + <li style="color: red;">Exportieren Sie Ihr Projekt <b>nicht</b> als + „.tgz“, „.java“, „.tar.gz“ o.ä. Das Klausursystem akzeptiert nur Archive + mit der Endung „.zip“.</li> + </ul><p>Falls Sie mehrere Archive hochladen, wird nur das zuletzt + hochgeladene Archiv bewertet. Sie können hochgeladene Archive + löschen.</p></body> +</html> diff --git a/Klausuren/Sd1/Tests/IntMax/Solution/pom.xml b/Klausuren/Sd1/Tests/IntMax/Solution/pom.xml new file mode 100644 index 000000000..1cf3f35b0 --- /dev/null +++ b/Klausuren/Sd1/Tests/IntMax/Solution/pom.xml @@ -0,0 +1,54 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>de.hdm_stuttgart.mi.sd1</groupId> + <artifactId>intmax_solution</artifactId> + <version>2.0</version> + <packaging>jar</packaging> + + <name>Intmax_solution</name> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <repositories> + <repository> + <id>hdm-mi-internal-maven-repo</id> + <url>https://maven.mi.hdm-stuttgart.de/artifacts</url> + </repository> + </repositories> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.2</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + + </plugins> + </build> + + <dependencies> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>de.hdm_stuttgart.mi.exam</groupId> + <artifactId>unitmarking</artifactId> + <version>0.9</version> + </dependency> + </dependencies> + +</project> diff --git a/Klausuren/Sd1/Tests/IntMax/Solution/src/main/java/de/hdm_stuttgart/mi/sd1/intmax/Max.java b/Klausuren/Sd1/Tests/IntMax/Solution/src/main/java/de/hdm_stuttgart/mi/sd1/intmax/Max.java new file mode 100644 index 000000000..40c0cdf50 --- /dev/null +++ b/Klausuren/Sd1/Tests/IntMax/Solution/src/main/java/de/hdm_stuttgart/mi/sd1/intmax/Max.java @@ -0,0 +1,97 @@ +package de.hdm_stuttgart.mi.sd1.intmax; + +/** + * Dealing with array values + * + */ +public class Max { + + /** + * An array may contain multiple values being equal to the maximum. + * The sample {-4, 5, 2, 5, 4} contains two elements being equal to + * the array's maximum value 5 at index positions 1 and 3. This method + * retrieves the first index of an array element being equal to the + * maximum. In the current example the desired index is 1 pointing + * to the second array element. + * + * @param values An array of arbitrary values. + * + * @return The smallest index of an array member being equal to the maximum. + * <dl> + * <dt><b>Precondition:</b></dt> + * <dd>0 < values.length</dd> + * + * <dt><b>Postcondition:</b></dt> + * <dd>0 <= return value < values.length</dd> + * </dl> + */ + public static int getFirstMaxIndex(final int[] values) { + int + firstMaxIndex = 0; // The index of the first array element being equal to the maximum value + + for (int i = 1; i < values.length; i++) { + if (values[firstMaxIndex] < values[i]) {// Another value larger than the current maximum candidate + firstMaxIndex = i; // New index to possible first maximum value + } + } + return firstMaxIndex; + } + + /** + * <p>An array may contain multiple values being equal to the maximum. + * The sample {-4, 5, 2, 5, 4} contains two elements being equal to + * the array's maximum value 5 at index positions 1 and 3 + * respectively. This method retrieves all index values of array + * elements being equal to the maximum and returns + * them as an array in ascending order.</p> + * <p>In the current example the returned array equals {1, 3} + * pointing to the second and fourth array elements.</p> + * + * @param values An array of arbitrary values. + * + * @return + * <ul> + * <li>An empty array if null == values or 0 == values.length</li> + * <li>All index values in ascending order of any array member being equal to the + * maximum otherwise</li> + * </ul> + */ + public static int[] getMaxIndexValues(final int[] values) { + if (null == values || values.length == 0) { + return new int[0]; + } + + int + numberOfMaxValues = 1, // The number of array elements being equal to the maximum. + firstMaxIndex = 0; // The index of the first array element being equal to the maximum value + // found so far. + + for (int i = 1; i < values.length; i++) { + if (values[firstMaxIndex] == values[i]) { // Another value being identical to the maximum? + numberOfMaxValues++; + } else if (values[firstMaxIndex] < values[i]) {// Value greater current maximum candidate? + firstMaxIndex = i; // Raise index to new candidate maximum value and + numberOfMaxValues = 1; // reset number of values found so far. + } + } + // Now we do know: + // 1. The first max value's index aka firstMaxIndex + // 2. the number of array members being equal to the array's maximum value. + // We can thus allocate an array of required size: + // + final int[] ascendingIndexList = new int[numberOfMaxValues]; + + // .. and fill in the corresponding index values + int ascendingArrayIndex = 0; + // We already know the array's first element: + ascendingIndexList[ascendingArrayIndex++] = firstMaxIndex; + // Let's fill in the remaining index values + // + for (int i = firstMaxIndex + 1; i < values.length; i++) { + if (values[firstMaxIndex] == values[i]) { + ascendingIndexList[ascendingArrayIndex++] = i; + } + } + return ascendingIndexList; + } +} \ No newline at end of file diff --git a/Klausuren/Sd1/Tests/IntMax/Solution/src/test/java/de/hdm_stuttgart/mi/sd1/intmax/MaxTest.java b/Klausuren/Sd1/Tests/IntMax/Solution/src/test/java/de/hdm_stuttgart/mi/sd1/intmax/MaxTest.java new file mode 100644 index 000000000..84c10fa06 --- /dev/null +++ b/Klausuren/Sd1/Tests/IntMax/Solution/src/test/java/de/hdm_stuttgart/mi/sd1/intmax/MaxTest.java @@ -0,0 +1,79 @@ +package de.hdm_stuttgart.mi.sd1.intmax; + +import java.util.Arrays; + +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.DisableOnDebug; +import org.junit.rules.TestRule; +import org.junit.rules.Timeout; +import org.junit.runners.MethodSorters; + +/** + * Unit test array max values. + */ +@SuppressWarnings({ "javadoc" }) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class MaxTest { + + + @Rule // Kill test if lasting longer than 1000 milliseconds unless in debugging mode + public final TestRule timeout = new DisableOnDebug(Timeout.millis(1000)); + + @Test + public void test01SingleValue() { + final int[] v = {-3}, + vCopy = Arrays.copyOf(v, v.length); + + Assert.assertEquals(0, Max.getFirstMaxIndex(v)); + Assert.assertArrayEquals(new int[] {0}, Max.getMaxIndexValues(v)); + Assert.assertArrayEquals(vCopy, v); // Don't touch original! + } + + @Test + public void test02UniqueValues() { + final int[] v = {-3, 4, 100, 7, 11, 20}, + vCopy = Arrays.copyOf(v, v.length); + Assert.assertEquals(2, Max.getFirstMaxIndex(v)); + Assert.assertArrayEquals(new int[] {2}, Max.getMaxIndexValues(v)); + Assert.assertArrayEquals(vCopy, v); // Don't touch original! + } + + @Test + public void test03DuplicateStartValues() { + final int[] v = {40, 40, -0, 1, 7, 1, 12}, + vCopy = Arrays.copyOf(v, v.length); + Assert.assertEquals(0, Max.getFirstMaxIndex(v)); + Assert.assertArrayEquals(new int[] {0, 1}, Max.getMaxIndexValues(v)); + Assert.assertArrayEquals(vCopy, v); // Don't touch original! + } + + @Test + public void test04DuplicateEndValues() { + final int[] v = {-4, -4, 3, 7, 20, 20, 20}, + vCopy = Arrays.copyOf(v, v.length); + Assert.assertEquals(4, Max.getFirstMaxIndex(v)); + Assert.assertArrayEquals(new int[] {4, 5, 6}, Max.getMaxIndexValues(v)); + Assert.assertArrayEquals(vCopy, v); // Don't touch original! + } + + @Test + public void test05DuplicateCenterValues() { + final int[] v = {-4, -4, 3, 20, 20, 20, -6, 3}, + vCopy = Arrays.copyOf(v, v.length); + Assert.assertEquals(3, Max.getFirstMaxIndex(v)); + Assert.assertArrayEquals(new int[] {3, 4, 5}, Max.getMaxIndexValues(v)); + Assert.assertArrayEquals(vCopy, v); // Don't touch original! + } + + @Test + public void test06MultipleGroupsValues() { + final int[] v = {20, 20, -4, -4, 3, 20, 20, 20, -6, 3, 20, 20}, + vCopy = Arrays.copyOf(v, v.length); + Assert.assertEquals(0, Max.getFirstMaxIndex(v)); + Assert.assertArrayEquals(new int[] {0, 1, 5, 6, 7, 10, 11}, Max.getMaxIndexValues(v)); + Assert.assertArrayEquals(vCopy, v); // Don't touch original! + } +} diff --git a/Klausuren/Sd1/Tests/IntMax/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/mein_ergebnis/ShowReachedPoints.java b/Klausuren/Sd1/Tests/IntMax/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/mein_ergebnis/ShowReachedPoints.java new file mode 100644 index 000000000..4cd79ff2e --- /dev/null +++ b/Klausuren/Sd1/Tests/IntMax/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/mein_ergebnis/ShowReachedPoints.java @@ -0,0 +1,16 @@ +package de.hdm_stuttgart.sw1.klausur.mein_ergebnis; + +import de.hdm_stuttgart.mi.exam.unitmarking.RunTests; +import de.hdm_stuttgart.mi.sd1.intmax.MaxTest; + +public class ShowReachedPoints { + + /** + * Execution reveals the number of reached points. + * + * @param args Unused + */ + public static void main(String[] args) { + RunTests.exec(MaxTest.class); + } +} diff --git a/Klausuren/Sd1/Tests/MaxThreeValueDiff/Exam/pom.xml b/Klausuren/Sd1/Tests/MaxThreeValueDiff/Exam/pom.xml index f91823dba..f4802e7bf 100644 --- a/Klausuren/Sd1/Tests/MaxThreeValueDiff/Exam/pom.xml +++ b/Klausuren/Sd1/Tests/MaxThreeValueDiff/Exam/pom.xml @@ -3,11 +3,22 @@ <modelVersion>4.0.0</modelVersion> <groupId>de.hdm-stuttgart.de.sd1</groupId> - <artifactId>diff</artifactId> + <artifactId>diff_solution</artifactId> <version>1.0</version> <packaging>jar</packaging> - <name>Diff</name> + <name>Diff_solution</name> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <repositories> + <repository> + <id>hdm-mi-internal-maven-repo</id> + <url>https://maven.mi.hdm-stuttgart.de/artifacts</url> + </repository> + </repositories> <build> <plugins> diff --git a/Klausuren/Sd1/Tests/MaxThreeValueDiff/Solution/pom.xml b/Klausuren/Sd1/Tests/MaxThreeValueDiff/Solution/pom.xml index 9d7b0d4d6..f4802e7bf 100644 --- a/Klausuren/Sd1/Tests/MaxThreeValueDiff/Solution/pom.xml +++ b/Klausuren/Sd1/Tests/MaxThreeValueDiff/Solution/pom.xml @@ -9,6 +9,17 @@ <name>Diff_solution</name> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <repositories> + <repository> + <id>hdm-mi-internal-maven-repo</id> + <url>https://maven.mi.hdm-stuttgart.de/artifacts</url> + </repository> + </repositories> + <build> <plugins> <plugin> -- GitLab