From 160caf591deb3e1b8d4431ac9cfc8afd9d573ebb Mon Sep 17 00:00:00 2001 From: "Dr. Martin Goik" <goik@hdm-stuttgart.de> Date: Fri, 19 Feb 2021 22:23:04 +0100 Subject: [PATCH] Exam winter 2020 --- Doc/Sd1/Exam/2020/Winter_1/exam.xml | 280 +++++++++++++++++ Doc/Sd1/appendix.xml | 3 + .../mi/sd1/aufgabe1/_3_Maexchen.java | 10 +- .../mi/sd1/aufgabe2/Beispiel.java | 8 +- .../mi/sd1/aufgabe2/MaexleWurf.java | 11 +- .../mi/sd1/test/aufgabe1/Test_3_Maexchen.java | 36 +-- .../test/aufgabe2/Test_MaexchenVergleich.java | 41 +-- .../de/hdm_stuttgart/mi/sd1/aufgabe2/Geo.java | 2 +- .../de/hdm_stuttgart/mi/sd1/aufgabe2/Geo.java | 2 +- Klausuren/Sd1/2020winter/First/Exam/pom.xml | 119 ++++++++ .../First/Exam/src/main/assembly/assembly.xml | 36 +++ .../mi/sd1/task1/_1_Triangle.java | 26 ++ .../mi/sd1/task1/_2_DigitExpressions.java | 66 ++++ .../hdm_stuttgart/mi/sd1/task1/_3_Range.java | 112 +++++++ .../mi/sd1/task1/_4_Armstrong.java | 57 ++++ .../mi/sd1/task1/package-info.java | 16 + .../mi/sd1/task2/_5_DayConverter.java | 51 ++++ .../mi/sd1/task2/package-info.java | 5 + .../mi/sd1/task1/doc-files/triangle.svg | 286 ++++++++++++++++++ .../First/Exam/src/main/resources/log4j2.xml | 21 ++ .../mi/sd1/test/ShowReachedPoints.java | 25 ++ .../mi/sd1/test/ignore_me/ObjectWrapper.java | 169 +++++++++++ .../mi/sd1/test/task1/Test_1_Triangle.java | 23 ++ .../test/task1/Test_2_DigitExpressions.java | 83 +++++ .../mi/sd1/test/task1/Test_3_Range.java | 64 ++++ .../mi/sd1/test/task1/Test_4_Armstrong.java | 32 ++ .../sd1/test/task2/Test_5_DayConverter.java | 59 ++++ Klausuren/Sd1/2020winter/First/Solve/pom.xml | 120 ++++++++ .../Solve/src/main/assembly/assembly.xml | 36 +++ .../mi/sd1/ignore_me/DayConverterDemo.java | 22 ++ .../hdm_stuttgart/mi/sd1/ignore_me/Test.java | 20 ++ .../mi/sd1/task1/_1_Triangle.java | 28 ++ .../mi/sd1/task1/_2_DigitExpressions.java | 73 +++++ .../hdm_stuttgart/mi/sd1/task1/_3_Range.java | 148 +++++++++ .../mi/sd1/task1/_4_Armstrong.java | 100 ++++++ .../mi/sd1/task1/package-info.java | 16 + .../mi/sd1/task2/_5_DayConverter.java | 76 +++++ .../mi/sd1/task2/package-info.java | 5 + .../mi/sd1/task1/doc-files/triangle.svg | 286 ++++++++++++++++++ .../First/Solve/src/main/resources/log4j2.xml | 21 ++ .../mi/sd1/test/ShowReachedPoints.java | 25 ++ .../mi/sd1/test/ignore_me/ObjectWrapper.java | 169 +++++++++++ .../mi/sd1/test/task1/Test_1_Triangle.java | 23 ++ .../test/task1/Test_2_DigitExpressions.java | 83 +++++ .../mi/sd1/test/task1/Test_3_Range.java | 64 ++++ .../mi/sd1/test/task1/Test_4_Armstrong.java | 32 ++ .../sd1/test/task2/Test_5_DayConverter.java | 59 ++++ 47 files changed, 2999 insertions(+), 50 deletions(-) create mode 100644 Doc/Sd1/Exam/2020/Winter_1/exam.xml create mode 100644 Klausuren/Sd1/2020winter/First/Exam/pom.xml create mode 100644 Klausuren/Sd1/2020winter/First/Exam/src/main/assembly/assembly.xml create mode 100644 Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_1_Triangle.java create mode 100644 Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_2_DigitExpressions.java create mode 100644 Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_3_Range.java create mode 100644 Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_4_Armstrong.java create mode 100644 Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java create mode 100644 Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/_5_DayConverter.java create mode 100644 Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java create mode 100644 Klausuren/Sd1/2020winter/First/Exam/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/triangle.svg create mode 100644 Klausuren/Sd1/2020winter/First/Exam/src/main/resources/log4j2.xml create mode 100644 Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/ShowReachedPoints.java create mode 100644 Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/ignore_me/ObjectWrapper.java create mode 100644 Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_1_Triangle.java create mode 100644 Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_2_DigitExpressions.java create mode 100644 Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_3_Range.java create mode 100644 Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_4_Armstrong.java create mode 100644 Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task2/Test_5_DayConverter.java create mode 100644 Klausuren/Sd1/2020winter/First/Solve/pom.xml create mode 100644 Klausuren/Sd1/2020winter/First/Solve/src/main/assembly/assembly.xml create mode 100644 Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/DayConverterDemo.java create mode 100644 Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/Test.java create mode 100644 Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_1_Triangle.java create mode 100644 Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_2_DigitExpressions.java create mode 100644 Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_3_Range.java create mode 100644 Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_4_Armstrong.java create mode 100644 Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java create mode 100644 Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/_5_DayConverter.java create mode 100644 Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java create mode 100644 Klausuren/Sd1/2020winter/First/Solve/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/triangle.svg create mode 100644 Klausuren/Sd1/2020winter/First/Solve/src/main/resources/log4j2.xml create mode 100644 Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/ShowReachedPoints.java create mode 100644 Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/ignore_me/ObjectWrapper.java create mode 100644 Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_1_Triangle.java create mode 100644 Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_2_DigitExpressions.java create mode 100644 Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_3_Range.java create mode 100644 Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_4_Armstrong.java create mode 100644 Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task2/Test_5_DayConverter.java diff --git a/Doc/Sd1/Exam/2020/Winter_1/exam.xml b/Doc/Sd1/Exam/2020/Winter_1/exam.xml new file mode 100644 index 000000000..978d128fe --- /dev/null +++ b/Doc/Sd1/Exam/2020/Winter_1/exam.xml @@ -0,0 +1,280 @@ +<?xml version="1.0" encoding="UTF-8"?> +<section version="5.0" xml:id="sd1_exam_2020_winter" xml:lang="en" + xmlns="http://docbook.org/ns/docbook" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:xila="http://www.w3.org/2001/XInclude/local-attributes" + xmlns:xi="http://www.w3.org/2001/XInclude" + xmlns:trans="http://docbook.org/ns/transclusion" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns:m="http://www.w3.org/1998/Math/MathML" + xmlns:html="http://www.w3.org/1999/xhtml" + xmlns:db="http://docbook.org/ns/docbook"> + <title>SD1 examination winter 2020/1</title> + + <section xml:id="sd1_exam_2020_winter_task1"> + <title>Implementing tasks</title> + + <section xml:id="sd1_exam_2020_winter_task1_preparation"> + <title>Preparation</title> + + <para>Download and unzip the above file <filename>exam.zip</filename>. + Then import the resulting <filename>Exam</filename> Project into your + <productname>IDEA</productname> IDE by choosing »File --> Open...« + subsequently selecting the <filename>Exam/pom.xml</filename> + file.</para> + </section> + + <section xml:id="sd1_exam_2020_winter_task1_description"> + <title>Description</title> + + <para>Your imported project contains:</para> + + <itemizedlist> + <listitem> + <para>Partial implementations of classes and methods.</para> + </listitem> + + <listitem> + <para><productname>Javadoc</productname> comments describing the + desired behaviour</para> + </listitem> + + <listitem> + <para><productname>Junit</productname> tests for testing the desired + (not yet implemented) behaviour.</para> + </listitem> + </itemizedlist> + </section> + + <section xml:id="sd1_exam_2020_winter_task1_tasks"> + <title>Tasks</title> + + <para>Complete the implementation of classes and methods in both + packages <package>de.hdm_stuttgart.mi.sd1.task1</package> and + <package>de.hdm_stuttgart.mi.sd1.task2</package>. Your project's + <filename>test</filename> branch contains corresponding + <productname>Junit</productname> tests for each class / method to be + implemented.</para> + </section> + + <section xml:id="sd1_exam_2020_winter_task1_hints"> + <title>Hints</title> + + <itemizedlist> + <listitem> + <para>Your score solely depends on the number of successfully + executing unit tests. A »nearly correct« implementation failing with + respect to a given unit tests will contribute no points at + all.</para> + + <para>General advice: Implement less but correctly.</para> + </listitem> + + <listitem> + <para>Mind special cases <abbrev>i.e.</abbrev> <code>null</code> + variable values or <code>null</code> values being contained in + arrays.</para> + </listitem> + + <listitem> + <para>In case of test failures both the + <productname>IDEA</productname> debugger and logging statements are + your friend.</para> + </listitem> + + <listitem> + <para>Executing + <package>de.hdm_stuttgart.mi.sd1.test</package>.<classname>ShowReachedPoints</classname> + in your project's <filename>test</filename> branch as a + <productname>Java</productname> application (not as + <productname>Junit</productname> test!) shows your number of points + reached so far.</para> + </listitem> + + <listitem> + <para>Do not model your implementations along unit test definitions + i.e avoid <link + xlink:href="https://freedocs.mi.hdm-stuttgart.de/__slidesd1_appendix.html#/sd1_fig_testDontCheat">cheating + this way</link>! Such behaviour will be regarded as an attempt at + deception (<foreignphrase + xml:lang="de">Täuschungsversuch</foreignphrase>).</para> + </listitem> + </itemizedlist> + </section> + + <section version="5.1" xml:id="sd1_exam_2020_winter_uploadFirst"> + <title>Project upload</title> + + <para>Export your project by hitting »File« --> »Export to Zip File« + in IDEA creating an <abbrev>e.g.</abbrev> + <filename>solution-1.zip</filename> file. Hit the <quote> choose + file</quote> button in your <productname>ILIAS</productname> browser tab + and select <filename>solution-1.zip</filename>. Subsequently click + <quote>upload</quote>. Do not forget to advance to the next question for + actually saving your upload. Common pitfalls:</para> + + <itemizedlist> + <listitem> + <para>Do not select the wrong archive! In particular avoid choosing + the original <filename>exam.zip</filename> skeleton.</para> + </listitem> + + <listitem> + <para>After uploading check for <filename>solution_1.zip</filename> + being visible in the examination system.</para> + </listitem> + + <listitem> + <para>You may upload multiple versions i.e. + <filename>solution_2.zip</filename> etc. . Only your least uploaded + archive will become subject to marking.</para> + </listitem> + </itemizedlist> + </section> + + <section xml:id="sd1_exam_2020_winter_examCaveats"> + <title>Caveats</title> + + <itemizedlist> + <listitem> + <para>When approaching examination ending time check your input for + completeness.</para> + </listitem> + + <listitem> + <para>Projects residing just on your local workstation cannot be + recovered after exam termination.</para> + </listitem> + </itemizedlist> + </section> + </section> + + <section xml:id="sd1_exam_2020_winter_task2"> + <title>Type conflict</title> + + <qandaset defaultlabel="qanda" xml:id="sd1_exam_2020_winter_task2Qanda"> + <qandadiv> + <qandaentry> + <question> + <para>We consider:</para> + + <programlisting language="java">byte divideByThree(final byte value) { + return value / 3; // Compile Error: Incompatible types. + // Required: byte + // Found: int +}</programlisting> + + <para>Using a cast solves our problem syntactically:</para> + + <programlisting language="java">byte divideByThree(final byte value) { + return (byte)(value / 3); +}</programlisting> + + <para>Answer the following questions:</para> + + <orderedlist> + <listitem> + <para>Why does the compile time error happen in the first + place?</para> + </listitem> + + <listitem> + <para>Casts may have negative effects <abbrev>i.e.</abbrev> + truncation problems. May this become a problem with respect to + the second code snippet?</para> + </listitem> + </orderedlist> + </question> + + <answer> + <orderedlist> + <listitem> + <para>According to <link + xlink:href="https://freedocs.mi.hdm-stuttgart.de/__slidesw1LanguageFundamental.html#/sd1_fig_genericBinaryTypeExamples">Binary + operator type examples</link> the <code language="java">value + / 3</code> expression is of type <code + language="java">int</code> rather then <code + language="java">byte</code>. This contradicts the method's + return type of <code language="java">byte</code> causing the + compile time error.</para> + </listitem> + + <listitem> + <para>Dividing any value by three always stays within a given + type's range. For example <code language="java">127 / 3</code> + equals 42 and <code language="java">-128 / 3</code> equals + -42. Casting the <code language="java">value / 3</code> + expression into a <code language="java">byte</code> is thus a + safe operation guaranteed to avoid any data truncation + problems.</para> + </listitem> + </orderedlist> + </answer> + </qandaentry> + </qandadiv> + </qandaset> + </section> + + <section xml:id="sd1_exam_2020_winter_task3"> + <title>Weird subtraction</title> + + <qandaset defaultlabel="qanda" xml:id="sd1_exam_2020_winter_task3Qanda"> + <qandadiv> + <qandaentry> + <question> + <para>Consider the following code snippet:</para> + + <informaltable border="1"> + <tr> + <th>Code</th> + + <th>Result</th> + </tr> + + <tr> + <td valign="top"><programlisting language="java">char c = 0; +c -= 1; +int cc = c; +System.out.println("cc == " + cc);</programlisting></td> + + <td valign="top"><screen>cc == 65535</screen></td> + </tr> + </informaltable> + + <para>How comes the operator <code language="java">c -= 1</code> + acting on c starting from 0 yields a positive value of + 65535?</para> + </question> + + <answer> + <para>A <code language="java">char</code> ranges from 0 to + <inlineequation> + <m:math display="inline"> + <m:mrow> + <m:msup> + <m:mi>2</m:mi> + + <m:mi>16</m:mi> + </m:msup> + + <m:mo>-</m:mo> + + <m:mi>1</m:mi> + </m:mrow> + </m:math> + </inlineequation>. The <code language="java">-=</code> operator + steps from the lowest possible value to the type's maximum in a + cyclic fashion:</para> + + <screen> 0 00000000 00000000 + -1 -00000000 00000001 +----- ------------------ +65535 11111111 11111111 + +</screen> + </answer> + </qandaentry> + </qandadiv> + </qandaset> + </section> +</section> diff --git a/Doc/Sd1/appendix.xml b/Doc/Sd1/appendix.xml index e4b87b179..7f37287dc 100644 --- a/Doc/Sd1/appendix.xml +++ b/Doc/Sd1/appendix.xml @@ -3097,6 +3097,9 @@ Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.372 sec</scree <section xml:id="sd1_exams"> <title>Past Software Development 1 examinations</title> + <xi:include href="Exam/2020/Winter_1/exam.xml" xpointer="element(/1)" + ns:idfixup="auto"/> + <xi:include href="Exam/2020/Summer/exam.xml" xpointer="element(/1)" ns:idfixup="auto"/> diff --git a/Klausuren/Sd1/2017winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe1/_3_Maexchen.java b/Klausuren/Sd1/2017winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe1/_3_Maexchen.java index a76076195..6ae749f2a 100644 --- a/Klausuren/Sd1/2017winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe1/_3_Maexchen.java +++ b/Klausuren/Sd1/2017winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe1/_3_Maexchen.java @@ -1,5 +1,7 @@ package de.hdm_stuttgart.mi.sd1.aufgabe1; +import de.hdm_stuttgart.mi.sd1.model.Wuerfel; + /** * <p>Bewertungen für das Würfelspiel «Mäxchen» (Schwäbisch «Mäxle»). Gespielt wird mit zwei * Würfeln, jeweils mit Augenzahl 1 bis 6:</p> @@ -27,7 +29,7 @@ public class _3_Maexchen { * @param wuerfel2 Die Augenzahl des zweiten Würfels. * @return <code>true</code>, falls es sich um einen Pasch handelt, ansonsten <code>false</code>. */ - static public boolean istPasch(final int wuerfel1, final int wuerfel2) { + static public boolean istPasch(final Wuerfel wuerfel1, final Wuerfel wuerfel2) { return wuerfel1 == wuerfel2; } @@ -38,8 +40,8 @@ public class _3_Maexchen { * @param wuerfel2 Die Augenzahl des zweiten Würfels. * @return <code>true</code>, falls es sich um ein »Mäxchen« handelt, ansonsten <code>false</code>. */ - static public boolean istMaexchen(final int wuerfel1, final int wuerfel2) { - return 3 == wuerfel1 + wuerfel2; + static public boolean istMaexchen(final Wuerfel wuerfel1, final Wuerfel wuerfel2) { + return 3 == wuerfel1.wert + wuerfel2.wert; } /** @@ -49,7 +51,7 @@ public class _3_Maexchen { * @param wuerfel2 Die Augenzahl des zweiten Würfels. * @return <code>true</code>, falls es sich um keinen Sonderfall handelt, ansonsten <code>false</code>. */ - static public boolean istKeinSonderfall(final int wuerfel1, final int wuerfel2) { + static public boolean istKeinSonderfall(final Wuerfel wuerfel1, final Wuerfel wuerfel2) { return !istPasch(wuerfel1, wuerfel2) && !istMaexchen(wuerfel1, wuerfel2); } diff --git a/Klausuren/Sd1/2017winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe2/Beispiel.java b/Klausuren/Sd1/2017winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe2/Beispiel.java index b301e0377..6cf883ab8 100644 --- a/Klausuren/Sd1/2017winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe2/Beispiel.java +++ b/Klausuren/Sd1/2017winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe2/Beispiel.java @@ -1,5 +1,7 @@ package de.hdm_stuttgart.mi.sd1.aufgabe2; +import de.hdm_stuttgart.mi.sd1.model.Wuerfel; + /** * Diese Klasse dient nur als Beispiel und muss daher auch nicht geändert werden. */ @@ -7,9 +9,9 @@ public class Beispiel { public static void main(String[] args) { final MaexleWurf - w1 = new MaexleWurf(1, 2) // Ein Mäxchen, höchster möglicher Wert. - ,w2 = new MaexleWurf(1, 4) // Ein »normaler« Wurf. - ,w3 = new MaexleWurf(2,2); // + w1 = new MaexleWurf(Wuerfel.EINS, Wuerfel.ZWEI) // Ein Mäxchen, höchster möglicher Wert. + ,w2 = new MaexleWurf(Wuerfel.EINS, Wuerfel.VIER) // Ein »normaler« Wurf. + ,w3 = new MaexleWurf(Wuerfel.ZWEI, Wuerfel.ZWEI); // System.out.println(w1.compareTo(w2)); System.out.println(w3.compareTo(w1)); diff --git a/Klausuren/Sd1/2017winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe2/MaexleWurf.java b/Klausuren/Sd1/2017winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe2/MaexleWurf.java index 3e2a0658c..fc204a957 100644 --- a/Klausuren/Sd1/2017winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe2/MaexleWurf.java +++ b/Klausuren/Sd1/2017winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe2/MaexleWurf.java @@ -1,6 +1,7 @@ package de.hdm_stuttgart.mi.sd1.aufgabe2; import de.hdm_stuttgart.mi.sd1.aufgabe1._3_Maexchen; +import de.hdm_stuttgart.mi.sd1.model.Wuerfel; /** * <p>Darstellung eines Mäxchen Wurfs, z.B. (3|2), siehe auch die Erläuterungen in {@link _3_Maexchen} und @@ -11,7 +12,7 @@ import de.hdm_stuttgart.mi.sd1.aufgabe1._3_Maexchen; */ public class MaexleWurf { - private final int untereAugenzahl, obereAugenzahl; + private final Wuerfel untereAugenzahl, obereAugenzahl; /** * Ein Wurf bestehend aus den Augenzahlen beider Würfel. Die Reihenfolge der Augenzahlen spielt dabei keine Rolle. @@ -20,8 +21,8 @@ public class MaexleWurf { * @param wuerfel2 Augenzahl des zweiten Würfels. */ - public MaexleWurf(final int wuerfel1, final int wuerfel2) { - if (wuerfel1 <= wuerfel2) { + public MaexleWurf(final Wuerfel wuerfel1, final Wuerfel wuerfel2) { + if (wuerfel1.wert <= wuerfel2.wert) { untereAugenzahl = wuerfel1; obereAugenzahl = wuerfel2; } else { @@ -99,9 +100,9 @@ public class MaexleWurf { private int getWert() { if (_3_Maexchen.istKeinSonderfall(untereAugenzahl, obereAugenzahl)) { - return untereAugenzahl + 10 * obereAugenzahl; // Nix besonderes, nur zählen, maximal 65. + return untereAugenzahl.wert + 10 * obereAugenzahl.wert; // Nix besonderes, nur zählen, maximal 65. } else if (_3_Maexchen.istPasch(untereAugenzahl, obereAugenzahl)) { - return 65 + untereAugenzahl; // Pasch: Höchster »Normalwert« + Paschwert (1-6), maximal 71. + return 65 + untereAugenzahl.wert; // Pasch: Höchster »Normalwert« + Paschwert (1-6), maximal 71. } else { return 72; // Mäxchen: Höchster Wert } diff --git a/Klausuren/Sd1/2017winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/aufgabe1/Test_3_Maexchen.java b/Klausuren/Sd1/2017winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/aufgabe1/Test_3_Maexchen.java index 673ef9b5f..53ced96a4 100644 --- a/Klausuren/Sd1/2017winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/aufgabe1/Test_3_Maexchen.java +++ b/Klausuren/Sd1/2017winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/aufgabe1/Test_3_Maexchen.java @@ -3,6 +3,7 @@ package de.hdm_stuttgart.mi.sd1.test.aufgabe1; import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; import de.hdm_stuttgart.mi.exam.unitmarking.Marking; import de.hdm_stuttgart.mi.sd1.aufgabe1._3_Maexchen; +import de.hdm_stuttgart.mi.sd1.model.Wuerfel; import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; @@ -19,12 +20,13 @@ public class Test_3_Maexchen extends ExaminationTestDefaults { * Pasch. */ @Test @Marking(points = 2) public void test_220() { - for (int i = 1; i <= 6; i++) { - for (int j = 1; j <= 6; j++) { - if (j == i) { - Assert.assertTrue("i = " + i + ", j = " + j, _3_Maexchen.istPasch(i, j)); + for (final Wuerfel w1: Wuerfel.values()) { + for (final Wuerfel w2: Wuerfel.values()) { + final String msg = w1 + ", " + w2 + " should be "; + if (w1 == w2) { + Assert.assertTrue(msg + "true", _3_Maexchen.istPasch(w1, w2)); } else { - Assert.assertFalse("i = " + i + ", j = " + j, _3_Maexchen.istPasch(i, j)); + Assert.assertFalse(msg + "false", _3_Maexchen.istPasch(w1, w2)); } } } @@ -33,12 +35,13 @@ public class Test_3_Maexchen extends ExaminationTestDefaults { * Mäxchen. */ @Test @Marking(points = 2) public void test_240() { - for (int i = 1; i <= 6; i++) { - for (int j = 1; j <= 6; j++) { - if (3 == j + i) { - Assert.assertTrue("i = " + i + ", j = " + j, _3_Maexchen.istMaexchen(i, j)); + for (final Wuerfel w1: Wuerfel.values()) { + for (final Wuerfel w2: Wuerfel.values()) { + final String msg = w1 + ", " + w2 + " should be "; + if (3 == w1.wert + w2.wert) { + Assert.assertTrue(msg + "true", _3_Maexchen.istMaexchen(w1, w2)); } else { - Assert.assertFalse("i = " + i + ", j = " + j, _3_Maexchen.istMaexchen(i, j)); + Assert.assertFalse(msg + "false", _3_Maexchen.istMaexchen(w1, w2)); } } } @@ -47,14 +50,13 @@ public class Test_3_Maexchen extends ExaminationTestDefaults { * Kein Sonderfall. */ @Test public void test_280() { - for (int i = 1; i <= 6; i++) { - for (int j = 1; j < 6; j++) { - //System.out.println("i = " + i + ", j = " + j); - if ( i == j || // »Pasch« oder - 3 == i + j) { // »Mäxchen« - Assert.assertFalse("i = " + i + ", j = " + j, _3_Maexchen.istKeinSonderfall(i, j)); + for (final Wuerfel w1: Wuerfel.values()) { + for (final Wuerfel w2: Wuerfel.values()) { + final String msg = w1 + ", " + w2 + " should be "; + if (w1 == w2 || 3 == w1.wert + w2.wert) { + Assert.assertFalse(msg + "false", _3_Maexchen.istKeinSonderfall(w1, w2)); } else { - Assert.assertTrue("i = " + i + ", j = " + j, _3_Maexchen.istKeinSonderfall(i, j)); + Assert.assertTrue(msg + "true", _3_Maexchen.istKeinSonderfall(w1, w2)); } } } diff --git a/Klausuren/Sd1/2017winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/aufgabe2/Test_MaexchenVergleich.java b/Klausuren/Sd1/2017winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/aufgabe2/Test_MaexchenVergleich.java index 572d3476b..23a928964 100644 --- a/Klausuren/Sd1/2017winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/aufgabe2/Test_MaexchenVergleich.java +++ b/Klausuren/Sd1/2017winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/aufgabe2/Test_MaexchenVergleich.java @@ -2,6 +2,7 @@ package de.hdm_stuttgart.mi.sd1.test.aufgabe2; import de.hdm_stuttgart.mi.sd1.aufgabe2.MaexleWurf; +import de.hdm_stuttgart.mi.sd1.model.Wuerfel; import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; @@ -9,8 +10,7 @@ import org.junit.runners.MethodSorters; import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; import de.hdm_stuttgart.mi.exam.unitmarking.Marking; - -import java.util.Arrays; +import static de.hdm_stuttgart.mi.sd1.model.Wuerfel.*; /** * Teste Ordnung von Würfelergebnissen beim »Mäxchen« Spiel. @@ -32,26 +32,26 @@ public class Test_MaexchenVergleich extends ExaminationTestDefaults { static { int index = 0; - for (int i = 3; i <= 6; i++) { // 5 + 4 + 3 + 2 + 1 == countNichtSonderfälle - for (int j = 1; j < i; j++) { - nichtSonderFaelle1[index] = new MaexleWurf(i, j); - nichtSonderFaelle2[index] = new MaexleWurf(j, i); + for (int i = 2; i < 6; i++) { // 5 + 4 + 3 + 2 + 1 == countNichtSonderfälle + for (int j = 0; j < i; j++) { + nichtSonderFaelle1[index] = new MaexleWurf(Wuerfel.values()[i], Wuerfel.values()[j]); + nichtSonderFaelle2[index] = new MaexleWurf(Wuerfel.values()[j], Wuerfel.values()[i]); index++; } } - for (int i = 1; i <= 6; i++) { - paschFaelle[i - 1] = new MaexleWurf(i, i); + for (int i = 0; i < 6; i++) { + paschFaelle[i] = new MaexleWurf(Wuerfel.values()[i], Wuerfel.values()[i]); } - maexchenFaelle[0] = new MaexleWurf(1, 2); - maexchenFaelle[1] = new MaexleWurf(2, 1); + maexchenFaelle[0] = new MaexleWurf(EINS, ZWEI); + maexchenFaelle[1] = new MaexleWurf(ZWEI, EINS); } /** * toString() */ @Test @Marking(points = 2) public void test_80() { - Assert.assertEquals("(3|1)", new MaexleWurf(1, 3).toString()); - Assert.assertEquals("(3|1)", new MaexleWurf(3, 1).toString()); + Assert.assertEquals("(DREI|EINS)", new MaexleWurf(EINS, DREI).toString()); + Assert.assertEquals("(DREI|EINS)", new MaexleWurf(DREI, EINS).toString()); } /** @@ -65,9 +65,12 @@ public class Test_MaexchenVergleich extends ExaminationTestDefaults { Assert.assertEquals("i = " + i, 0, nichtSonderFaelle1[i].compareTo(nichtSonderFaelle2[i])); Assert.assertEquals("i = " + i, 0, nichtSonderFaelle2[i].compareTo(nichtSonderFaelle1[i])); - Assert.assertTrue("i = " + i, 0 < nichtSonderFaelle1[i].compareTo(new MaexleWurf(i , i))); - Assert.assertTrue("i = " + i, 0 < nichtSonderFaelle1[i].compareTo(new MaexleWurf(1 , 2))); - Assert.assertTrue("i = " + i, 0 < nichtSonderFaelle1[i].compareTo(new MaexleWurf(2 , 1))); + Assert.assertTrue("i = " + i, 0 < nichtSonderFaelle1[i].compareTo( + new MaexleWurf(EINS, EINS))); + Assert.assertTrue("i = " + i, 0 < nichtSonderFaelle1[i].compareTo( + new MaexleWurf(EINS, ZWEI))); + Assert.assertTrue("i = " + i, 0 < nichtSonderFaelle1[i].compareTo( + new MaexleWurf(ZWEI, EINS))); } } @@ -86,10 +89,10 @@ public class Test_MaexchenVergleich extends ExaminationTestDefaults { * Gleichheit Mäxchen */ @Test @Marking(points = 2) public void test_140() { - Assert.assertEquals(0, new MaexleWurf(1, 2).compareTo(new MaexleWurf(1, 2))); - Assert.assertEquals(0, new MaexleWurf(1, 2).compareTo(new MaexleWurf(2, 1))); - Assert.assertEquals(0, new MaexleWurf(2, 1).compareTo(new MaexleWurf(1, 2))); - Assert.assertEquals(0, new MaexleWurf(2, 1).compareTo(new MaexleWurf(2, 1))); + Assert.assertEquals(0, new MaexleWurf(EINS, ZWEI).compareTo(new MaexleWurf(EINS, ZWEI))); + Assert.assertEquals(0, new MaexleWurf(EINS, ZWEI).compareTo(new MaexleWurf(ZWEI, EINS))); + Assert.assertEquals(0, new MaexleWurf(ZWEI, EINS).compareTo(new MaexleWurf(EINS, ZWEI))); + Assert.assertEquals(0, new MaexleWurf(ZWEI, EINS).compareTo(new MaexleWurf(ZWEI, EINS))); } /** diff --git a/Klausuren/Sd1/2018winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe2/Geo.java b/Klausuren/Sd1/2018winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe2/Geo.java index 5e06f3132..0129edafe 100644 --- a/Klausuren/Sd1/2018winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe2/Geo.java +++ b/Klausuren/Sd1/2018winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe2/Geo.java @@ -31,7 +31,7 @@ package de.hdm_stuttgart.mi.sd1.aufgabe2; * * <p>Instanzen von {@link Geo} können aus beiden Darstellungen erzeugt werden:</p> * - * <pre>final Geo stuttgartBreite1 = new Geo(<b style="color: red;">48°</b>, <b style="color: green;">46′</b>,<b style="color: blue;">56″</b>), // Grad, Minuten, Sekunden + * <pre>final Geo stuttgartBreite1 = new Geo(<b style="color: red;">48</b>, <b style="color: green;">46</b>,<b style="color: blue;">56</b>), // Grad, Minuten, Sekunden * stuttgartBreite2 = new Geo(48.782222); // Dezimalangabe: Identische Breite bis auf Rundungsfehler</pre> * * <section class="implementationHints"> diff --git a/Klausuren/Sd1/2018winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe2/Geo.java b/Klausuren/Sd1/2018winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe2/Geo.java index 6a7c71b4f..224010bc6 100644 --- a/Klausuren/Sd1/2018winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe2/Geo.java +++ b/Klausuren/Sd1/2018winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/aufgabe2/Geo.java @@ -33,7 +33,7 @@ import java.text.DecimalFormat; * * <p>Instanzen von {@link Geo} können aus beiden Darstellungen erzeugt werden:</p> * - * <pre>final Geo stuttgartBreite1 = new Geo(<b style="color: red;">48°</b>, <b style="color: green;">46′</b>,<b style="color: blue;">56″</b>), // Grad, Minuten, Sekunden + * <pre>final Geo stuttgartBreite1 = new Geo(<b style="color: red;">48</b>, <b style="color: green;">46</b>,<b style="color: blue;">56</b>), // Grad, Minuten, Sekunden * stuttgartBreite2 = new Geo(48.782222); // Dezimalangabe: Identische Breite bis auf Rundungsfehler</pre> * * <p>Jede Instanz von {@link Geo} stellt beide Darstellungen bereit:</p> diff --git a/Klausuren/Sd1/2020winter/First/Exam/pom.xml b/Klausuren/Sd1/2020winter/First/Exam/pom.xml new file mode 100644 index 000000000..d1f56cdf2 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Exam/pom.xml @@ -0,0 +1,119 @@ +<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>sd1_2020winter_exam</artifactId> + <version>0.9</version> + <packaging>jar</packaging> + + <name>sd1_2020winter_exam</name> + + <url>https://freedocs.mi.hdm-stuttgart.de/sd1_sect_mavenCli.html</url> + + <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/nexus/repository/mi-maven</url> + </repository> + </repositories> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.13</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <version>2.13.3</version> + </dependency> + + <dependency> + <groupId>de.hdm_stuttgart.mi.exam</groupId> + <artifactId>unitmarking</artifactId> + <version>1.1</version> + </dependency> + + </dependencies> + + <build> + <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.1</version> + <configuration> + <source>11</source> + <target>11</target> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>3.2.0</version> + <configuration> + <doclint>none</doclint> + <javaApiLinks> + <property> + <name>api_11</name> + <value>https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-15-doc/api/</value> + </property> + </javaApiLinks> + + <additionalOptions> + <additionalOption>-html5 --allow-script-in-comments</additionalOption> + </additionalOptions> + <nohelp>true</nohelp> + <header><![CDATA[ + <script type="text/javascript" + src="https://freedocs.mi.hdm-stuttgart.de/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> + <script type="text/javascript" + src="https://freedocs.mi.hdm-stuttgart.de/lib/mi/jdocSupplement.js"></script> + <link rel="stylesheet" href="https://freedocs.mi.hdm-stuttgart.de/lib/mi/jdocSupplement.css"> + <link rel="stylesheet" href="https://freedocs.mi.hdm-stuttgart.de/lib/highlight.js/styles/idea.css"> + <script src="https://freedocs.mi.hdm-stuttgart.de/lib/highlight.js/highlight.js"></script> + <script type="text/javascript">hljs.initHighlightingOnLoad();</script>]]> + </header> + <javadocExecutable>${java.home}/bin/javadoc</javadocExecutable> + </configuration> + </plugin> + + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <version>3.3.0</version> + + <configuration> + <descriptors> + <descriptor>src/main/assembly/assembly.xml</descriptor> + </descriptors> + </configuration> + <executions> + <execution> + <id>make-assembly</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + <configuration> + <archive> + <manifest> + <mainClass>de.hdm_stuttgart.mi.sd1.test.ShowReachedPoints</mainClass> + </manifest> + </archive> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/Klausuren/Sd1/2020winter/First/Exam/src/main/assembly/assembly.xml b/Klausuren/Sd1/2020winter/First/Exam/src/main/assembly/assembly.xml new file mode 100644 index 000000000..85268e296 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Exam/src/main/assembly/assembly.xml @@ -0,0 +1,36 @@ +<assembly + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> + <id>fat-tests</id> + <formats> + <format>jar</format> + </formats> + <includeBaseDirectory>false</includeBaseDirectory> + <dependencySets> + <dependencySet> + <outputDirectory/> + <useProjectArtifact>true</useProjectArtifact> + <unpack>true</unpack> + <scope>test</scope> + </dependencySet> + </dependencySets> + <fileSets> + <fileSet> + <directory>${project.build.directory}/test-classes</directory> + <outputDirectory/> + <includes> + <include>**/*.class</include> + </includes> + <useDefaultExcludes>true</useDefaultExcludes> + </fileSet> + <fileSet> + <directory>${project.build.directory}/classes</directory> + <outputDirectory/> + <includes> + <include>**/*.class</include> + </includes> + <useDefaultExcludes>true</useDefaultExcludes> + </fileSet> + </fileSets> +</assembly> \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_1_Triangle.java b/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_1_Triangle.java new file mode 100644 index 000000000..99b6e8625 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_1_Triangle.java @@ -0,0 +1,26 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +public class _1_Triangle { + + static private final int triangleAngleSum = 180; + + /** + * <p>Compute a triangle's third angle.</p> + * + * <p>A triangle's sum of all angles is 180°:</p> + * + * <object data="doc-files/triangle.svg" type="image/svg+xml"></object> + * + * <p>Thus knowing the values of two angles \( \alpha \) and \( \beta \) allows for calculating the third one.</p> + * + * @param alpha The first of a triangles three angle values. + * @param beta the second of a triangle's three angle values. + * @return The remaining third angle's value. + */ + + static public int getThirdAngle(final int alpha, final int beta) { + return -42;// TODO: Implement me correctly + } + private _1_Triangle(){/* Ignore me: Suppressing default constructor javadoc generation: + javadoc does not include private constructors by default */} +} diff --git a/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_2_DigitExpressions.java b/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_2_DigitExpressions.java new file mode 100644 index 000000000..99f085a1f --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_2_DigitExpressions.java @@ -0,0 +1,66 @@ +package de.hdm_stuttgart.mi.sd1.task1; + + +/** + * <p>Computing results from a single digit value.</p> + */ +public class _2_DigitExpressions { + /** + * <p>Computing an expression from a single digit value.</p> + * + * <p>A single digit value <code>d</code> may be 0, 1, 2, 3, 4, 5, 6, 7, 8 or 9. Starting from an arbitrary digit + * value \( d \) this method computes \(d + d^2 + d^3 \). Example:</p> + * + * <p>A digit value of 3 will return \(3 + 3 \cdot 3 + 3 \cdot 3 \cdot 3 = 39 \).</p> + * + * @param digit A single digit value ranging from 0 to 9. + * @return \( \texttt{digit} + \texttt{digit}^2 + \texttt{digit}^3 \). + */ + static public int getValueThreeDigits(final byte digit) { + return -333; // TODO: Implement me correctly + } + + /** + * <p>Computing an expression from a single digit up to an imposed limit.</p> + * + * <p>This method is a generalization of {@link #getValueThreeDigits(byte)}. Instead of imposing a fixed limit + * for of 3 the highest product's exponent is being provided by an extra argument. Examples:</p> + * + * <table class="goikTableDefaults"> + * <tbody> + * <tr> + * <th>digit</th> + * <th style="max-width: 5em;">Highest exponent</th> + * <th>Result</th> + * </tr> + * <tr> + * <td>5</td> + * <td style="color:red;">2</td> + * <td>\( 5 + 5^\color{red}{2} = 5 + 25 = 30 \)</td> + * </tr> + * <tr> + * <td>2</td> + * <td style="color:red;">4</td> + * <td> \( 2 + 2^2 + 2^3 + 2^\color{red}{4} = 2 + 4 + 8 + 16 = 30 \)</td> + * </tr> + * + * </tbody> + * + * </table> + * + * <section class="implementationHints"> + * <h3 class="implementationHints">Implementation hints:</h3> + * <p>Be careful with respect to arithmetic overflow errors.</p> + * </section> + * + * @param digit A single digit value ranging from 0 to 9. + * @param highestExponent The highest power to be present. Must be greater than 0. + * @return \( \texttt{digit} + \texttt{digit}^2 + \cdots + \texttt{digit}^{\texttt{maxLength}} \) + */ + static public long getValue(final byte digit, final byte highestExponent) { + return 42; // TODO: Implement me correctly + } + + private _2_DigitExpressions(){/* Ignore me: Suppressing default constructor javadoc generation: + javadoc does not include private constructors by default */} +} diff --git a/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_3_Range.java b/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_3_Range.java new file mode 100644 index 000000000..b351b150f --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_3_Range.java @@ -0,0 +1,112 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +import java.util.Arrays; + +public class _3_Range { + + /** + * + * <p>Turn a range defined by start and end value into a sorted array of values.</p> + * + * <p>A range of unique ascending values is being defined by a lower and upper inclusive limit. Examples:</p> + * + * <table class="goikTableDefaults"> + * <tbody> + * <tr> + * <th>[rangeStartInclusive, rangeEndInclusive]</th> + * <th>Result array</th> + * <th>Remark</th> + * </tr> + * <tr> + * <td>[2, 7]</td> + * <td>{2, 3, 4, 5, 6, 7}</td> + * <td>All values in between 2 and 7</td> + * </tr> + * <tr> + * <td>[-5, -5]</td> + * <td>{-5}</td> + * <td>Just the single value -5</td> + * </tr> + * <tr> + * <td>[2, 1]</td> + * <td>{}</td> + * <td>Range end definition <code>1</code> is smaller than range start <code>2</code> ⇒ empty result.</td> + * </tr> + * + * </tbody> + * + * </table> + * + * @param rangeStartInclusive Start of range (inclusive). + * @param rangeEndInclusive End of range (inclusive). + * @return All values within <code>[rangeStartInclusive, rangeEndInclusive]</code>. If + * <code>rangeEndInclusive < rangeStartInclusive</code> the resulting array is empty. + */ + static public int[] createRange(final int rangeStartInclusive, final int rangeEndInclusive) { + return null; // TODO: Implement me correctly + } + + /** + * <p>An array by range definition restricted by an array of values to be excluded.</p> + * + * <p>This method generalizes {@link #createRange(int, int)} by excluding values being present + * in an array. Examples:</p> + * + * <table class="goikTableDefaults"> + * <tbody> + * <tr> + * <th>[rangeStartInclusive, rangeEndInclusive]</th> + * <th>Excluded Values</th> + * <th>Result array</th> + * <th>Explanation</th> + * </tr> + * <tr> + * <td>[2, 7]</td> + * <td>{1, 4, 6}</td> + * <td>{2, 3, 5, 7}</td> + * <td>\( \{2, 3, \color{red}{4}, 5, \color{red}{6}, 7\} \) by range excluding + * \( \{\color{red}{1}, \color{red}{4}, \color{red}{6}\} \Longrightarrow \{2, 3, 5, 7\}\) </td> + * </tr> + * <tr> + * <td>[-1, 3]</td> + * <td>{-1, 1, 2, 3}</td> + * <td>{0}</td> + * <td>\( \{\color{red}{-1}, 0, \color{red}{1}, \color{red}{2}, \color{red}{3}\} \) by range excluding + * \( \{\color{red}{-1}, \color{red}{1}, \color{red}{2}, \color{red}{3} \} \) + * \(\Longrightarrow \{0\}\) </td> + * </tr> + * <tr> + * <td>[1, 3]</td> + * <td>\( \{2, 1, 3, 4 \} \)</td> + * <td>{}</td> + * <td>\( \{\color{red}{1}, \color{red}{2}, \color{red}{3}\} \) by range excluding + * \( \{ \color{red}{2}, \color{red}{1}, \color{red}{3}, \color{red}{4} \} \) + * \(\Longrightarrow \{\}\) </td> + * </tr> + * + * </tbody> + * + * </table> + * + * <p/> + * + * <section class="implementationHints"> + * <h3 class="implementationHints">Implementation hints:</h3> + * <p>The class {@link Arrays} offers assistance i.e. for copying arrays.</p> + * </ol> + * </section> + * + * @param rangeStartInclusive Values greater than or equal + * @param rangeEndInclusive Start of range (inclusive). + * @param excludedValues End of range (inclusive). + * @return All values within <code>[rangeStartInclusive, rangeEndInclusive]</code> <em>not</em> being + * present in the <code>excludedValues</code> array. + */ + static public int[] + createRangeWithExclusions(final int rangeStartInclusive, final int rangeEndInclusive, final int[] excludedValues) { + return null; // TODO: Implement me correctly + } + + private _3_Range(){/* Ignore me: Suppressing default constructor javadoc generation: + javadoc does not include private constructors by default */} +} diff --git a/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_4_Armstrong.java b/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_4_Armstrong.java new file mode 100644 index 000000000..2e441f769 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_4_Armstrong.java @@ -0,0 +1,57 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +/** + * <p>Checking for Armstrong numbers.</p> + */ +public class _4_Armstrong { + + /** + * <p>Check arbitrary integer values for being Armstrong numbers.</p> + * + * <p>An Armstrong number is every integer being equal to the sum of its own digits each raised to the + * power of the number digits.</p> + * + * <p>Examples: + * <ul> + * <li>153 having 3 digits is an Armstrong number since \(153 = 1^3 + 5^3 + 3^3 \).</li> + * + * <li>Likewise 1634 having 4 digits is an Armstrong number as well: \(1634 = 1^4 + 6^4 + 3^4 + 4^4\). + * </li> + * + * <li>On contrary »most« integer values i.e. 23 are no Armstrong numbers since e.g. \(23 \ne 2^2 + 3^2 \). + * </li> + * </ul> + * + * </p> + * + * @param armstrongCandidate This value is to be examined whether or not it is an Armstrong number. + * @return <code>true</code> if the value is an Armstrong number, <code>false</code> otherwise. + * + * <section class="implementationHints"> + * <h3 class="implementationHints">Implementation hints:</h3> + * <ol> + * <li> + * <p>Turn a given integer into a string e.g. 153 --> <code>"153"</code>. The + * {@link Integer} class offers a suitable method.</p> + * </li> + * + * <li> + * <p>Turn the string into an array of <code>char</code> e.g. "153" --> {'1', '5', '3'}. The + * {@link String} class offers a suitable method.</p> + * </li> + * + * <li> + * <p>For each <code>char</code> access its »digit value« by subtracting <code>'0'</code>: For example + * the expression <code>'5' - '0'</code> amounts to 5 of type <code>int</code>.</p> + * </li> + * </ol> + * </section> + * + */ + public static boolean isArmstrongNumber(final int armstrongCandidate) { + return true; // TODO: Implement me correctly + } + + private _4_Armstrong(){/* Ignore me: Suppressing default constructor javadoc generation: + javadoc does not include private constructors by default */} +} diff --git a/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java b/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java new file mode 100644 index 000000000..93c08f78c --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java @@ -0,0 +1,16 @@ +/** + * This package mostly (if not completely) contains static method skeletons. + * + * <p>The ordering being implied by class names reflects the author's opinion with respect to ascending implementation + * difficulty. Hints:</p> + * + * <ul> + * <li>Run <code>mvn javadoc:javadoc</code> and open the generated index.html in your browser of choice.</li> + * + * <li>Use the corresponding unit tests to check your implementation's consistency and class + * <code>de.hdm_stuttgart.mi.sd1.test.ShowReachedPoints</code> from your project's “unit test†branch.</li> + * + * </ul> + * + */ +package de.hdm_stuttgart.mi.sd1.task1; \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/_5_DayConverter.java b/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/_5_DayConverter.java new file mode 100644 index 000000000..f69c656a6 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/_5_DayConverter.java @@ -0,0 +1,51 @@ +package de.hdm_stuttgart.mi.sd1.task2; + +/** + * <p>This class converts a given number of days into an immutable object providing years, weeks and days.</p> + * + * <p>The following example decomposes a 380 days period into an equivalent number of years, weeks and days, each to + * its minimum. We assume all years having 365 days ignoring leap years:</p> + * + * <table class="goikTableDefaults"> + * <tbody> + * <tr> + * <th>Code</th> + * <th>Result</th> + * </tr> + * <tr> + * <td> + * <pre><code class="java"> final _5_DayConverter converter = new _5_DayConverter(380); // 380 days + * + * final int + * years = converter.years, + * weeks = converter.weeks, + * days = converter.days; + * + * System.out.println(380 + " days equal " + years + " year, " + weeks + " weeks and " + days + " day");</code></pre> + * </td> + * <td> + * <pre><code class="nohighlight">380 days equal 1 year, 2 weeks and 1 day</code></pre> + * </td> + * </tr> + * </tbody> + * + * </table> + * + * <p>Instances of {@link _5_DayConverter} are immutable. Thus the following assignments are bound to fail + * at compile time:</p> + * + * <pre><code class="java">{@code converter.years = 2; + * converter.weeks = 1; + * converter.days = 5;}</code></pre> + * + * + * <section class="implementationHints"> + * <h3 class="implementationHints">Hint:</h3> + * + * <p>The class is yet unimplemented. The above code snippets provide a clue how to achieve an + * implementation satisfying the corresponding unit tests.</p> + * </section> + */ +public class _5_DayConverter { + // TODO: Implement me! +} diff --git a/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java b/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java new file mode 100644 index 000000000..86d4b8870 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java @@ -0,0 +1,5 @@ +/** + * Years, weeks and days. + * + */ +package de.hdm_stuttgart.mi.sd1.task2; diff --git a/Klausuren/Sd1/2020winter/First/Exam/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/triangle.svg b/Klausuren/Sd1/2020winter/First/Exam/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/triangle.svg new file mode 100644 index 000000000..dfa662afa --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Exam/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/triangle.svg @@ -0,0 +1,286 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="104.40134mm" + height="47.857903mm" + viewBox="0 0 104.40133 47.857902" + version="1.1" + id="svg8" + inkscape:version="1.0.2 (1.0.2+r75+1)" + sodipodi:docname="triangle.svg"> + <defs + id="defs2"> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend" + style="overflow:visible" + inkscape:isstock="true"> + <path + id="path1448" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" + inkscape:connector-curvature="0" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5-9" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0-1" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5-7" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0-0" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5-7-3" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0-0-6" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-6" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-2" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-1" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-8" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-2" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-02" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="1.4" + inkscape:cx="183.86541" + inkscape:cy="380.68734" + inkscape:document-units="mm" + inkscape:current-layer="layer1" + showgrid="true" + inkscape:window-width="3840" + inkscape:window-height="2096" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + inkscape:snap-global="true" + inkscape:snap-nodes="true" + inkscape:snap-intersection-paths="true" + inkscape:snap-smooth-nodes="true" + inkscape:snap-midpoints="true" + inkscape:snap-others="true" + inkscape:snap-grids="true" + inkscape:snap-to-guides="true" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" + showguides="false" + inkscape:snap-bbox="true" + inkscape:document-rotation="0"> + <inkscape:grid + type="xygrid" + id="grid10" + units="mm" + spacingx="4.5" + spacingy="4.5" + originx="203.267" + originy="31.923428" /> + </sodipodi:namedview> + <metadata + id="metadata5"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(203.26702,-136.79119)"> + <path + style="fill:none;stroke:#000000;stroke-width:0.705556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="M -202.5,168.71462 H -99 l -76.5,-31.5 z" + id="path408" + sodipodi:nodetypes="cccc" /> + <text + xml:space="preserve" + style="font-size:8.46667px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;stroke-width:0.264583" + x="-197.97824" + y="167.73402" + id="text416"><tspan + sodipodi:role="line" + id="tspan414" + x="-197.97824" + y="167.73402" + style="stroke-width:0.264583">α</tspan></text> + <text + xml:space="preserve" + style="font-size:8.46667px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;stroke-width:0.264583" + x="-177.23431" + y="146.83549" + id="text420"><tspan + sodipodi:role="line" + id="tspan418" + x="-177.23431" + y="146.83549" + style="stroke-width:0.264583">β</tspan></text> + <text + xml:space="preserve" + style="font-size:8.46667px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;stroke-width:0.264583" + x="-124.44968" + y="165.90762" + id="text424"><tspan + sodipodi:role="line" + id="tspan422" + x="-124.44968" + y="165.90762" + style="stroke-width:0.264583">γ</tspan></text> + <path + style="opacity:0.962634;fill:none;stroke:#000000;stroke-width:0.706001;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path1307" + sodipodi:type="arc" + sodipodi:cx="-202.5" + sodipodi:cy="168.71461" + sodipodi:rx="11.25" + sodipodi:ry="13.499999" + sodipodi:start="5.5104313" + sodipodi:end="6.2831164" + sodipodi:arc-type="slice" + d="m -194.4451,159.29013 a 11.25,13.499999 0 0 1 3.1951,9.42355 l -11.25,9.3e-4 z" /> + <path + style="opacity:0.962634;fill:none;stroke:#000000;stroke-width:0.706001;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path1307-3" + sodipodi:type="arc" + sodipodi:cx="-175.5" + sodipodi:cy="137.21461" + sodipodi:rx="11.25" + sodipodi:ry="13.5" + sodipodi:start="0.32840358" + sodipodi:end="2.3676625" + sodipodi:arc-type="slice" + d="m -164.85122,141.5688 a 11.25,13.5 0 0 1 -8.16337,8.81224 11.25,13.5 0 0 1 -10.53106,-3.73058 l 8.04565,-9.43585 z" /> + <path + style="opacity:0.962634;fill:none;stroke:#000000;stroke-width:0.706001;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path1307-6" + sodipodi:type="arc" + sodipodi:cx="-114.75004" + sodipodi:cy="168.77052" + sodipodi:rx="11.25" + sodipodi:ry="22.533491" + sodipodi:start="3.1440738" + sodipodi:end="3.6251659" + sodipodi:arc-type="arc" + d="m -126,168.71461 a 11.25,22.533491 0 0 1 1.2899,-10.42094" + sodipodi:open="true" /> + <text + xml:space="preserve" + style="font-size:8.46667px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;stroke-width:0.264583" + x="-194.36299" + y="182.88795" + id="text416-7"><tspan + sodipodi:role="line" + id="tspan414-5" + x="-194.36299" + y="182.88795" + style="stroke-width:0.264583">α + β+ γ = 180° </tspan></text> + </g> +</svg> diff --git a/Klausuren/Sd1/2020winter/First/Exam/src/main/resources/log4j2.xml b/Klausuren/Sd1/2020winter/First/Exam/src/main/resources/log4j2.xml new file mode 100644 index 000000000..130f87a14 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Exam/src/main/resources/log4j2.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Configuration> + <Appenders> + <File name="A1" fileName="A1.log" append="false"> + <PatternLayout pattern="%t %-5p %c{2} - %m%n"/> + </File> + <Console name="STDOUT" target="SYSTEM_OUT"> + <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/> + </Console> + </Appenders> + <Loggers> + + <!-- You my want to define class or package level per-logger rules --> + <Logger name="de.hdm_stuttgart.mi.sd1.App" level="debug"> + <AppenderRef ref="A1"/> + </Logger> + <Root level="info"> + <AppenderRef ref="STDOUT"/> + </Root> + </Loggers> +</Configuration> \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/ShowReachedPoints.java b/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/ShowReachedPoints.java new file mode 100644 index 000000000..119e2b4d3 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/ShowReachedPoints.java @@ -0,0 +1,25 @@ +package de.hdm_stuttgart.mi.sd1.test; + +import de.hdm_stuttgart.mi.exam.unitmarking.RunTests; +import de.hdm_stuttgart.mi.sd1.test.task1.*; +import de.hdm_stuttgart.mi.sd1.test.task2.Test_5_DayConverter; + +public class ShowReachedPoints { + + /** + * Revealing total number of reached points fromm all tasks. + * + * @param args Unused + */ + public static void main(String[] args) { + RunTests.exec( + "Task 1" + , Test_1_Triangle.class + , Test_2_DigitExpressions.class + , Test_3_Range.class + , Test_4_Armstrong.class + ); + + RunTests.exec("Task 2", Test_5_DayConverter.class); + } +} \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/ignore_me/ObjectWrapper.java b/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/ignore_me/ObjectWrapper.java new file mode 100644 index 000000000..3ea40e6af --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/ignore_me/ObjectWrapper.java @@ -0,0 +1,169 @@ +package de.hdm_stuttgart.mi.sd1.test.ignore_me; + +import org.junit.Assert; + +import java.lang.reflect.*; +import java.util.Arrays; +import java.util.stream.Collectors; + +public class ObjectWrapper<T> { + + private final Class classz; + private final T instance; + + static public void assertFinal(final Class classZ, final String fieldName) { + try { + final int modifier = classZ.getDeclaredField(fieldName).getModifiers(); + Assert.assertTrue("»" + fieldName + "« can be modified, no immutable!", Modifier.isFinal(modifier)); + + } catch (NoSuchFieldException e) { + Assert.fail("No such field »" + fieldName + "«"); + } + } + + public ObjectWrapper(final Class<T> classz, final Object ... parameter) { + this.classz = classz; + T tmpInstance = null; + final Constructor<?>[] candidates = Arrays. + stream(classz.getConstructors()). + filter(c -> matchesArgumentList(c, parameter)). + toArray(Constructor<?>[]::new); + if (0 == candidates.length) { + Assert.fail("No suitable constructor in class »" + classz.getName() + "« matching arguments »(" + + Arrays.stream(parameter).map(Object::toString).collect(Collectors.joining(", ")) + + ")«"); + } else if (1 < candidates.length) { + Assert.fail("Multiple constructor matches due to ambiguous signature"); + } else { + try { + tmpInstance = (T) candidates[0].newInstance( + Arrays.stream(parameter).toArray()); + } catch (Exception e) { + Assert.fail("Unable to instantiate instance of class »" + classz.getName() + "«: "+ e); + } + } + instance = tmpInstance; + } + + public <R> void assertFieldExists(final Class<R> valueType, final String name) { + try { + final Field field = classz.getField(name); + if (!valueType.equals(field.getType())) { + Assert.fail("Field »" + name + "« in class »" + classz.getName() + "« is not of type »" + + valueType.getName() + "«"); + } + } catch (final NoSuchFieldException e) { + Assert.fail("No such field »" + name + "« in class »" + classz.getName() + "«"); + } + } + + public <R> R get(final Class<R> valueType, final String name) { + + try { + final Field field = classz.getField(name); + if (valueType.equals(field.getType())) { + return (R) field.get(instance); + } else { + Assert.fail("Field »" + name + "« in class »" + classz.getName() + "« is not of type »" + + valueType.getName() + "«"); + } + } catch (final NoSuchFieldException e) { + Assert.fail("No such field »" + name + "« in class »" + classz.getName() + "«"); + } catch (final IllegalAccessException e) { + Assert.fail("Unable to access field »" + name + "« in class »" + classz.getName() + "«: " + e.getMessage()); + } + return null; + } + public void set(final String name, final Object value) { + + try { + final Field field = classz.getField(name); + final Class argumentType = value.getClass(); + if (field.getType().equals(argumentType) || + field.getType().equals(getPrimitiveType(argumentType))){ + field.set(instance, value); + } else { + Assert.fail("Field »" + name + "« in class »" + classz.getName() + "« is not of type »" + + argumentType.getName() + "«"); + } + } catch (final NoSuchFieldException e) { + Assert.fail("No such field »" + name + "« in class »" + classz.getName() + "«"); + } catch (final IllegalAccessException e) { + Assert.fail("Unable to access field »" + name + "« in class »" + classz.getName() + "«: " + e.getMessage()); + } + } + + public <R> R invoke(final Class<R> returnType, final String name, final Object ... parameter) { + + final Method[] candidates = Arrays. + stream(classz.getMethods()). + filter(m-> m.getName().equals(name) && matchesArgumentList(m, parameter)). + toArray(Method[]::new); + + if (0 == candidates.length) { + Assert.fail("No suitable method found"); + } else if (1 < candidates.length) { + Assert.fail("Multiple method matches due to ambigious signature"); + } else { + final Method method = candidates[0]; + if (method.getReturnType().equals(returnType)) { + try { + return (R) method.invoke(instance, parameter); + } catch (final Exception e) { + Assert.fail("Unable to execute method: " + e); + } + } else { + Assert.fail("Method »" + method.getName() + "« does not have return type »" + returnType.getName() + "«"); + } + } + return null; + } + + /** + * Check for a given array of objects matching an {@link Executable}'s argument list. + * + * @param executable + * @param parameter + * @return <code>true</code> if parameters match the {@link Executable}'s argument list, <code>false</code> + * otherwise. + */ + private boolean matchesArgumentList(final Executable executable, final Object ... parameter) { + + if (executable.getParameterCount() != parameter.length) { + return false; + } else { + final Class<?>[] formalArgumentTypes = executable.getParameterTypes(); + for (int i = 0; i < formalArgumentTypes.length; i++) { + final Class parametersClass = parameter[i].getClass(); + + if (!formalArgumentTypes[i].equals(parametersClass) && + !formalArgumentTypes[i].equals(getPrimitiveType(parametersClass))) { + return false; + } + } + } + return true; + } + + static private Class<?> getPrimitiveType (final Class<?> in) { + if (in.equals(Byte.class)) { + return byte.class; + } else if (in.equals(Short.class)) { + return short.class; + } else if (in.equals(Integer.class)) { + return int.class; + } else if (in.equals(Long.class)) { + return long.class; + } else if (in.equals(Float.class)) { + return float.class; + } else if (in.equals(Double.class)) { + return double.class; + } else if (in.equals(Boolean.class)) { + return boolean.class; + } else if (in.equals(Character.class)) { + return char.class; + } else { + return in; // Type is no primitive + } + } +} diff --git a/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_1_Triangle.java b/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_1_Triangle.java new file mode 100644 index 000000000..e00b18dde --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_1_Triangle.java @@ -0,0 +1,23 @@ +package de.hdm_stuttgart.mi.sd1.test.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task1._1_Triangle; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@SuppressWarnings({"UnusedDeclaration"}) +public class Test_1_Triangle extends ExaminationTestDefaults { + + @Test @Marking(points = 10) public void test_100() { + Assert.assertEquals(60, _1_Triangle.getThirdAngle(20, 100)); + Assert.assertEquals(87, _1_Triangle.getThirdAngle(1, 92)); + Assert.assertEquals(178, _1_Triangle.getThirdAngle(1, 1)); + Assert.assertEquals(30, _1_Triangle.getThirdAngle(50, 100)); + Assert.assertEquals(1, _1_Triangle.getThirdAngle(178, 1)); + Assert.assertEquals(28, _1_Triangle.getThirdAngle(2, 150)); + } +} diff --git a/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_2_DigitExpressions.java b/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_2_DigitExpressions.java new file mode 100644 index 000000000..48ce976c0 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_2_DigitExpressions.java @@ -0,0 +1,83 @@ +package de.hdm_stuttgart.mi.sd1.test.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task1._2_DigitExpressions; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@SuppressWarnings({"UnusedDeclaration"}) +public class Test_2_DigitExpressions extends ExaminationTestDefaults { + + @Test @Marking(points = 6) public void test_100() { + Assert.assertEquals(0, _2_DigitExpressions.getValueThreeDigits((byte) 0)); + Assert.assertEquals(3, _2_DigitExpressions.getValueThreeDigits((byte) 1)); + Assert.assertEquals(14, _2_DigitExpressions.getValueThreeDigits((byte) 2)); + Assert.assertEquals(39, _2_DigitExpressions.getValueThreeDigits((byte) 3)); + Assert.assertEquals(84, _2_DigitExpressions.getValueThreeDigits((byte) 4)); + Assert.assertEquals(155, _2_DigitExpressions.getValueThreeDigits((byte) 5)); + Assert.assertEquals(258, _2_DigitExpressions.getValueThreeDigits((byte) 6)); + Assert.assertEquals(399, _2_DigitExpressions.getValueThreeDigits((byte) 7)); + Assert.assertEquals(584, _2_DigitExpressions.getValueThreeDigits((byte) 8)); + Assert.assertEquals(819, _2_DigitExpressions.getValueThreeDigits((byte) 9)); + } + + @Test @Marking(points = 3) public void test_120_1() { + Assert.assertEquals(0, _2_DigitExpressions.getValue((byte) 0, (byte) 1)); + Assert.assertEquals(1, _2_DigitExpressions.getValue((byte) 1, (byte) 1)); + Assert.assertEquals(2, _2_DigitExpressions.getValue((byte) 2, (byte) 1)); + Assert.assertEquals(3, _2_DigitExpressions.getValue((byte) 3, (byte) 1)); + Assert.assertEquals(4, _2_DigitExpressions.getValue((byte) 4, (byte) 1)); + Assert.assertEquals(5, _2_DigitExpressions.getValue((byte) 5, (byte) 1)); + Assert.assertEquals(6, _2_DigitExpressions.getValue((byte) 6, (byte) 1)); + Assert.assertEquals(7, _2_DigitExpressions.getValue((byte) 7, (byte) 1)); + Assert.assertEquals(8, _2_DigitExpressions.getValue((byte) 8, (byte) 1)); + Assert.assertEquals(9, _2_DigitExpressions.getValue((byte) 9, (byte) 1)); + } + @Test @Marking(points = 3) public void test_140_2() { + Assert.assertEquals(0, _2_DigitExpressions.getValue((byte) 0, (byte) 2)); + Assert.assertEquals(2, _2_DigitExpressions.getValue((byte) 1, (byte) 2)); + Assert.assertEquals(6, _2_DigitExpressions.getValue((byte) 2, (byte) 2)); + Assert.assertEquals(12, _2_DigitExpressions.getValue((byte) 3, (byte) 2)); + Assert.assertEquals(20, _2_DigitExpressions.getValue((byte) 4, (byte) 2)); + Assert.assertEquals(30, _2_DigitExpressions.getValue((byte) 5, (byte) 2)); + Assert.assertEquals(42, _2_DigitExpressions.getValue((byte) 6, (byte) 2)); + Assert.assertEquals(56, _2_DigitExpressions.getValue((byte) 7, (byte) 2)); + Assert.assertEquals(72, _2_DigitExpressions.getValue((byte) 8, (byte) 2)); + Assert.assertEquals(90, _2_DigitExpressions.getValue((byte) 9, (byte) 2)); + } + + @Test @Marking(points = 3) public void test_160_4() { + Assert.assertEquals(0, _2_DigitExpressions.getValue((byte) 0, (byte) 4)); + Assert.assertEquals(4, _2_DigitExpressions.getValue((byte) 1, (byte) 4)); + Assert.assertEquals(30, _2_DigitExpressions.getValue((byte) 2, (byte) 4)); + Assert.assertEquals(120, _2_DigitExpressions.getValue((byte) 3, (byte) 4)); + Assert.assertEquals(340, _2_DigitExpressions.getValue((byte) 4, (byte) 4)); + Assert.assertEquals(780, _2_DigitExpressions.getValue((byte) 5, (byte) 4)); + Assert.assertEquals(1554, _2_DigitExpressions.getValue((byte) 6, (byte) 4)); + Assert.assertEquals(2800, _2_DigitExpressions.getValue((byte) 7, (byte) 4)); + Assert.assertEquals(4680, _2_DigitExpressions.getValue((byte) 8, (byte) 4)); + Assert.assertEquals(7380, _2_DigitExpressions.getValue((byte) 9, (byte) 4)); + } + + @Test @Marking(points = 2) public void test_180_long() { + Assert.assertEquals(0, _2_DigitExpressions.getValue((byte) 0, (byte) 11)); + Assert.assertEquals(11, _2_DigitExpressions.getValue((byte) 1, (byte) 11)); + Assert.assertEquals(4094, _2_DigitExpressions.getValue((byte) 2, (byte) 11)); + Assert.assertEquals(265719, _2_DigitExpressions.getValue((byte) 3, (byte) 11)); + Assert.assertEquals(5592404, _2_DigitExpressions.getValue((byte) 4, (byte) 11)); + Assert.assertEquals(61035155, _2_DigitExpressions.getValue((byte) 5, (byte) 11)); + Assert.assertEquals(435356466, _2_DigitExpressions.getValue((byte) 6, (byte) 11)); + Assert.assertEquals(2306881199L, _2_DigitExpressions.getValue((byte) 7, (byte) 11)); + Assert.assertEquals(9817068104L, _2_DigitExpressions.getValue((byte) 8, (byte) 11)); + Assert.assertEquals(35303692059L, _2_DigitExpressions.getValue((byte) 9, (byte) 11)); + } + + @Test @Marking(points = 3) public void test_180Divers() { + Assert.assertEquals(30, _2_DigitExpressions.getValue((byte) 5, (byte) 2)); + Assert.assertEquals(30, _2_DigitExpressions.getValue((byte) 2, (byte) 4)); + } +} diff --git a/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_3_Range.java b/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_3_Range.java new file mode 100644 index 000000000..59bf212c1 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_3_Range.java @@ -0,0 +1,64 @@ +package de.hdm_stuttgart.mi.sd1.test.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task1._3_Range; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class Test_3_Range extends ExaminationTestDefaults { + + @Test @Marking(points = 3) + public void test_100_one() { + Assert.assertArrayEquals(new int[]{-1}, _3_Range.createRange(-1, -1)); + Assert.assertArrayEquals(new int[]{0}, _3_Range.createRange(0, 0)); + } + + @Test @Marking(points = 3) + public void test_120_two() { + Assert.assertArrayEquals(new int[]{5, 6}, _3_Range.createRange(5, 6)); + Assert.assertArrayEquals(new int[]{-20, -19}, _3_Range.createRange(-20, -19)); + } + + @Test @Marking(points = 3) + public void test_140_more() { + Assert.assertArrayEquals(new int[]{1, 2, 3, 4, 5, 6}, _3_Range.createRange(1, 6)); + Assert.assertArrayEquals(new int[]{-10, -9, -8, -7, -6}, _3_Range.createRange(-10, -6)); + } + + @Test @Marking(points = 3) + public void test_160_empty() { + Assert.assertArrayEquals(new int[]{}, _3_Range.createRange(1, 0)); + Assert.assertArrayEquals(new int[]{}, _3_Range.createRange(20, 10)); + Assert.assertArrayEquals(new int[]{}, _3_Range.createRange(-30, -51)); + } + + @Test @Marking(points = 2) + public void test_500_one() { + Assert.assertArrayEquals(new int[]{1}, + _3_Range.createRangeWithExclusions(1, 1, new int[]{3})); + Assert.assertArrayEquals(new int[]{}, + _3_Range.createRangeWithExclusions(1, 1, new int[]{1})); + Assert.assertArrayEquals(new int[]{}, + _3_Range.createRangeWithExclusions(1, 1, new int[]{2, 1, 4})); + } + + @Test + public void test_520_two() { + Assert.assertArrayEquals(new int[]{5, 6}, + _3_Range.createRangeWithExclusions(5, 6, new int[]{4, 3})); + + Assert.assertArrayEquals(new int[]{5}, + _3_Range.createRangeWithExclusions(5, 6, new int[]{4, 6, 3})); + + Assert.assertArrayEquals(new int[]{6}, + _3_Range.createRangeWithExclusions(5, 6, new int[]{4, 3, 5})); + + Assert.assertArrayEquals(new int[]{}, + _3_Range.createRangeWithExclusions(5, 6, new int[]{6, 4, 3, 5})); + + } +} \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_4_Armstrong.java b/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_4_Armstrong.java new file mode 100644 index 000000000..43da1d8ea --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_4_Armstrong.java @@ -0,0 +1,32 @@ +package de.hdm_stuttgart.mi.sd1.test.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task1._4_Armstrong; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import java.util.Arrays; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class Test_4_Armstrong extends ExaminationTestDefaults { + + @Test @Marking(points = 5) + public void test_100() { + final int[] ascendingArmstrongNumbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748, + 92727, 93084, 548834, 1741725, 4210818, 9800817, 9926315, 24678050, 24678051, 88593477, 146511208, + 472335975, 534494836}; + + for (final int a: ascendingArmstrongNumbers) { + Assert.assertTrue(a + " is an Armstrong number", _4_Armstrong.isArmstrongNumber(a)); + } + + for (int i = 10; i < 1_000_000; i++) { + if (Arrays.binarySearch(ascendingArmstrongNumbers, i) < 0) { + Assert.assertFalse(i + " is not an Armstrong number", _4_Armstrong.isArmstrongNumber(i)); + } + } + } +} diff --git a/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task2/Test_5_DayConverter.java b/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task2/Test_5_DayConverter.java new file mode 100644 index 000000000..e062b8474 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task2/Test_5_DayConverter.java @@ -0,0 +1,59 @@ +package de.hdm_stuttgart.mi.sd1.test.task2; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task2._5_DayConverter; + +import de.hdm_stuttgart.mi.sd1.test.ignore_me.ObjectWrapper; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class Test_5_DayConverter extends ExaminationTestDefaults { + + private static void checkYearsWeeksDays(final int overallDayPeriod, + final int yearsExpected, final int weeksExpected, final int daysExpected){ + + final ObjectWrapper<_5_DayConverter> converter = + new ObjectWrapper<>(_5_DayConverter.class, overallDayPeriod); + + Assert.assertEquals(yearsExpected, (int) converter.get(int.class, "years")); + Assert.assertEquals(weeksExpected, (int) converter.get(int.class, "weeks")); + Assert.assertEquals(daysExpected, (int) converter.get(int.class, "days")); + } + + @Test @Marking(points = 5) public void test_080_small() { + checkYearsWeeksDays(6,0, 0, 6); + checkYearsWeeksDays(7,0, 1, 0); + checkYearsWeeksDays(3 * 7 + 5,0, 3, 5); + } + + @Test @Marking(points = 5) public void test_100_fullYears() { + checkYearsWeeksDays(365,1, 0, 0); + checkYearsWeeksDays(2 * 365,2, 0, 0); + checkYearsWeeksDays(7 * 365,7, 0, 0); + checkYearsWeeksDays(11* 365,11, 0, 0); + checkYearsWeeksDays(22* 365,22, 0, 0); + } + + @Test @Marking(points = 5) public void test_120_mixed() { + + checkYearsWeeksDays(365 + 5 * 7 + 3,1, 5, 3); + checkYearsWeeksDays(2 * 365 + 5 * 7 + 1,2, 5, 1); + checkYearsWeeksDays(3 * 365 + 2 * 7 + 2,3, 2, 2); + checkYearsWeeksDays(11 * 365 + 11 * 7 + 6,11, 11, 6); + + } + + @Test @Marking(points = 5) public void test_900_immutable() { + + final ObjectWrapper<_5_DayConverter> converter = + new ObjectWrapper<>(_5_DayConverter.class, 0); + + ObjectWrapper.assertFinal(_5_DayConverter.class, "years"); + ObjectWrapper.assertFinal(_5_DayConverter.class, "weeks"); + ObjectWrapper.assertFinal(_5_DayConverter.class, "days"); + } +} diff --git a/Klausuren/Sd1/2020winter/First/Solve/pom.xml b/Klausuren/Sd1/2020winter/First/Solve/pom.xml new file mode 100644 index 000000000..da0d7a31c --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/pom.xml @@ -0,0 +1,120 @@ +<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>sd1_2020winter_solve</artifactId> + <version>0.9</version> + <packaging>jar</packaging> + + <name>sd1_2020winter_solve</name> + + <url>https://freedocs.mi.hdm-stuttgart.de/sd1_sect_mavenCli.html</url> + + <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/nexus/repository/mi-maven</url> + </repository> + </repositories> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.13</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <version>2.13.3</version> + </dependency> + + <dependency> + <groupId>de.hdm_stuttgart.mi.exam</groupId> + <artifactId>unitmarking</artifactId> + <version>1.1</version> + </dependency> + + </dependencies> + + <build> + <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.1</version> + <configuration> + <source>11</source> + <target>11</target> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>3.2.0</version> + <configuration> + <doclint>none</doclint> + <show>private</show> + <javaApiLinks> + <property> + <name>api_11</name> + <value>https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-15-doc/api/</value> + </property> + </javaApiLinks> + + <additionalOptions> + <additionalOption>-html5 --allow-script-in-comments</additionalOption> + </additionalOptions> + <nohelp>true</nohelp> + <header><![CDATA[ + <script type="text/javascript" + src="https://freedocs.mi.hdm-stuttgart.de/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> + <script type="text/javascript" + src="https://freedocs.mi.hdm-stuttgart.de/lib/mi/jdocSupplement.js"></script> + <link rel="stylesheet" href="https://freedocs.mi.hdm-stuttgart.de/lib/mi/jdocSupplement.css"> + <link rel="stylesheet" href="https://freedocs.mi.hdm-stuttgart.de/lib/highlight.js/styles/idea.css"> + <script src="https://freedocs.mi.hdm-stuttgart.de/lib/highlight.js/highlight.js"></script> + <script type="text/javascript">hljs.initHighlightingOnLoad();</script>]]> + </header> + <javadocExecutable>${java.home}/bin/javadoc</javadocExecutable> + </configuration> + </plugin> + + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <version>3.3.0</version> + + <configuration> + <descriptors> + <descriptor>src/main/assembly/assembly.xml</descriptor> + </descriptors> + </configuration> + <executions> + <execution> + <id>make-assembly</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + <configuration> + <archive> + <manifest> + <mainClass>de.hdm_stuttgart.mi.sd1.test.ShowReachedPoints</mainClass> + </manifest> + </archive> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/Klausuren/Sd1/2020winter/First/Solve/src/main/assembly/assembly.xml b/Klausuren/Sd1/2020winter/First/Solve/src/main/assembly/assembly.xml new file mode 100644 index 000000000..85268e296 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/src/main/assembly/assembly.xml @@ -0,0 +1,36 @@ +<assembly + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> + <id>fat-tests</id> + <formats> + <format>jar</format> + </formats> + <includeBaseDirectory>false</includeBaseDirectory> + <dependencySets> + <dependencySet> + <outputDirectory/> + <useProjectArtifact>true</useProjectArtifact> + <unpack>true</unpack> + <scope>test</scope> + </dependencySet> + </dependencySets> + <fileSets> + <fileSet> + <directory>${project.build.directory}/test-classes</directory> + <outputDirectory/> + <includes> + <include>**/*.class</include> + </includes> + <useDefaultExcludes>true</useDefaultExcludes> + </fileSet> + <fileSet> + <directory>${project.build.directory}/classes</directory> + <outputDirectory/> + <includes> + <include>**/*.class</include> + </includes> + <useDefaultExcludes>true</useDefaultExcludes> + </fileSet> + </fileSets> +</assembly> \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/DayConverterDemo.java b/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/DayConverterDemo.java new file mode 100644 index 000000000..29a0aee4f --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/DayConverterDemo.java @@ -0,0 +1,22 @@ +package de.hdm_stuttgart.mi.sd1.ignore_me; + +import de.hdm_stuttgart.mi.sd1.task2._5_DayConverter; + +public class DayConverterDemo { + + public static void main(String[] args) { + + final _5_DayConverter converter = new _5_DayConverter(380); + + final int + years = converter.years, + weeks = converter.weeks, + days = converter.days; + + System.out.println(380 + " days equal " + years + " year, " + weeks + " weeks and " + days + " day"); + + + } + + +} diff --git a/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/Test.java b/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/Test.java new file mode 100644 index 000000000..02a6c63b6 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/Test.java @@ -0,0 +1,20 @@ +package de.hdm_stuttgart.mi.sd1.ignore_me; + +public class Test { + + public static void main(String[] args) { + + int power = 0; + + int digit = 8; + + long product = digit, sum = 0; + int index = 0; + while (sum < Integer.MAX_VALUE) { + sum += product; + product *= digit; + index++; + } + System.out.println(index); + } +} diff --git a/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_1_Triangle.java b/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_1_Triangle.java new file mode 100644 index 000000000..cab099460 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_1_Triangle.java @@ -0,0 +1,28 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +public class _1_Triangle { + + static private final int triangleAngleSum = 180; + + /** + * <p>Compute a triangle's third angle.</p> + * + * <p>A triangle's sum of all angles is 180°:</p> + * + * <object data="doc-files/triangle.svg" type="image/svg+xml"></object> + * + * <p>Thus knowing the values of two angles \( \alpha \) and \( \beta \) allows for calculating the third one.</p> + * + * @param alpha The first of a triangles three angle values. + * @param beta the second of a triangle's three angle values. + * @return The remaining third angle's value. + */ + + static public int getThirdAngle(final int alpha, final int beta) { + return triangleAngleSum - alpha - beta; + } + + + private _1_Triangle(){/* Ignore me: Suppressing default constructor javadoc generation: + javadoc does not include private constructors by default */} +} diff --git a/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_2_DigitExpressions.java b/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_2_DigitExpressions.java new file mode 100644 index 000000000..101997367 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_2_DigitExpressions.java @@ -0,0 +1,73 @@ +package de.hdm_stuttgart.mi.sd1.task1; + + +/** + * <p>Computing results from a single digit value.</p> + */ +public class _2_DigitExpressions { + /** + * <p>Computing an expression from a single digit value.</p> + * + * <p>A single digit value <code>d</code> may be 0, 1, 2, 3, 4, 5, 6, 7, 8 or 9. Starting from an arbitrary digit + * value \( d \) this method computes \(d + d^2 + d^3 \). Example:</p> + * + * <p>A digit value of 3 will return \(3 + 3 \cdot 3 + 3 \cdot 3 \cdot 3 = 39 \).</p> + * + * @param digit A single digit value ranging from 0 to 9. + * @return \( \texttt{digit} + \texttt{digit}^2 + \texttt{digit}^3 \). + */ + static public int getValueThreeDigits(final byte digit) { + return digit * (1 + digit * (1 + digit)); // Horner's method, https://en.wikipedia.org/wiki/Horner%27s_method + } + + /** + * <p>Computing an expression from a single digit up to an imposed limit.</p> + * + * <p>This method is a generalization of {@link #getValueThreeDigits(byte)}. Instead of imposing a fixed limit + * for of 3 the highest product's exponent is being provided by an extra argument. Examples:</p> + * + * <table class="goikTableDefaults"> + * <tbody> + * <tr> + * <th>digit</th> + * <th style="max-width: 5em;">Highest exponent</th> + * <th>Result</th> + * </tr> + * <tr> + * <td>5</td> + * <td style="color:red;">2</td> + * <td>\( 5 + 5^\color{red}{2} = 5 + 25 = 30 \)</td> + * </tr> + * <tr> + * <td>2</td> + * <td style="color:red;">4</td> + * <td> \( 2 + 2^2 + 2^3 + 2^\color{red}{4} = 2 + 4 + 8 + 16 = 30 \)</td> + * </tr> + * + * </tbody> + * + * </table> + * + * <section class="implementationHints"> + * <h3 class="implementationHints">Implementation hints:</h3> + * <p>Be careful with respect to arithmetic overflow errors.</p> + * </section> + * + * @param digit A single digit value ranging from 0 to 9. + * @param highestExponent The highest power to be present. Must be greater than 0. + * @return \( \texttt{digit} + \texttt{digit}^2 + \cdots + \texttt{digit}^{\texttt{maxLength}} \) + */ + static public long getValue(final byte digit, final byte highestExponent) { + long product = digit; + long result = digit; + + for (int i = 1; i < highestExponent; i++) { + product *= digit; + result += product; + } + return result; + } + + private _2_DigitExpressions(){/* Ignore me: Suppressing default constructor javadoc generation: + javadoc does not include private constructors by default */} +} diff --git a/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_3_Range.java b/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_3_Range.java new file mode 100644 index 000000000..f1c6fcd4c --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_3_Range.java @@ -0,0 +1,148 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +import java.util.Arrays; + +public class _3_Range { + + /** + * + * <p>Turn a range defined by start and end value into a sorted array of values.</p> + * + * <p>A range of unique ascending values is being defined by a lower and upper inclusive limit. Examples:</p> + * + * <table class="goikTableDefaults"> + * <tbody> + * <tr> + * <th>Range</th> + * <th>Array</th> + * <th>Remark</th> + * </tr> + * <tr> + * <td>[2, 7]</td> + * <td>{2, 3, 4, 5, 6, 7}</td> + * <td>All values in between 2 and 7</td> + * </tr> + * <tr> + * <td>[-5, -5]</td> + * <td>{-5}</td> + * <td>Just the single value -5</td> + * </tr> + * <tr> + * <td>[2, 1]</td> + * <td>{}</td> + * <td>Range end definition <code>1</code> is smaller than range start <code>2</code> ⇒ empty result.</td> + * </tr> + * + * </tbody> + * + * </table> + * + * @param rangeStartInclusive Start of range (inclusive). + * @param rangeEndInclusive End of range (inclusive). + * @return All values within <code>[rangeStartInclusive, rangeEndInclusive]</code>. If + * <code>rangeEndInclusive < rangeStartInclusive</code> the result is an empty array. + */ + static public int[] createRange(final int rangeStartInclusive, final int rangeEndInclusive) { + if (rangeStartInclusive <= rangeEndInclusive) { + final int size = rangeEndInclusive - rangeStartInclusive + 1; + final int[] result = new int[size]; + for (int i = 0; i < size; i++) { + result[i] = rangeStartInclusive + i; + } + return result; + } else { + return new int[]{}; + } + } + + /** + * <p>An array by range definition restricted by an array of values to be excluded.</p> + * + * <p>This method generalizes {@link #createRange(int, int)} by excluding values being present + * in an array. Examples:</p> + * + * <table class="goikTableDefaults"> + * <tbody> + * <tr> + * <th>[rangeStartInclusive, rangeEndInclusive]</th> + * <th>Excluded Values</th> + * <th>Result array</th> + * <th>Explanation</th> + * </tr> + * <tr> + * <td>[2, 7]</td> + * <td>{1, 4, 6}</td> + * <td>{2, 3, 5, 7}</td> + * <td>\( \{2, 3, \color{red}{4}, 5, \color{red}{6}, 7\} \) by range excluding + * \( \{\color{red}{1}, \color{red}{4}, \color{red}{6}\} \Longrightarrow \{2, 3, 5, 7\}\) </td> + * </tr> + * <tr> + * <td>[-1, 3]</td> + * <td>{-1, 1, 2, 3}</td> + * <td>{0}</td> + * <td>\( \{\color{red}{-1}, 0, \color{red}{1}, \color{red}{2}, \color{red}{3}\} \) by range excluding + * \( \{\color{red}{-1}, \color{red}{1}, \color{red}{2}, \color{red}{3} \} \) + * \(\Longrightarrow \{0\}\) </td> + * </tr> + * <tr> + * <td>[1, 3]</td> + * <td>\( \{2, 1, 3, 4 \} \)</td> + * <td>{}</td> + * <td>\( \{\color{red}{1}, \color{red}{2}, \color{red}{3}\} \) by range excluding + * \( \{ \color{red}{2}, \color{red}{1}, \color{red}{3}, \color{red}{4} \} \) + * \(\Longrightarrow \{\}\) </td> + * </tr> + * + * </tbody> + * + * </table> + * + * <p/> + * + * <section class="implementationHints"> + * <h3 class="implementationHints">Implementation hints:</h3> + * <p>The class {@link Arrays} offers assistance i.e. for copying arrays.</p> + * </ol> + * </section> + * + * @param rangeStartInclusive Values greater than or equal + * @param rangeEndInclusive Start of range (inclusive). + * @param excludedValues End of range (inclusive). + * @return All values within <code>[rangeStartInclusive, rangeEndInclusive]</code> <em>not</em> being + * present in the <code>excludedValues</code> array. + */ + static public int[] + createRangeWithExclusions(final int rangeStartInclusive, final int rangeEndInclusive, final int[] excludedValues) { + if (rangeStartInclusive <= rangeEndInclusive) { + final int[] tmpResult = new int[rangeEndInclusive - rangeStartInclusive + 1]; + int resultValueCount = 0; + for (int i = rangeStartInclusive; i <= rangeEndInclusive; i++) { + if (!contains(excludedValues, i)) { + tmpResult[resultValueCount++] = i; + } + } + return Arrays.copyOf(tmpResult, resultValueCount); + } else { + return new int[]{}; + } + } + + /** + * Check for presence of a value within an array. + * + * @param list An array of values + * @param value To be checked for being contained within the array in question. + * @return + */ + static private boolean contains(final int[] list, final int value) { + for (final int l: list) { + if (l == value) { + return true; + } + } + return false; + } + + private _3_Range(){/* Ignore me: Suppressing default constructor javadoc generation: + javadoc does not include private constructors by default */} +} diff --git a/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_4_Armstrong.java b/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_4_Armstrong.java new file mode 100644 index 000000000..aac68dfc1 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_4_Armstrong.java @@ -0,0 +1,100 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +/** + * <p>Checking for Armstrong numbers.</p> + */ +public class _4_Armstrong { + + /** + * <p>Check arbitrary integer values for being Armstrong numbers.</p> + * + * <p>An Armstrong number is every integer being equal to the sum of its own digits each raised to the + * power of the number digits.</p> + * + * <p>Examples: + * <ul> + * <li>153 having 3 digits is an Armstrong number since \(153 = 1^3 + 5^3 + 3^3 \).</li> + * + * <li>Likewise 1634 having 4 digits is an Armstrong number as well: \(1634 = 1^4 + 6^4 + 3^4 + 4^4\). + * </li> + * + * <li>On contrary »most« integer values i.e. 23 are no Armstrong numbers since e.g. \(23 \ne 2^2 + 3^2 \). + * </li> + * </ul> + * + * </p> + * + * @param armstrongCandidate This value is to be examined whether or not it is an Armstrong number. + * @return <code>true</code> if the value is an Armstrong number, <code>false</code> otherwise. + * + * <section class="implementationHints"> + * <h3 class="implementationHints">Implementation hints:</h3> + * <ol> + * <li> + * <p>Turn a given integer into a string e.g. 153 --> <code>"153"</code>. The + * {@link Integer} class offers a suitable method.</p> + * </li> + * + * <li> + * <p>Turn the string into an array of <code>char</code> e.g. "153" --> {'1', '5', '3'}. The + * {@link String} class offers a suitable method.</p> + * </li> + * + * <li> + * <p>For each <code>char</code> access its »digit value« by subtracting <code>'0'</code>: For example + * the expression <code>'5' - '0'</code> amounts to 5 of type <code>int</code>.</p> + * </li> + * </ol> + * </section> + * + */ + public static boolean isArmstrongNumber(final int armstrongCandidate) { + final byte[] digits = int2digits(armstrongCandidate); + return armstrongCandidate == digitPowerSum(digits); + } + + /** + * <p>De-composing an integer value into an array of its digits.</p> + * + * <p>Example: <code>int i = 12345</code> will be converted to {1, 2, 3, 4, 5}.</p> + * + * @param value The value to be converted. + * @return The resulting array. + * + */ + static private byte[] int2digits(final int value) { + final char[] digitCharacters = Integer.toString(value).toCharArray(); + final int digitCount = digitCharacters.length; + + final byte[] digits = new byte[digitCount]; + for (int i = 0; i < digitCount; i++) { + digits[i] = (byte) (digitCharacters[i] - '0'); // Safe for {'0', '1', ..., '9'} + } + return digits; + } + + /** + * <p>Calculating an integer array's individual sum of components raised to the power of + * the array's length.</p> + * + * <p>Example: {1, 5, 3} of length \(3\) will be turned into \( 1^3 + 5^3 + 3^3 \).</p> + * + * @param digits A non-null value. + * @return The array's digit power sum. + */ + static private int digitPowerSum(final byte[] digits) { + + int digitPowerSum = 0; + for (final byte digit : digits) { + int digitPower = digit; + for (int i = 1; i < digits.length; i++) { + digitPower *= digit; + } + digitPowerSum += digitPower; + } + return digitPowerSum; + } + + private _4_Armstrong(){/* Ignore me: Suppressing default constructor javadoc generation: + javadoc does not include private constructors by default */} +} diff --git a/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java b/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java new file mode 100644 index 000000000..93c08f78c --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java @@ -0,0 +1,16 @@ +/** + * This package mostly (if not completely) contains static method skeletons. + * + * <p>The ordering being implied by class names reflects the author's opinion with respect to ascending implementation + * difficulty. Hints:</p> + * + * <ul> + * <li>Run <code>mvn javadoc:javadoc</code> and open the generated index.html in your browser of choice.</li> + * + * <li>Use the corresponding unit tests to check your implementation's consistency and class + * <code>de.hdm_stuttgart.mi.sd1.test.ShowReachedPoints</code> from your project's “unit test†branch.</li> + * + * </ul> + * + */ +package de.hdm_stuttgart.mi.sd1.task1; \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/_5_DayConverter.java b/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/_5_DayConverter.java new file mode 100644 index 000000000..dbf26c8b7 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/_5_DayConverter.java @@ -0,0 +1,76 @@ +package de.hdm_stuttgart.mi.sd1.task2; + +/** + * <p>This class converts a given number of days into an immutable object providing years, weeks and days.</p> + * + * <p>The following example decomposes a 380 days period into an equivalent number of years, weeks and days, each to + * its minimum. We assume all years having 365 days ignoring leap years:</p> + * + * <table class="goikTableDefaults"> + * <tbody> + * <tr> + * <th>Code</th> + * <th>Result</th> + * </tr> + * <tr> + * <td> + * <pre><code class="java"> final _5_DayConverter converter = new _5_DayConverter(380); // 380 days + * + * final int + * years = converter.years, + * weeks = converter.weeks, + * days = converter.days; + * + * System.out.println(380 + " days equal " + years + " year, " + weeks + " weeks and " + days + " day");</code></pre> + * </td> + * <td> + * <pre><code class="nohighlight">380 days equal 1 year, 2 weeks and 1 day</code></pre> + * </td> + * </tr> + * </tbody> + * + * </table> + * + * <p>Instances of {@link _5_DayConverter} are immutable. Thus the following assignments are bound to fail + * at compile time:</p> + * + * <pre><code class="java">{@code converter.years = 2; + * converter.weeks = 1; + * converter.days = 5;}</code></pre> + * + * + * <section class="implementationHints"> + * <h3 class="implementationHints">Hint:</h3> + * + * <p>The class is yet unimplemented. The above code snippets provide a clue how to achieve an + * implementation satisfying the corresponding unit tests.</p> + * </section> + */ +public class _5_DayConverter { + + static private final int + DAYS_PER_YEAR = 365, + DAYS_PER_WEEK = 7; + + /** + * A given time periods number of years. + */ + public final int years; + + /** + * A given time periods number of weeks. + */ + public final int weeks; + + /** + * A given time periods number of days. + */ + public final int days; + + public _5_DayConverter(final int days) { + years = days / DAYS_PER_YEAR; + final int remainingDays = days % DAYS_PER_YEAR; + weeks = remainingDays / DAYS_PER_WEEK; + this.days = remainingDays % DAYS_PER_WEEK; + } +} diff --git a/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java b/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java new file mode 100644 index 000000000..86d4b8870 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java @@ -0,0 +1,5 @@ +/** + * Years, weeks and days. + * + */ +package de.hdm_stuttgart.mi.sd1.task2; diff --git a/Klausuren/Sd1/2020winter/First/Solve/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/triangle.svg b/Klausuren/Sd1/2020winter/First/Solve/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/triangle.svg new file mode 100644 index 000000000..dfa662afa --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/triangle.svg @@ -0,0 +1,286 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="104.40134mm" + height="47.857903mm" + viewBox="0 0 104.40133 47.857902" + version="1.1" + id="svg8" + inkscape:version="1.0.2 (1.0.2+r75+1)" + sodipodi:docname="triangle.svg"> + <defs + id="defs2"> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend" + style="overflow:visible" + inkscape:isstock="true"> + <path + id="path1448" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" + inkscape:connector-curvature="0" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5-9" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0-1" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5-7" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0-0" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5-7-3" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0-0-6" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-6" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-2" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-1" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-8" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-2" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-02" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="1.4" + inkscape:cx="183.86541" + inkscape:cy="380.68734" + inkscape:document-units="mm" + inkscape:current-layer="layer1" + showgrid="true" + inkscape:window-width="3840" + inkscape:window-height="2096" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + inkscape:snap-global="true" + inkscape:snap-nodes="true" + inkscape:snap-intersection-paths="true" + inkscape:snap-smooth-nodes="true" + inkscape:snap-midpoints="true" + inkscape:snap-others="true" + inkscape:snap-grids="true" + inkscape:snap-to-guides="true" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" + showguides="false" + inkscape:snap-bbox="true" + inkscape:document-rotation="0"> + <inkscape:grid + type="xygrid" + id="grid10" + units="mm" + spacingx="4.5" + spacingy="4.5" + originx="203.267" + originy="31.923428" /> + </sodipodi:namedview> + <metadata + id="metadata5"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(203.26702,-136.79119)"> + <path + style="fill:none;stroke:#000000;stroke-width:0.705556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="M -202.5,168.71462 H -99 l -76.5,-31.5 z" + id="path408" + sodipodi:nodetypes="cccc" /> + <text + xml:space="preserve" + style="font-size:8.46667px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;stroke-width:0.264583" + x="-197.97824" + y="167.73402" + id="text416"><tspan + sodipodi:role="line" + id="tspan414" + x="-197.97824" + y="167.73402" + style="stroke-width:0.264583">α</tspan></text> + <text + xml:space="preserve" + style="font-size:8.46667px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;stroke-width:0.264583" + x="-177.23431" + y="146.83549" + id="text420"><tspan + sodipodi:role="line" + id="tspan418" + x="-177.23431" + y="146.83549" + style="stroke-width:0.264583">β</tspan></text> + <text + xml:space="preserve" + style="font-size:8.46667px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;stroke-width:0.264583" + x="-124.44968" + y="165.90762" + id="text424"><tspan + sodipodi:role="line" + id="tspan422" + x="-124.44968" + y="165.90762" + style="stroke-width:0.264583">γ</tspan></text> + <path + style="opacity:0.962634;fill:none;stroke:#000000;stroke-width:0.706001;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path1307" + sodipodi:type="arc" + sodipodi:cx="-202.5" + sodipodi:cy="168.71461" + sodipodi:rx="11.25" + sodipodi:ry="13.499999" + sodipodi:start="5.5104313" + sodipodi:end="6.2831164" + sodipodi:arc-type="slice" + d="m -194.4451,159.29013 a 11.25,13.499999 0 0 1 3.1951,9.42355 l -11.25,9.3e-4 z" /> + <path + style="opacity:0.962634;fill:none;stroke:#000000;stroke-width:0.706001;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path1307-3" + sodipodi:type="arc" + sodipodi:cx="-175.5" + sodipodi:cy="137.21461" + sodipodi:rx="11.25" + sodipodi:ry="13.5" + sodipodi:start="0.32840358" + sodipodi:end="2.3676625" + sodipodi:arc-type="slice" + d="m -164.85122,141.5688 a 11.25,13.5 0 0 1 -8.16337,8.81224 11.25,13.5 0 0 1 -10.53106,-3.73058 l 8.04565,-9.43585 z" /> + <path + style="opacity:0.962634;fill:none;stroke:#000000;stroke-width:0.706001;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path1307-6" + sodipodi:type="arc" + sodipodi:cx="-114.75004" + sodipodi:cy="168.77052" + sodipodi:rx="11.25" + sodipodi:ry="22.533491" + sodipodi:start="3.1440738" + sodipodi:end="3.6251659" + sodipodi:arc-type="arc" + d="m -126,168.71461 a 11.25,22.533491 0 0 1 1.2899,-10.42094" + sodipodi:open="true" /> + <text + xml:space="preserve" + style="font-size:8.46667px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;stroke-width:0.264583" + x="-194.36299" + y="182.88795" + id="text416-7"><tspan + sodipodi:role="line" + id="tspan414-5" + x="-194.36299" + y="182.88795" + style="stroke-width:0.264583">α + β+ γ = 180° </tspan></text> + </g> +</svg> diff --git a/Klausuren/Sd1/2020winter/First/Solve/src/main/resources/log4j2.xml b/Klausuren/Sd1/2020winter/First/Solve/src/main/resources/log4j2.xml new file mode 100644 index 000000000..130f87a14 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/src/main/resources/log4j2.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Configuration> + <Appenders> + <File name="A1" fileName="A1.log" append="false"> + <PatternLayout pattern="%t %-5p %c{2} - %m%n"/> + </File> + <Console name="STDOUT" target="SYSTEM_OUT"> + <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/> + </Console> + </Appenders> + <Loggers> + + <!-- You my want to define class or package level per-logger rules --> + <Logger name="de.hdm_stuttgart.mi.sd1.App" level="debug"> + <AppenderRef ref="A1"/> + </Logger> + <Root level="info"> + <AppenderRef ref="STDOUT"/> + </Root> + </Loggers> +</Configuration> \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/ShowReachedPoints.java b/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/ShowReachedPoints.java new file mode 100644 index 000000000..119e2b4d3 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/ShowReachedPoints.java @@ -0,0 +1,25 @@ +package de.hdm_stuttgart.mi.sd1.test; + +import de.hdm_stuttgart.mi.exam.unitmarking.RunTests; +import de.hdm_stuttgart.mi.sd1.test.task1.*; +import de.hdm_stuttgart.mi.sd1.test.task2.Test_5_DayConverter; + +public class ShowReachedPoints { + + /** + * Revealing total number of reached points fromm all tasks. + * + * @param args Unused + */ + public static void main(String[] args) { + RunTests.exec( + "Task 1" + , Test_1_Triangle.class + , Test_2_DigitExpressions.class + , Test_3_Range.class + , Test_4_Armstrong.class + ); + + RunTests.exec("Task 2", Test_5_DayConverter.class); + } +} \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/ignore_me/ObjectWrapper.java b/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/ignore_me/ObjectWrapper.java new file mode 100644 index 000000000..3ea40e6af --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/ignore_me/ObjectWrapper.java @@ -0,0 +1,169 @@ +package de.hdm_stuttgart.mi.sd1.test.ignore_me; + +import org.junit.Assert; + +import java.lang.reflect.*; +import java.util.Arrays; +import java.util.stream.Collectors; + +public class ObjectWrapper<T> { + + private final Class classz; + private final T instance; + + static public void assertFinal(final Class classZ, final String fieldName) { + try { + final int modifier = classZ.getDeclaredField(fieldName).getModifiers(); + Assert.assertTrue("»" + fieldName + "« can be modified, no immutable!", Modifier.isFinal(modifier)); + + } catch (NoSuchFieldException e) { + Assert.fail("No such field »" + fieldName + "«"); + } + } + + public ObjectWrapper(final Class<T> classz, final Object ... parameter) { + this.classz = classz; + T tmpInstance = null; + final Constructor<?>[] candidates = Arrays. + stream(classz.getConstructors()). + filter(c -> matchesArgumentList(c, parameter)). + toArray(Constructor<?>[]::new); + if (0 == candidates.length) { + Assert.fail("No suitable constructor in class »" + classz.getName() + "« matching arguments »(" + + Arrays.stream(parameter).map(Object::toString).collect(Collectors.joining(", ")) + + ")«"); + } else if (1 < candidates.length) { + Assert.fail("Multiple constructor matches due to ambiguous signature"); + } else { + try { + tmpInstance = (T) candidates[0].newInstance( + Arrays.stream(parameter).toArray()); + } catch (Exception e) { + Assert.fail("Unable to instantiate instance of class »" + classz.getName() + "«: "+ e); + } + } + instance = tmpInstance; + } + + public <R> void assertFieldExists(final Class<R> valueType, final String name) { + try { + final Field field = classz.getField(name); + if (!valueType.equals(field.getType())) { + Assert.fail("Field »" + name + "« in class »" + classz.getName() + "« is not of type »" + + valueType.getName() + "«"); + } + } catch (final NoSuchFieldException e) { + Assert.fail("No such field »" + name + "« in class »" + classz.getName() + "«"); + } + } + + public <R> R get(final Class<R> valueType, final String name) { + + try { + final Field field = classz.getField(name); + if (valueType.equals(field.getType())) { + return (R) field.get(instance); + } else { + Assert.fail("Field »" + name + "« in class »" + classz.getName() + "« is not of type »" + + valueType.getName() + "«"); + } + } catch (final NoSuchFieldException e) { + Assert.fail("No such field »" + name + "« in class »" + classz.getName() + "«"); + } catch (final IllegalAccessException e) { + Assert.fail("Unable to access field »" + name + "« in class »" + classz.getName() + "«: " + e.getMessage()); + } + return null; + } + public void set(final String name, final Object value) { + + try { + final Field field = classz.getField(name); + final Class argumentType = value.getClass(); + if (field.getType().equals(argumentType) || + field.getType().equals(getPrimitiveType(argumentType))){ + field.set(instance, value); + } else { + Assert.fail("Field »" + name + "« in class »" + classz.getName() + "« is not of type »" + + argumentType.getName() + "«"); + } + } catch (final NoSuchFieldException e) { + Assert.fail("No such field »" + name + "« in class »" + classz.getName() + "«"); + } catch (final IllegalAccessException e) { + Assert.fail("Unable to access field »" + name + "« in class »" + classz.getName() + "«: " + e.getMessage()); + } + } + + public <R> R invoke(final Class<R> returnType, final String name, final Object ... parameter) { + + final Method[] candidates = Arrays. + stream(classz.getMethods()). + filter(m-> m.getName().equals(name) && matchesArgumentList(m, parameter)). + toArray(Method[]::new); + + if (0 == candidates.length) { + Assert.fail("No suitable method found"); + } else if (1 < candidates.length) { + Assert.fail("Multiple method matches due to ambigious signature"); + } else { + final Method method = candidates[0]; + if (method.getReturnType().equals(returnType)) { + try { + return (R) method.invoke(instance, parameter); + } catch (final Exception e) { + Assert.fail("Unable to execute method: " + e); + } + } else { + Assert.fail("Method »" + method.getName() + "« does not have return type »" + returnType.getName() + "«"); + } + } + return null; + } + + /** + * Check for a given array of objects matching an {@link Executable}'s argument list. + * + * @param executable + * @param parameter + * @return <code>true</code> if parameters match the {@link Executable}'s argument list, <code>false</code> + * otherwise. + */ + private boolean matchesArgumentList(final Executable executable, final Object ... parameter) { + + if (executable.getParameterCount() != parameter.length) { + return false; + } else { + final Class<?>[] formalArgumentTypes = executable.getParameterTypes(); + for (int i = 0; i < formalArgumentTypes.length; i++) { + final Class parametersClass = parameter[i].getClass(); + + if (!formalArgumentTypes[i].equals(parametersClass) && + !formalArgumentTypes[i].equals(getPrimitiveType(parametersClass))) { + return false; + } + } + } + return true; + } + + static private Class<?> getPrimitiveType (final Class<?> in) { + if (in.equals(Byte.class)) { + return byte.class; + } else if (in.equals(Short.class)) { + return short.class; + } else if (in.equals(Integer.class)) { + return int.class; + } else if (in.equals(Long.class)) { + return long.class; + } else if (in.equals(Float.class)) { + return float.class; + } else if (in.equals(Double.class)) { + return double.class; + } else if (in.equals(Boolean.class)) { + return boolean.class; + } else if (in.equals(Character.class)) { + return char.class; + } else { + return in; // Type is no primitive + } + } +} diff --git a/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_1_Triangle.java b/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_1_Triangle.java new file mode 100644 index 000000000..e00b18dde --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_1_Triangle.java @@ -0,0 +1,23 @@ +package de.hdm_stuttgart.mi.sd1.test.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task1._1_Triangle; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@SuppressWarnings({"UnusedDeclaration"}) +public class Test_1_Triangle extends ExaminationTestDefaults { + + @Test @Marking(points = 10) public void test_100() { + Assert.assertEquals(60, _1_Triangle.getThirdAngle(20, 100)); + Assert.assertEquals(87, _1_Triangle.getThirdAngle(1, 92)); + Assert.assertEquals(178, _1_Triangle.getThirdAngle(1, 1)); + Assert.assertEquals(30, _1_Triangle.getThirdAngle(50, 100)); + Assert.assertEquals(1, _1_Triangle.getThirdAngle(178, 1)); + Assert.assertEquals(28, _1_Triangle.getThirdAngle(2, 150)); + } +} diff --git a/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_2_DigitExpressions.java b/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_2_DigitExpressions.java new file mode 100644 index 000000000..48ce976c0 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_2_DigitExpressions.java @@ -0,0 +1,83 @@ +package de.hdm_stuttgart.mi.sd1.test.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task1._2_DigitExpressions; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@SuppressWarnings({"UnusedDeclaration"}) +public class Test_2_DigitExpressions extends ExaminationTestDefaults { + + @Test @Marking(points = 6) public void test_100() { + Assert.assertEquals(0, _2_DigitExpressions.getValueThreeDigits((byte) 0)); + Assert.assertEquals(3, _2_DigitExpressions.getValueThreeDigits((byte) 1)); + Assert.assertEquals(14, _2_DigitExpressions.getValueThreeDigits((byte) 2)); + Assert.assertEquals(39, _2_DigitExpressions.getValueThreeDigits((byte) 3)); + Assert.assertEquals(84, _2_DigitExpressions.getValueThreeDigits((byte) 4)); + Assert.assertEquals(155, _2_DigitExpressions.getValueThreeDigits((byte) 5)); + Assert.assertEquals(258, _2_DigitExpressions.getValueThreeDigits((byte) 6)); + Assert.assertEquals(399, _2_DigitExpressions.getValueThreeDigits((byte) 7)); + Assert.assertEquals(584, _2_DigitExpressions.getValueThreeDigits((byte) 8)); + Assert.assertEquals(819, _2_DigitExpressions.getValueThreeDigits((byte) 9)); + } + + @Test @Marking(points = 3) public void test_120_1() { + Assert.assertEquals(0, _2_DigitExpressions.getValue((byte) 0, (byte) 1)); + Assert.assertEquals(1, _2_DigitExpressions.getValue((byte) 1, (byte) 1)); + Assert.assertEquals(2, _2_DigitExpressions.getValue((byte) 2, (byte) 1)); + Assert.assertEquals(3, _2_DigitExpressions.getValue((byte) 3, (byte) 1)); + Assert.assertEquals(4, _2_DigitExpressions.getValue((byte) 4, (byte) 1)); + Assert.assertEquals(5, _2_DigitExpressions.getValue((byte) 5, (byte) 1)); + Assert.assertEquals(6, _2_DigitExpressions.getValue((byte) 6, (byte) 1)); + Assert.assertEquals(7, _2_DigitExpressions.getValue((byte) 7, (byte) 1)); + Assert.assertEquals(8, _2_DigitExpressions.getValue((byte) 8, (byte) 1)); + Assert.assertEquals(9, _2_DigitExpressions.getValue((byte) 9, (byte) 1)); + } + @Test @Marking(points = 3) public void test_140_2() { + Assert.assertEquals(0, _2_DigitExpressions.getValue((byte) 0, (byte) 2)); + Assert.assertEquals(2, _2_DigitExpressions.getValue((byte) 1, (byte) 2)); + Assert.assertEquals(6, _2_DigitExpressions.getValue((byte) 2, (byte) 2)); + Assert.assertEquals(12, _2_DigitExpressions.getValue((byte) 3, (byte) 2)); + Assert.assertEquals(20, _2_DigitExpressions.getValue((byte) 4, (byte) 2)); + Assert.assertEquals(30, _2_DigitExpressions.getValue((byte) 5, (byte) 2)); + Assert.assertEquals(42, _2_DigitExpressions.getValue((byte) 6, (byte) 2)); + Assert.assertEquals(56, _2_DigitExpressions.getValue((byte) 7, (byte) 2)); + Assert.assertEquals(72, _2_DigitExpressions.getValue((byte) 8, (byte) 2)); + Assert.assertEquals(90, _2_DigitExpressions.getValue((byte) 9, (byte) 2)); + } + + @Test @Marking(points = 3) public void test_160_4() { + Assert.assertEquals(0, _2_DigitExpressions.getValue((byte) 0, (byte) 4)); + Assert.assertEquals(4, _2_DigitExpressions.getValue((byte) 1, (byte) 4)); + Assert.assertEquals(30, _2_DigitExpressions.getValue((byte) 2, (byte) 4)); + Assert.assertEquals(120, _2_DigitExpressions.getValue((byte) 3, (byte) 4)); + Assert.assertEquals(340, _2_DigitExpressions.getValue((byte) 4, (byte) 4)); + Assert.assertEquals(780, _2_DigitExpressions.getValue((byte) 5, (byte) 4)); + Assert.assertEquals(1554, _2_DigitExpressions.getValue((byte) 6, (byte) 4)); + Assert.assertEquals(2800, _2_DigitExpressions.getValue((byte) 7, (byte) 4)); + Assert.assertEquals(4680, _2_DigitExpressions.getValue((byte) 8, (byte) 4)); + Assert.assertEquals(7380, _2_DigitExpressions.getValue((byte) 9, (byte) 4)); + } + + @Test @Marking(points = 2) public void test_180_long() { + Assert.assertEquals(0, _2_DigitExpressions.getValue((byte) 0, (byte) 11)); + Assert.assertEquals(11, _2_DigitExpressions.getValue((byte) 1, (byte) 11)); + Assert.assertEquals(4094, _2_DigitExpressions.getValue((byte) 2, (byte) 11)); + Assert.assertEquals(265719, _2_DigitExpressions.getValue((byte) 3, (byte) 11)); + Assert.assertEquals(5592404, _2_DigitExpressions.getValue((byte) 4, (byte) 11)); + Assert.assertEquals(61035155, _2_DigitExpressions.getValue((byte) 5, (byte) 11)); + Assert.assertEquals(435356466, _2_DigitExpressions.getValue((byte) 6, (byte) 11)); + Assert.assertEquals(2306881199L, _2_DigitExpressions.getValue((byte) 7, (byte) 11)); + Assert.assertEquals(9817068104L, _2_DigitExpressions.getValue((byte) 8, (byte) 11)); + Assert.assertEquals(35303692059L, _2_DigitExpressions.getValue((byte) 9, (byte) 11)); + } + + @Test @Marking(points = 3) public void test_180Divers() { + Assert.assertEquals(30, _2_DigitExpressions.getValue((byte) 5, (byte) 2)); + Assert.assertEquals(30, _2_DigitExpressions.getValue((byte) 2, (byte) 4)); + } +} diff --git a/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_3_Range.java b/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_3_Range.java new file mode 100644 index 000000000..59bf212c1 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_3_Range.java @@ -0,0 +1,64 @@ +package de.hdm_stuttgart.mi.sd1.test.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task1._3_Range; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class Test_3_Range extends ExaminationTestDefaults { + + @Test @Marking(points = 3) + public void test_100_one() { + Assert.assertArrayEquals(new int[]{-1}, _3_Range.createRange(-1, -1)); + Assert.assertArrayEquals(new int[]{0}, _3_Range.createRange(0, 0)); + } + + @Test @Marking(points = 3) + public void test_120_two() { + Assert.assertArrayEquals(new int[]{5, 6}, _3_Range.createRange(5, 6)); + Assert.assertArrayEquals(new int[]{-20, -19}, _3_Range.createRange(-20, -19)); + } + + @Test @Marking(points = 3) + public void test_140_more() { + Assert.assertArrayEquals(new int[]{1, 2, 3, 4, 5, 6}, _3_Range.createRange(1, 6)); + Assert.assertArrayEquals(new int[]{-10, -9, -8, -7, -6}, _3_Range.createRange(-10, -6)); + } + + @Test @Marking(points = 3) + public void test_160_empty() { + Assert.assertArrayEquals(new int[]{}, _3_Range.createRange(1, 0)); + Assert.assertArrayEquals(new int[]{}, _3_Range.createRange(20, 10)); + Assert.assertArrayEquals(new int[]{}, _3_Range.createRange(-30, -51)); + } + + @Test @Marking(points = 2) + public void test_500_one() { + Assert.assertArrayEquals(new int[]{1}, + _3_Range.createRangeWithExclusions(1, 1, new int[]{3})); + Assert.assertArrayEquals(new int[]{}, + _3_Range.createRangeWithExclusions(1, 1, new int[]{1})); + Assert.assertArrayEquals(new int[]{}, + _3_Range.createRangeWithExclusions(1, 1, new int[]{2, 1, 4})); + } + + @Test + public void test_520_two() { + Assert.assertArrayEquals(new int[]{5, 6}, + _3_Range.createRangeWithExclusions(5, 6, new int[]{4, 3})); + + Assert.assertArrayEquals(new int[]{5}, + _3_Range.createRangeWithExclusions(5, 6, new int[]{4, 6, 3})); + + Assert.assertArrayEquals(new int[]{6}, + _3_Range.createRangeWithExclusions(5, 6, new int[]{4, 3, 5})); + + Assert.assertArrayEquals(new int[]{}, + _3_Range.createRangeWithExclusions(5, 6, new int[]{6, 4, 3, 5})); + + } +} \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_4_Armstrong.java b/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_4_Armstrong.java new file mode 100644 index 000000000..43da1d8ea --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_4_Armstrong.java @@ -0,0 +1,32 @@ +package de.hdm_stuttgart.mi.sd1.test.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task1._4_Armstrong; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import java.util.Arrays; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class Test_4_Armstrong extends ExaminationTestDefaults { + + @Test @Marking(points = 5) + public void test_100() { + final int[] ascendingArmstrongNumbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748, + 92727, 93084, 548834, 1741725, 4210818, 9800817, 9926315, 24678050, 24678051, 88593477, 146511208, + 472335975, 534494836}; + + for (final int a: ascendingArmstrongNumbers) { + Assert.assertTrue(a + " is an Armstrong number", _4_Armstrong.isArmstrongNumber(a)); + } + + for (int i = 10; i < 1_000_000; i++) { + if (Arrays.binarySearch(ascendingArmstrongNumbers, i) < 0) { + Assert.assertFalse(i + " is not an Armstrong number", _4_Armstrong.isArmstrongNumber(i)); + } + } + } +} diff --git a/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task2/Test_5_DayConverter.java b/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task2/Test_5_DayConverter.java new file mode 100644 index 000000000..e062b8474 --- /dev/null +++ b/Klausuren/Sd1/2020winter/First/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task2/Test_5_DayConverter.java @@ -0,0 +1,59 @@ +package de.hdm_stuttgart.mi.sd1.test.task2; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task2._5_DayConverter; + +import de.hdm_stuttgart.mi.sd1.test.ignore_me.ObjectWrapper; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class Test_5_DayConverter extends ExaminationTestDefaults { + + private static void checkYearsWeeksDays(final int overallDayPeriod, + final int yearsExpected, final int weeksExpected, final int daysExpected){ + + final ObjectWrapper<_5_DayConverter> converter = + new ObjectWrapper<>(_5_DayConverter.class, overallDayPeriod); + + Assert.assertEquals(yearsExpected, (int) converter.get(int.class, "years")); + Assert.assertEquals(weeksExpected, (int) converter.get(int.class, "weeks")); + Assert.assertEquals(daysExpected, (int) converter.get(int.class, "days")); + } + + @Test @Marking(points = 5) public void test_080_small() { + checkYearsWeeksDays(6,0, 0, 6); + checkYearsWeeksDays(7,0, 1, 0); + checkYearsWeeksDays(3 * 7 + 5,0, 3, 5); + } + + @Test @Marking(points = 5) public void test_100_fullYears() { + checkYearsWeeksDays(365,1, 0, 0); + checkYearsWeeksDays(2 * 365,2, 0, 0); + checkYearsWeeksDays(7 * 365,7, 0, 0); + checkYearsWeeksDays(11* 365,11, 0, 0); + checkYearsWeeksDays(22* 365,22, 0, 0); + } + + @Test @Marking(points = 5) public void test_120_mixed() { + + checkYearsWeeksDays(365 + 5 * 7 + 3,1, 5, 3); + checkYearsWeeksDays(2 * 365 + 5 * 7 + 1,2, 5, 1); + checkYearsWeeksDays(3 * 365 + 2 * 7 + 2,3, 2, 2); + checkYearsWeeksDays(11 * 365 + 11 * 7 + 6,11, 11, 6); + + } + + @Test @Marking(points = 5) public void test_900_immutable() { + + final ObjectWrapper<_5_DayConverter> converter = + new ObjectWrapper<>(_5_DayConverter.class, 0); + + ObjectWrapper.assertFinal(_5_DayConverter.class, "years"); + ObjectWrapper.assertFinal(_5_DayConverter.class, "weeks"); + ObjectWrapper.assertFinal(_5_DayConverter.class, "days"); + } +} -- GitLab