diff --git a/Doc/Sd1/Appendix/Exam/2023/Winter/exam.xml b/Doc/Sd1/Appendix/Exam/2023/Winter/exam.xml new file mode 100644 index 0000000000000000000000000000000000000000..e072eb5e25c6e937b165a15acd90737e26a23480 --- /dev/null +++ b/Doc/Sd1/Appendix/Exam/2023/Winter/exam.xml @@ -0,0 +1,202 @@ +<?xml version="1.0" encoding="UTF-8"?> +<section version="5.0" xml:id="sd1_exam_2023_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 2023</title> + + <section xml:id="sd1_exam_2023_winter_task1"> + <title>Implementing tasks</title> + + <section xml:id="sd1_exam_2023_winter_task1_preparation"> + <title>Preparation</title> + + <orderedlist> + <listitem> + <para>Download and unzip the above file + <filename>exam.zip</filename>. You should see a directory + »<filename>Exam</filename>« containing a + <filename>pom.xml</filename> file.</para> + </listitem> + + <listitem> + <para>Open this project in your <productname>IDEA</productname> IDE + by selecting the <filename>Exam/pom.xml</filename> file. Your home + directory is <filename>/home/student</filename>.</para> + </listitem> + </orderedlist> + </section> + + <section xml:id="sd1_exam_2023_winter_task1_task"> + <title>Task</title> + + <qandaset defaultlabel="qanda" xml:id="sd1_exam_2023_winter_task1Qanda"> + <qandadiv> + <qandaentry> + <question> + <para>Open the <filename>Readme.md</filename> file in your + project's root. It contains all necessary instructions for + solving the implementation tasks.</para> + </question> + + <answer> + <para>Solution see <link + xlink:href="https://gitlab.mi.hdm-stuttgart.de/goik/GoikLectures/-/tree/master/Klausuren/Sd1/2023winter/Solve">winter + 2023 exam</link>.</para> + </answer> + </qandaentry> + </qandadiv> + </qandaset> + </section> + + <section xml:id="sd1_exam_2023_winter_task1Caveats"> + <title>Caveats</title> + + <itemizedlist> + <listitem> + <para>When approaching end of examination check your input for + completeness prior to being automatically logged out by the system. + Remember: There is 120 minutes for the examination and another 5 + minutes to check for completeness.</para> + </listitem> + + <listitem> + <para>Projects residing just on your local workstation's file system + cannot be recovered after finishing the exam.</para> + </listitem> + </itemizedlist> + </section> + </section> + + <section xml:id="sd1_exam_2023_winter_task2"> + <title>Beginner's nightmare</title> + + <qandaset defaultlabel="qanda" xml:id="sd1_exam_2023_winter_task3Qanda"> + <qandadiv> + <qandaentry> + <question> + <para>We consider the following class method + <methodname>sum</methodname>:</para> + + <programlisting language="none">01 /** +02 * Summing up an int array's values +03 * +04 * @param values An array of int values +05 * @return The sum of all array values +06 */ +07 public static int sum(int[] values) { +08 +09 int sum; +10 +11 for (i = 0; i <= values.length; i++) { +12 sum += values[i]; +13 } +14 return sum; +15 }</programlisting> + + <para>This code does contain errors. Explain and correct each of + those. Line numbers are being provided for your convenience</para> + </question> + + <answer> + <para>There are errors:</para> + + <glosslist> + <glossentry> + <glossterm>Line 9</glossterm> + + <glossdef> + <para>The variable <code language="java">sum</code> lacks + initialization <code language="java">int sum = + 0</code>.</para> + </glossdef> + </glossentry> + + <glossentry> + <glossterm>Line 16</glossterm> + + <glossdef> + <para>There are two errors here:</para> + + <itemizedlist> + <listitem> + <para>Variable i has not been declared: <code + language="java">int i = 0; ...</code></para> + </listitem> + + <listitem> + <para>The loop's upper limit is being breached: <code + language="java">i < values.length</code> rather then + <code language="java">i <= values.length</code> is + being required.</para> + </listitem> + </itemizedlist> + </glossdef> + </glossentry> + </glosslist> + </answer> + </qandaentry> + </qandadiv> + </qandaset> + </section> + + <section xml:id="sd1_exam_2023_winter_task3"> + <title>Strange endless loop result</title> + + <qandaset defaultlabel="qanda" xml:id="sd1_exam_2023_winter_task2Qanda"> + <qandadiv> + <qandaentry> + <question> + <para>We consider:</para> + + <programlisting language="java">for (byte b = 0; b <= Byte.MAX_VALUE; b++);</programlisting> + + <para>This snippet causes an endless loop. Give an + explanation.</para> + + <tip> + <para>Consider the ++ operator's behavior when reaching variable + <code>b</code>'s upper limit.</para> + </tip> + </question> + + <answer> + <para>The operator ++ acting on a byte variable will cycle between + <code language="java">Byte.MIN_VALUE</code> and <code + language="java">Byte.MAX_VALUE</code>. Consider:</para> + + <informaltable border="1"> + <tr> + <th>Code</th> + + <th>Output</th> + </tr> + + <tr> + <td valign="top"><programlisting language="java">byte b = Byte.MAX_VALUE; +System.out.println(b); +b++; +System.out.println(b);</programlisting></td> + + <td valign="top"><screen>127 +-128</screen></td> + </tr> + </informaltable> + + <para>Before breeching the loop's upper limit <code + language="java">Byte.MAX_VALUE</code> our variable <code + language="java">b will thus transition</code> from Byte.MAX_VALUE + to <code language="java">Byte.MIN_VALUE</code>. The loop will thus + continue forever.</para> + </answer> + </qandaentry> + </qandadiv> + </qandaset> + </section> +</section> diff --git a/Doc/Sd1/Appendix/appendix.xml b/Doc/Sd1/Appendix/appendix.xml index cb9d8e3c6417d1a8b3e4702b55c4d8c907174658..c7ed5a8fce7d839e868bfb2ea9a3f1ba326d500b 100644 --- a/Doc/Sd1/Appendix/appendix.xml +++ b/Doc/Sd1/Appendix/appendix.xml @@ -2353,6 +2353,10 @@ Value 2147483645 is not prime. </listitem> </orderedlist> + + <xi:include href="Exam/2023/Winter/exam.xml" xpointer="element(/1)" + ns:idfixup="auto"/> + <xi:include href="Exam/2023/Summer/exam.xml" xpointer="element(/1)" ns:idfixup="auto"/> diff --git a/Klausuren/Sd1/2023winter/Exam/Readme.md b/Klausuren/Sd1/2023winter/Exam/Readme.md new file mode 100644 index 0000000000000000000000000000000000000000..caf9ae0dd53a781da24b0432c27cbb53c88352b1 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Exam/Readme.md @@ -0,0 +1,55 @@ +# Generate and open class/method javadoc for browsing + +Grab a terminal in this IDE (By lower left icon or Alt+F12) and issue the following command: + +<pre>Exam> mvn javadoc:javadoc +... +[<span style="color:blue;font-weight:bold;">INFO</span>] Executing tasks +[<span style="color:orange;font-weight:bold;">WARNING</span>] [echo] Javadoc root at <span style="color:blue;">file:///home/.../Downloads/Exam/target/site/apidocs/index.html</span> +[<span style="color:blue;font-weight:bold;">INFO</span>] Executed tasks +...</pre> + +Click the <span style="color:blue;">file:///.../index.html</span> link opening your project's `index.html` Javadoc root +in your system's default web browser. + +# Implementation tasks + +Your project's following packages do contain implementation tasks: + +- `de.hdm_stuttgart.mi.sd1.task1` (50 Points) + +- `de.hdm_stuttgart.mi.sd1.task2` (20 points, more difficult) + +Read the generated documentation and implement the skeleton methods and classes. + +Your project's `test` branch does contain corresponding unit tests for verifying your solutions' correctness. + +# Hints + +- 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 not contribute any points at all. + +- General advice: Implement less but correctly. + +- Mind special cases i.e. `null` variable values or null values being contained in arrays. + +- In case of test failures both the IDEA debugger and logging statements are your friend. + +Executing `de.hdm_stuttgart.mi.sd1.ShowReachedPoints` in your project's test branch as a Java application +(not as Junit test!) shows your number of points reached so far. + +Do not model your implementations along unit test definitions i.e. avoid cheating this way! Such behaviour will be +regarded as an attempt at deception (Täuschungsversuch). + +# Exam system upload + +After finishing implementing: + +1. Export this project by hitting **»File âž” Export âž” Project to Zip File«**. +1. Use a self-explanatory file name like e.g. `solution1.zip`. +1. Go to your exam browser window and upload `solution1.zip` . +1. Complete by **clicking the »<span style="background: #527A35;color:white;">Speichern + weiter âžž </span>«** button. +1. Hit **<span style="background: #446684;color:white;"> 🠬 Speichern + zurück</span>** and check if your + upload is visible. +1. If you advance on implementing: Repeat steps 1. to 5.: Only the least uploaded `.zip` archive will become subject to + marking. diff --git a/Klausuren/Sd1/2023winter/Exam/pom.xml b/Klausuren/Sd1/2023winter/Exam/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..b8ab3bc9848f85da99ff02c35cd1f19432095868 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Exam/pom.xml @@ -0,0 +1,129 @@ +<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_2023winter_exam</artifactId> + <version>0.9</version> + <packaging>jar</packaging> + + <name>sd1_2023winter_exam</name> + + <url>https://freedocs.mi.hdm-stuttgart.de/sd1_sect_mavenCli.html</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <maven.compiler.release>17</maven.compiler.release> + + <freedocs.url>https://freedocs.mi.hdm-stuttgart.de</freedocs.url> + <mathjax.url>${freedocs.url}/lib/MathJax/es5/tex-chtml.js</mathjax.url> + <libhighlight.url>${freedocs.url}/lib/highlight.js</libhighlight.url> + </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>de.hdm_stuttgart.mi.exam</groupId> + <artifactId>unitmarking</artifactId> + <version>1.3</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.11.0</version> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-antrun-plugin</artifactId> + <version>3.1.0</version> + <executions> + <execution> + <phase>generate-sources</phase> + <goals> + <goal>run</goal> + </goals> + <configuration> + <target> + <echo>Javadoc root at file://${project.basedir}/target/site/apidocs/index.html</echo> + </target> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>3.5.0</version> + <configuration> + <release>17</release> + <doclint>all</doclint> + <show>public</show> + <docfilessubdirs>true</docfilessubdirs> + <addStylesheets> + <stylesheet>resources/jdocSupplement.css</stylesheet> + </addStylesheets> + + <windowtitle>Exam documentation</windowtitle> + <links> + <link>${freedocs.url}/doc/openjdk-21-doc/api/</link> + </links> + <additionalOptions> + <additionalOption>-html5 --allow-script-in-comments</additionalOption> + </additionalOptions> + <nohelp>true</nohelp> + + <header><![CDATA[ + <script type="text/javascript" src="${mathjax.url}"></script> + <script type="text/javascript" src="{@docRoot}/resources/jdocSupplement.js"></script> + + <link rel="stylesheet" href="${libhighlight.url}/styles/idea.min.css"> + <script src="${libhighlight.url}/highlight.min.js"></script> + <script type="text/javascript">hljs.highlightAll();</script>]]> + </header> + <bottom><![CDATA[Copyright © 2023 Stuttgart Media University / MI. Licensed under + <a style="font-weight:bold;" href="https://creativecommons.org/licenses/by/4.0/legalcode" target="_blank" + >Creative Commons Attribution 4.0 International Public License</a>.]]></bottom> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-assembly-plugin</artifactId> + <version>3.6.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.ShowReachedPoints</mainClass> + </manifest> + </archive> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/Klausuren/Sd1/2023winter/Exam/src/main/assembly/assembly.xml b/Klausuren/Sd1/2023winter/Exam/src/main/assembly/assembly.xml new file mode 100644 index 0000000000000000000000000000000000000000..85268e2965620878373d76337f524d8785fd0e1f --- /dev/null +++ b/Klausuren/Sd1/2023winter/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/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLight.java b/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLight.java new file mode 100644 index 0000000000000000000000000000000000000000..24f51ff2d3a1bf2e390990eec8f333b15948c5d1 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLight.java @@ -0,0 +1,94 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +/** + * <p>Valid German traffic light states.</p> + */ +public class A_TrafficLight { + /** + * <p>Traffic light state validation.</p> + * + * <p>German traffic lights feature three different colours red, yellow and green. Only the following four states + * are valid:</p> + * + * <table style="outline: 2px solid;border-spacing: 10ex 0;"> + * <caption style="background: lightgrey;text-align: left;"><em>Valid German traffic light states</em></caption> + * <tr> + * <td style="border: 2px solid black;border-radius: 10px;font-size:40px;background:black;"> + * <ul> + * <li style="color:red;"></li> + * <li style="color:black;"></li> + * <li style="color:black;"></li> + * </ul> + * </td> + * <td>Wait</td> + * <td style="border: 2px solid black;border-radius: 10px;font-size:40px;background:black;"> + * <ul> + * <li style="color:red;"></li> + * <li style="color:yellow;"></li> + * <li style="color:black;"></li> + * </ul> + * </td> + * <td>Start</td> + * <td style="border: 2px solid black;border-radius: 10px;font-size:40px;background:black;"> + * <ul> + * <li style="color:black;"></li> + * <li style="color:black;"></li> + * <li style="color:green;"></li> + * </ul> + * </td> + * <td>Go</td> + * <td style="border: 2px solid black;border-radius: 10px;font-size:40px;background:black;"> + * <ul> + * <li style="color:black;"></li> + * <li style="color:yellow;"></li> + * <li style="color:black;"></li> + * </ul> + * </td> + * <td>Stop</td> + * </tr> + * </table> + * + * <p>On contrary <em>any</em> other pattern due to e.g. broken bulbs or other technical failures is invalid:</p> + * + * <table style="outline: 2px solid;border-spacing: 10ex 0;"> + * <caption style="background:lightgrey;text-align:left;"> + * <em>Invalid German traffic light state examples</em> + * </caption> + * <tr> + * <td style="border: 2px solid black;border-radius: 10px;font-size:40px;background:black;"> + * <ul > + * <li style="color:red;"></li> + * <li style="color:black;"></li> + * <li style="color:green;"></li> + * </ul> + * </td> + * <td> + * <p>Wait or go?</p> + * <p>(Fix my</p> + * <p>control</p> + * <p>unit!)</p> + * </td> + * <td style="border: 2px solid black;border-radius: 10px;font-size:40px;background:black;"> + * <ul > + * <li style="color:black;"></li> + * <li style="color:black;"></li> + * <li style="color:black;"></li> + * </ul> + * </td> + * <td>Broken bulb(s)</td> + * <td>...</td> + * </tr> + * </table> + * + * @param red <code>true</code> represents »on«, <code>false</code> represents »off«. + * @param yellow <code>true</code> represents »on«, <code>false</code> represents »off«. + * @param green <code>true</code> represents »on«, <code>false</code> represents »off«. + * + * @return <code>true</code> if in a valid state, <code>false</code> otherwise. + */ + static public boolean stateIsValid(boolean red, boolean yellow, boolean green) { + return true; //TODO: Implement me! + } + + private A_TrafficLight(){/* Ignore me: My sole purpose is suppressing default constructor javadoc generation */} +} diff --git a/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/B_Max.java b/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/B_Max.java new file mode 100644 index 0000000000000000000000000000000000000000..6bd47576dd94e6503ef6325fd55a9f36c3278d20 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/B_Max.java @@ -0,0 +1,59 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +/** + * <p>Doing basic calculations.</p> + */ +public class B_Max { + /** + * <p>Get the largest basic calculation result of two values.</p> + * + * <p>We have four different basic calculation operations:</p> + * + * <ul style="list-style:none"> + * <li><code style="font-weight: bolder">+</code>: Addition</li> + * <li><code style="font-weight: bolder">-</code>: Subtraction</li> + * <li><code style="font-weight: bolder">*</code>: Multiplication</li> + * <li><code style="font-weight: bolder">/</code>: Division</li> + * </ul> + * + * <p>Given two values like e.g 4 and 0.1 we can construct four different basic calculation terms:</p> + * + * <ul style="list-style:none"> + * <li><code>4 + 0.1 == 4.1</code></li> + * <li><code>4 - 0.1 == 3.9</code></li> + * <li><code>4 * 0.1 == 0.4</code></li> + * <li><code style="background: lightgreen">4 / 0.1 == 40</code></li> + * </ul> + * + * <p>The above example features a maximum result value of 40 resulting from dividing 4 by 0.1 . + * Depending on both values the maximum may result from either of our four basic operations. We take a + * second set of example values 3 and -1:</p> + * + * <ul style="list-style:none"> + * <li><code>3 + (-1) == 2</code></li> + * <li><code style="background: lightgreen">3 - (-1) == 4</code></li> + * <li><code>3 * (-1) == -3</code></li> + * <li><code>3 / (-1) == -3</code></li> + * </ul> + * + * <p>This time we get a maximum of 4 by subtracting -1 from 3 .</p> + * + * @param first The first operand + * @param second The second operand + * @return The largest basic calculation result taking both arguments in their respective order. + * + * <section class="implementationHints"> + * <h4 class="implementationHints">Hints:</h4> + * + * <ol> + * <li>Create all four possible arithmetic results</li> + * <li>Then choose the largest among these four values</li> + * </ol> + * + * </section> + */ + public static double getBasicCalculationMax(final double first, final double second) { + return 42.0; //TODO: Implement me! + } + private B_Max(){/* Ignore me, suppressing implicit default constructor Javadoc HTML generation */} +} diff --git a/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/C_WebUrl.java b/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/C_WebUrl.java new file mode 100644 index 0000000000000000000000000000000000000000..02916a8d23b6aa397d758b433f38b6dd29a0805f --- /dev/null +++ b/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/C_WebUrl.java @@ -0,0 +1,77 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +/** + * <p>Handle web addresses.</p> + */ +public class C_WebUrl { + + /** + * <p>Accessing web sites e.g. <code>www.wikipedia.org</code> requires entering the address in a web browser:</p> + * + * <img style="outline: 2px solid;" + * src="doc-files/weburlBlank.png" alt="A web address without protocol specification" > + * + * <p>Entering <code>www.wikipedia.org</code> fulfills its purpose. However behind the scenes either a + * <code>http://</code> or <code>https://</code> protocol specification is being silently prepended:</p> + * + * <img style="outline: 2px solid;" + * src="doc-files/weburlProtocol.png" alt="A web address including a protocol specification"> + * + * <p>The current method adds a missing protocol specification according to the following rules:</p> + * + * <ul> + * <li>An address already starting with either <code>http://</code> or <code>https://</code> is just being + * copied.</li> + * + * <li> + * <p>An address not starting with either <code>http://</code> or <code>https://</code> receives a + * protocol prefix according to the <code>tlsSupport</code> parameter.</p> + * </li> + * </ul> + * <p>Some examples:</p> + * <table class="goikTableDefaults"> + * <caption>Optional protocol prefix examples for <code>www.wikipedia.org</code></caption> + * <tr> + * <th><code>address</code></th> + * <th><code>tlsSupport</code></th> + * <th>Return value</th> + * </tr> + * <tr> + * <td style="color:blue"><code>www.wikipedia.org</code></td> + * <td><code style="color:red">true</code></td> + * <td><code style="color:red">https</code>://<code style="color:blue">www.wikipedia.org</code></td> + * </tr> + * <tr> + * <td style="color:blue"><code>www.wikipedia.org</code></td> + * <td><code style="color:red">false</code></td> + * <td><code style="color:red">http</code>://<code style="color:blue">www.wikipedia.org</code></td> + * </tr> + * <tr> + * <td style="color:blue"><code>http://www.wikipedia.org</code></td> + * <td>Protocol specification <code>http://</code> present, value irrelevant</td> + * <td style="color:blue"><code>http://www.wikipedia.org</code></td> + * </tr> + * <tr> + * <td style="color:blue"><code>https://www.wikipedia.org</code></td> + * <td>Protocol specification <code>https://</code> present, value irrelevant</td> + * <td style="color:blue"><code>https://www.wikipedia.org</code></td> + * </tr> + * </table> + * + * @param address A website's address. May either be a raw name or a full http/https prefixed protocol address. + * @param tlsSupport If <code>true</code> the server supports + * <code><span style="color:red">https</span>://...</code> connections. Otherwise, only + * <code><span style="color:red">http</span>://...</code> is being supported. + * + * @return A fully <code>http://</code> or <code>https://</code> prefixed protocol address. + * + * <section class="implementationHints"> + * <h4 class="implementationHints">Hint:</h4> + * + * <p>{@link String#startsWith(String)}</p> + * </section> + */ + public static String amendWebAddress(final String address, final boolean tlsSupport) { + return "Not yet implemented!"; //TODO: Implement me! + } +} diff --git a/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/D_Array.java b/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/D_Array.java new file mode 100644 index 0000000000000000000000000000000000000000..752b2f02b2c3300c06b3da4bdf7e102cf6b933c1 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/D_Array.java @@ -0,0 +1,67 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +/** + * Array helper method. + */ +public class D_Array { + + /** + * The special value -1 indicating two arrays are not being related by any sequence of right cyclic rotations. + * Example: {1, 2} and {1, 3}. + */ + static public final int NOT_CYCLICALLY_RELATED = -1 ; + + /** + * <p>Part 2: Check two arrays for being related by an integer number of successive right cyclic rotations or not.</p> + * + * <p>Consider a right cyclic array rotating example:</p> + * + * <pre> + * <span style="color:red">â¬â”€â”€â”€â”€â”€â”</span> + * {1, 7, <span style="color:blue">3</span>} ⇨ {<span style="color:blue">3</span>, 1, 7} + * <span style="color:red">⤻ ⤻</span> + * </pre> + * + * <p>The arrays <code>{1, 7, 3}</code> and <code>{3, 1, 7}</code> are thus being related by one right + * cyclic rotation.</p> + * + * <p>Arrays may also be related by a succession of multiple right cyclic rotations. Example:</p> + * + * <p><code>{1, 8, 3, 4}</code> and <code>{3, 4, 1, 8}</code> are being related by a sequence of two right cyclic + * rotations:</p> + * + * <pre> + * <span style="color:red"> â¬â”€â”€â”€â”€â”€â”€â”€â”€â” â¬â”€â”€â”€â”€â”€â”€â”€â”€â”</span> + * {1, 8, 3, <span style="color:blue">4</span>} ⇨ {<span style="color:blue">4</span>, 1, 8, <span + * style="color:orange">3</span>} ⇨ {<span style="color:orange">3</span>, <span style="color:blue">4</span>, 1, 8} + * <span style="color:red"> ⤻ ⤻ ⤻ ⤻ ⤻ ⤻</span> + * </pre> + * + * <p>In this case a value of 2 rotations is being returned.</p> + * + * <h4>Special cases: </h4> + * + * <ul> + * <li>Two identical arrays are being related by zero rotations.</li> + * <li>Two arrays of different size are always unrelated / {@link #NOT_CYCLICALLY_RELATED} .</li> + * </ul> + * + * @param array1 The first array. Values must remain untouched. + * @param array2 The second array. Values must remain untouched. + * + * @return Either the number of right cyclic rotations or the special value {@link #NOT_CYCLICALLY_RELATED} if both + * arrays are not being related by a sequence of cyclic rotations. + * + * <section class="implementationHints"> + * <h4 class="implementationHints">Hints:</h4> + * + * <p>You likely need two nested loops: One representing all possible array shift values. A second one + * comparing all index positions with respect to the given shift value.</p> + * + * </section> + */ + static public int isRotatedBy(final int[] array1, int[] array2) { + return 42; //TODO: Implement me! + } + private D_Array(){/* Ignore me, suppressing implicit default constructor Javadoc HTML generation */} +} diff --git a/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java b/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..6152c2c29cb6d00991e889f9f08151683f7245e0 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java @@ -0,0 +1,22 @@ +/** + * <p>Classes here mostly (if not completely) contain static methods to be implemented.</p> + * + * <p>The ordering being implied by (test) class names and related methods reflect the author's opinion about ascending + * implementation difficulty. You are free to proceed differently. Hints:</p> + * + * <ul> + * <li>Run <code>mvn javadoc:javadoc</code> and open the generated + * <code><projectroot>/target/site/apidocs/index.html</code> file in your browser of choice.</li> + * + * <li>Read the generated documentation thoroughly. Make sure you do understand the intended method behaviour prior + * to implementing.</li> + * + * <li>Use the corresponding unit tests from your project's »test« branch checking your implementation's + * correctness. Executing <code>de.hdm_stuttgart.mi.sd1.ShowReachedPoints</code> reveals your number + * of examination points reached so far.</li> + * + * <li>The debugger is your friend</li> + * </ul> + * + */ +package de.hdm_stuttgart.mi.sd1.task1; \ No newline at end of file diff --git a/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/Direction.java b/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/Direction.java new file mode 100644 index 0000000000000000000000000000000000000000..999e98a8cdc5d38a7472318310c60fab81f0bbb9 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/Direction.java @@ -0,0 +1,47 @@ +package de.hdm_stuttgart.mi.sd1.task2; + +// You probably don't want to edit this auxiliary class. Start with + +/** <p>The 8 main wind directions.</p> + * + * <p>You probably don't want to edit this auxiliary class. Start working on class {@link WindForecast} </p> + * + */ +public enum Direction { + /** + * North + */ + N, + /** + * Northeast + */ + NE, + /** + * East + */ + E, + + /** + * Southeast + */ + SE, + + /** + * South + */ + S, + + /** + * Southwest + */ + SW, + + /** + * West + */ + W, + /** + * Northwest + */ + NW +} diff --git a/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/WindForecast.java b/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/WindForecast.java new file mode 100644 index 0000000000000000000000000000000000000000..97dfecfe1202f8d98a9028499599bbd7e677bdc2 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/WindForecast.java @@ -0,0 +1,37 @@ +package de.hdm_stuttgart.mi.sd1.task2; + +/** + * <p>Check for matching wind conditions.</p> + * + * <p>Many water sport addicts depend on suitable wind conditions being described by wind speed and + * optionally wind direction.</p> + * + * <p>We start an example forecasting <span style="color:green">40</span> Km Wind speed from north using + * enum {@link Direction}:</p> + * + * <pre style="background-color: lightgray"><code class="nohighlight"> final WindForecast forecast = new WindForecast(<span style="color:green">40</span>, Direction.N);</code></pre> + * + * <p>A kitesurfer wants to get notified if the wind forecast at his or her spot predicts + * wind ranging from <span style="color:blue">30</span> Km/h to <span style="color:red">50</span> Km/h in speed coming + * either from northern ({@link Direction#N}) or northwestern ({@link Direction#NW}) directions.</p> + * + * <p>The <code>matchingConditions(...)</code> method in the following code snippet expects minimum and maximum desired + * wind speed and a (possibly empty) list of desired wind directions. One of our surfer's desired directions being + * {@link Direction#N} and the forcast of <span style="color:green">40</span> Km/h being within the desired <span style="color:blue">30</span> Km/h to + * <span style="color:red">50</span> Km/h range calling <code>matchingConditions(...)</code> will thus return + * <code>true</code>:</p> + * + * <pre style="background-color: lightgray"><code class="nohighlight"> final WindForecast forecast = new WindForecast(<span style="color:green">40</span>, Direction.N); + * + * if (forecast.matchingConditions(<span style="color:blue">30</span>, <span style="color:red">50</span>, new Direction[]{Direction.N, Direction.NW})) { + * System.out.println("Yeah, let's go for it! \uD83D\uDE0E"); + * else { + * System.out.println("I hate waiting for the wind! \uD83E\uDD2C"); + * }</code></pre> + * + * <p>Complete the implementation of {@link WindForecast} allowing to run code like above using the + * pre-defined enum {@link Direction}.</p> + */ +public class WindForecast { + //TODO: Implement me! +} diff --git a/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java b/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..b12e6627a104b0c0cc4c7151c2aef643bf94070f --- /dev/null +++ b/Klausuren/Sd1/2023winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java @@ -0,0 +1,18 @@ +/** + * <p>This package hosts more advanced implementation tasks.</p> + * + * <ul> + * <li>Run <code>mvn javadoc:javadoc</code> and open the generated + * <code><projectroot>/target/site/apidocs/index.html</code> file in your browser of choice.</li> + * + * <li>Read the generated documentation thoroughly. Make sure you do understand the intended method behaviour prior + * to implementing.</li> + * + * <li>Use the corresponding unit tests from your project's »test« branch checking your implementation's + * correctness. Executing <code>de.hdm_stuttgart.mi.sd1.ShowReachedPoints</code> reveals your number + * of examination points reached so far.</li> + * + * <li>The debugger is your friend</li> + * </ul> + */ +package de.hdm_stuttgart.mi.sd1.task2; \ No newline at end of file diff --git a/Klausuren/Sd1/2023winter/Exam/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/weburlBlank.png b/Klausuren/Sd1/2023winter/Exam/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/weburlBlank.png new file mode 100644 index 0000000000000000000000000000000000000000..01376dac6c420ef680afbbb82f147dfa569b0766 Binary files /dev/null and b/Klausuren/Sd1/2023winter/Exam/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/weburlBlank.png differ diff --git a/Klausuren/Sd1/2023winter/Exam/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/weburlProtocol.png b/Klausuren/Sd1/2023winter/Exam/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/weburlProtocol.png new file mode 100644 index 0000000000000000000000000000000000000000..a9c648b8d28812201ab15b272b7e953c7c0fb642 Binary files /dev/null and b/Klausuren/Sd1/2023winter/Exam/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/weburlProtocol.png differ diff --git a/Klausuren/Sd1/2023winter/Exam/src/main/javadoc/resources/fonts/dejavu.css b/Klausuren/Sd1/2023winter/Exam/src/main/javadoc/resources/fonts/dejavu.css new file mode 100644 index 0000000000000000000000000000000000000000..4fec2b593cdcc719fd7edd6744a33a3395ca8401 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Exam/src/main/javadoc/resources/fonts/dejavu.css @@ -0,0 +1,3 @@ +/* shame on you, javadoc! Still providing +@import url('resources/fonts/dejavu.css') line in stylesheet.css +*/ \ No newline at end of file diff --git a/Klausuren/Sd1/2023winter/Exam/src/main/javadoc/resources/jdocSupplement.css b/Klausuren/Sd1/2023winter/Exam/src/main/javadoc/resources/jdocSupplement.css new file mode 100644 index 0000000000000000000000000000000000000000..08840cdbf55d1f43368245d0a965659c4411b2ee --- /dev/null +++ b/Klausuren/Sd1/2023winter/Exam/src/main/javadoc/resources/jdocSupplement.css @@ -0,0 +1,72 @@ +/* Javadoc extensions: */ + +ul > li > ul { + list-style-type: circle; +} + +table.goikTableDefaults, +table.goikTableDefaults>caption, +table.goikTableDefaults>tr>th, +table.goikTableDefaults>tr>td, +table.goikTableDefaults>tbody>tr>th, +table.goikTableDefaults>tbody>tr>td { + border: 2px solid black; + border-collapse: collapse; + padding: 1ex; + vertical-align: top; +} + +table.goikTableDefaults>caption { + /* border-top-style: solid; border-left-style: solid; border-right-style: solid' */ + border-bottom-style: none; + font-weight: bold; + background:#dee3e9; + text-align:left; + padding:8px 3px 3px 7px; +} + +table.goikTableDefaults>tbody>tr>td { + vertical-align:top; +} +table.goikTableDefaults { + border-spacing: 0px !important; +} + +table.indexTable { + border-collapse: collapse; + border-style: hidden; +} + +table.indexTable caption { + text-align: left; +} + +table.indexTable td, table.indexTable th { + border: 1px solid black; + padding: 0.5ex; +} + +em { + font-weight: bold; + font-style: normal; +} +section.implementationHints>h3 { + font-weight: bold; + background-color: rgb(222, 227, 233); +} + +code { + white-space: pre; +} + +.implementationHints { + background-color: hsl(120, 100%, 95%) !important; +} + +.myRed { + color: red; +} + +.myGreen { + color: limegreen; +} diff --git a/Klausuren/Sd1/2023winter/Exam/src/main/javadoc/resources/jdocSupplement.js b/Klausuren/Sd1/2023winter/Exam/src/main/javadoc/resources/jdocSupplement.js new file mode 100644 index 0000000000000000000000000000000000000000..97911e5581090aac5e37323427450f8c8c8a3f94 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Exam/src/main/javadoc/resources/jdocSupplement.js @@ -0,0 +1,7 @@ +for(var i in document.links) { + var link = document.links[i]; + if (link.href && link.href.indexOf('http') === 0) { + link.target = '_blank'; + } +} + diff --git a/Klausuren/Sd1/2023winter/Exam/src/main/resources/log4j2.xml b/Klausuren/Sd1/2023winter/Exam/src/main/resources/log4j2.xml new file mode 100644 index 0000000000000000000000000000000000000000..130f87a144c4eb0107a846e580c8fa7f5e819fc1 --- /dev/null +++ b/Klausuren/Sd1/2023winter/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/2023winter/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/ShowReachedPoints.java b/Klausuren/Sd1/2023winter/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/ShowReachedPoints.java new file mode 100644 index 0000000000000000000000000000000000000000..651f0a5cd9ee20050512acadbcc61c4a8c6c0398 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/ShowReachedPoints.java @@ -0,0 +1,26 @@ +package de.hdm_stuttgart.mi.sd1; + +import de.hdm_stuttgart.mi.exam.unitmarking.RunTests; + +import de.hdm_stuttgart.mi.sd1.task1.A_TrafficLightTest; +import de.hdm_stuttgart.mi.sd1.task1.B_MaxTest; +import de.hdm_stuttgart.mi.sd1.task1.C_WebUrlTest; +import de.hdm_stuttgart.mi.sd1.task1.D_ArrayTest; + +import de.hdm_stuttgart.mi.sd1.task2.WindForecastTest; + +public class ShowReachedPoints { + + /** + * Revealing total number of reached points from all tasks. + * + * @param args Unused + */ + public static void main(String[] args) { + RunTests.exec( + "Task 1", + A_TrafficLightTest.class, B_MaxTest.class, C_WebUrlTest.class, D_ArrayTest.class + ); + RunTests.exec("Task 2", WindForecastTest.class); + } +} diff --git a/Klausuren/Sd1/2023winter/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLightTest.java b/Klausuren/Sd1/2023winter/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLightTest.java new file mode 100644 index 0000000000000000000000000000000000000000..3e3960d0433ee029f306e6a74bd417c112a6b177 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLightTest.java @@ -0,0 +1,28 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import static de.hdm_stuttgart.mi.sd1.task1.A_TrafficLight.stateIsValid; + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class A_TrafficLightTest extends ExaminationTestDefaults { + + @Test + @Marking(points = 18) + public void test_100() { + Assert.assertFalse( stateIsValid(false, false, false)); + Assert.assertTrue( stateIsValid(false, false, true)); + Assert.assertTrue( stateIsValid(false, true, false)); + Assert.assertFalse( stateIsValid(false, true, true)); + Assert.assertTrue( stateIsValid(true, false, false)); + Assert.assertFalse( stateIsValid(true, false, true)); + Assert.assertTrue( stateIsValid(true, true, false)); + Assert.assertFalse( stateIsValid(true, true, true)); + } +} diff --git a/Klausuren/Sd1/2023winter/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task1/B_MaxTest.java b/Klausuren/Sd1/2023winter/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task1/B_MaxTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d1e1779072d56c936ec178c43924e44fa6b20225 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task1/B_MaxTest.java @@ -0,0 +1,37 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class B_MaxTest extends ExaminationTestDefaults { + static final public double PRECISION = 1.E-12; + + @Test + @Marking(points = 15) + public void test() { + assertMaximum(12, 4, 3, '*'); + assertMaximum(5, 2, -3, '-'); + assertMaximum(5.1, 0.1, 5, '+'); + assertMaximum(35, 7, 0.2, '/'); + assertMaximum(-1.4,-7, 0.2, '*'); + assertMaximum(4,2, 2, '+'); + } + + private static void assertMaximum(final double expected, final double first, final double second, char operation) { + + final StringBuilder errMsg = new StringBuilder("Expected maximum is " + expected + " == " + first + " " + + operation + " "); + + if (second < 0) { + errMsg.append("(" + second + ")"); + } else { + errMsg.append(second); + } + Assert.assertEquals(errMsg.toString(), expected, B_Max.getBasicCalculationMax(first, second), PRECISION); + } +} diff --git a/Klausuren/Sd1/2023winter/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task1/C_WebUrlTest.java b/Klausuren/Sd1/2023winter/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task1/C_WebUrlTest.java new file mode 100644 index 0000000000000000000000000000000000000000..4df40473b27a8d74580319e3d44529c7ff71844c --- /dev/null +++ b/Klausuren/Sd1/2023winter/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task1/C_WebUrlTest.java @@ -0,0 +1,66 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + + + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class C_WebUrlTest extends ExaminationTestDefaults { + + static private final String dnsNames[] = { + "www.der-postillon.com", "www.duh.de", "www.amnesty.org" + }; + + + @Test + @Marking(points = 14) + public void test() { + + for(final String dns: dnsNames) { + final String + httpUrl = "http://" + dns, + httpsUrl = "https://" + dns, + + actualByHttpsTlsTrue = C_WebUrl.amendWebAddress(httpsUrl, true), + actualByHttpsTlsFalse = C_WebUrl.amendWebAddress(httpsUrl, false), + + actualByHttpTlsTrue = C_WebUrl.amendWebAddress(httpUrl, true), + actualByHttpTlsFalse = C_WebUrl.amendWebAddress(httpUrl, false), + + actualByDnsTlsTrue = C_WebUrl.amendWebAddress(dns, true), + actualByDnsTlsFalse = C_WebUrl.amendWebAddress(dns, false); + + Assert.assertEquals( + "Passing '" + httpsUrl + "' should return '" + httpsUrl + "' rather than '" + actualByHttpsTlsTrue + "'", + httpsUrl, actualByHttpsTlsTrue); + + Assert.assertEquals( + "Passing '" + httpsUrl + "' should return '" + httpsUrl + "' rather than '" + actualByHttpsTlsFalse + "'", + httpsUrl, actualByHttpsTlsFalse); + + Assert.assertEquals( + "Passing '" + httpUrl + "' should return '" + httpUrl + "' rather than '" + actualByHttpTlsTrue + "'", + httpUrl, actualByHttpTlsTrue); + + Assert.assertEquals( + "Passing '" + httpUrl + "' should return '" + httpUrl + "' rather than '" + actualByHttpTlsFalse + "'", + httpUrl, actualByHttpTlsFalse); + + + Assert.assertEquals( + "Passing '" + dns + "' when tlsSupport is 'true' should return '" + httpsUrl + "' rather than " + actualByDnsTlsTrue, + httpsUrl, actualByDnsTlsTrue); + + Assert.assertEquals( + "Passing '" + dns + "' when tlsSupport is 'false' should return '" + httpUrl + "' rather than " + actualByDnsTlsFalse, + httpUrl, actualByDnsTlsFalse); + + } + } +} diff --git a/Klausuren/Sd1/2023winter/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task1/D_ArrayTest.java b/Klausuren/Sd1/2023winter/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task1/D_ArrayTest.java new file mode 100644 index 0000000000000000000000000000000000000000..24b763ada8c1814fa8ec239998836bee384e0f9d --- /dev/null +++ b/Klausuren/Sd1/2023winter/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task1/D_ArrayTest.java @@ -0,0 +1,118 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import java.util.Arrays; + +import static de.hdm_stuttgart.mi.sd1.task1.D_Array.NOT_CYCLICALLY_RELATED; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class D_ArrayTest extends ExaminationTestDefaults { + + private static void assertRelatedByRotation(final int expectedRotation, final int[] array1, int[] array2) { + + final int[] array1Copy = Arrays.copyOf(array1, array1.length), + array2Copy = Arrays.copyOf(array2, array2.length); + + final String errorMessage; + if (NOT_CYCLICALLY_RELATED == expectedRotation) { + errorMessage = Arrays.toString(array1) + " and " + Arrays.toString(array2) + + " are not being cyclically related."; + } else { + errorMessage = Arrays.toString(array1) + " and " + Arrays.toString(array2) + + " are being cyclically related by " + expectedRotation + " right rotation(s)."; + } + Assert.assertEquals(errorMessage, expectedRotation, D_Array.isRotatedBy(array1, array2)); + + Assert.assertArrayEquals("You must not change values in array1 parameter", array1Copy, array1); + Assert.assertArrayEquals("You must not change values in array2 parameter", array2Copy, array2); + } + + @Test + public void test010_Minimum() { + assertRelatedByRotation(0, new int[]{}, new int[]{}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{}, new int[]{1}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{3}, new int[]{}); + } + @Test + public void test020One() { + assertRelatedByRotation(0, new int[]{77}, new int[]{77}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{8}, new int[]{77}); + } + + @Test + @Marking(points = 2) + public void test030Two() { + assertRelatedByRotation(0, new int[]{-1, 5}, new int[]{-1, 5}); + assertRelatedByRotation(1, new int[]{-1, 5}, new int[]{5, -1}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{-1, 5}, new int[]{-5, 1}); + } + @Test + @Marking(points = 2) + public void test040Three() { + assertRelatedByRotation( 0, new int[]{2, -6, 9}, new int[]{ 2, -6, 9}); + assertRelatedByRotation( 1, new int[]{2, -6, 9}, new int[]{ 9, 2, -6}); + assertRelatedByRotation( 2, new int[]{2, -6, 9}, new int[]{-6, 9, 2}); + + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{2, -6, 9}, new int[]{ 2, 9, -6}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{2, -6, 9}, new int[]{-6, 2, 9}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{2, -6, 9}, new int[]{-6, 2}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{-1, 2, 4}, new int[]{-1, 2, 5}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{-1, 2, 4}, new int[]{-2, 2, 4}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{-1, 2, 4}, new int[]{-1, 3, 4}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{-1, 2, 4}, new int[]{-1, 3, 4, 3}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{-1, 2, 4, 1}, new int[]{-1, 3, 4}); + } + @Test + @Marking(points = 2) + public void test050Twenty() { + assertRelatedByRotation( 0, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}); + + assertRelatedByRotation( 1, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{10, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + + assertRelatedByRotation( 2, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{9, 10, 1, 2, 3, 4, 5, 6, 7, 8}); + + assertRelatedByRotation( 3, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{8, 9, 10, 1, 2, 3, 4, 5, 6, 7}); + + assertRelatedByRotation( 4, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{7, 8, 9, 10, 1, 2, 3, 4, 5, 6}); + + assertRelatedByRotation( 5, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{6, 7, 8, 9, 10, 1, 2, 3, 4, 5}); + + assertRelatedByRotation( 6, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{5, 6, 7, 8, 9, 10, 1, 2, 3, 4}); + + assertRelatedByRotation( 7, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{4, 5, 6, 7, 8, 9, 10, 1, 2, 3}); + + assertRelatedByRotation( 8, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{3, 4, 5, 6, 7, 8, 9, 10, 1, 2}); + + assertRelatedByRotation( 9, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{2, 3, 4, 5, 6, 7, 8, 9, 10, 1}); + + assertRelatedByRotation( NOT_CYCLICALLY_RELATED, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{1, 2, 3, 4, 6, 5, 7, 8, 9, 10}); + + assertRelatedByRotation( NOT_CYCLICALLY_RELATED, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{1, 2, 3, 4, 6, 5, 7, 8, 9}); + + assertRelatedByRotation( NOT_CYCLICALLY_RELATED, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, + /* */ new int[]{1, 2, 3, 4, 6, 5, 7, 8, 9, 10}); + + assertRelatedByRotation( NOT_CYCLICALLY_RELATED, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{}); + + + } +} diff --git a/Klausuren/Sd1/2023winter/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task2/WindForecastTest.java b/Klausuren/Sd1/2023winter/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task2/WindForecastTest.java new file mode 100644 index 0000000000000000000000000000000000000000..00f5f04be115f99a51be06a185076eebd2760190 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/task2/WindForecastTest.java @@ -0,0 +1,56 @@ +package de.hdm_stuttgart.mi.sd1.task2; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.exam.unitmarking.reflect.ObjectWrapper; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import static de.hdm_stuttgart.mi.sd1.task2.Direction.*; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) + +public class WindForecastTest extends ExaminationTestDefaults { + + final ObjectWrapper<WindForecast> forecast_30_S = + new ObjectWrapper<>(WindForecast.class, 30, S); + + @Test + @Marking(points = 10) + public void test_100_noDirection() { + + Assert.assertTrue("Forecast speed 30 being within [30, 40] expects true", + forecast_30_S.invoke(boolean.class, "matchingConditions", 30, 40, new Direction[]{})); + + Assert.assertTrue("Forecast speed 30 being within [10, 40] expects true", + forecast_30_S.invoke(boolean.class, "matchingConditions", 10, 40, new Direction[]{})); + + Assert.assertTrue("Forecast speed 30 being within [20, 30] expects true", + forecast_30_S.invoke(boolean.class, "matchingConditions", 20, 30, new Direction[]{})); + + Assert.assertFalse("Forecast speed 30 outside [31, 40] expects false", + forecast_30_S.invoke(boolean.class, "matchingConditions", 31, 40, new Direction[]{})); + + Assert.assertFalse("Forecast speed 30 outside [20, 29] expects false", + forecast_30_S.invoke(boolean.class, "matchingConditions", 20, 29, new Direction[]{})); + } + + @Test + @Marking(points = 5) + public void test_200_Direction() { + + Assert.assertTrue("Forecast speed 30 being within [30, 40] and direction containing S expects true", + forecast_30_S.invoke(boolean.class, "matchingConditions", 30, 40, + new Direction[]{SE, SW, S})); + + Assert.assertFalse("Forecast speed 30 not within [31, 40] expects false", + forecast_30_S.invoke(boolean.class, "matchingConditions", 31, 40, + new Direction[]{SE, SW, S})); + + Assert.assertFalse("Forecast speed 30 being within [30, 40] but direction not containing S expects false", + forecast_30_S.invoke(boolean.class, "matchingConditions", 30, 40, + new Direction[]{N,NE,E,W,NW})); + } +} diff --git a/Klausuren/Sd1/2023winter/Solve/Readme.md b/Klausuren/Sd1/2023winter/Solve/Readme.md new file mode 100644 index 0000000000000000000000000000000000000000..caf9ae0dd53a781da24b0432c27cbb53c88352b1 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/Readme.md @@ -0,0 +1,55 @@ +# Generate and open class/method javadoc for browsing + +Grab a terminal in this IDE (By lower left icon or Alt+F12) and issue the following command: + +<pre>Exam> mvn javadoc:javadoc +... +[<span style="color:blue;font-weight:bold;">INFO</span>] Executing tasks +[<span style="color:orange;font-weight:bold;">WARNING</span>] [echo] Javadoc root at <span style="color:blue;">file:///home/.../Downloads/Exam/target/site/apidocs/index.html</span> +[<span style="color:blue;font-weight:bold;">INFO</span>] Executed tasks +...</pre> + +Click the <span style="color:blue;">file:///.../index.html</span> link opening your project's `index.html` Javadoc root +in your system's default web browser. + +# Implementation tasks + +Your project's following packages do contain implementation tasks: + +- `de.hdm_stuttgart.mi.sd1.task1` (50 Points) + +- `de.hdm_stuttgart.mi.sd1.task2` (20 points, more difficult) + +Read the generated documentation and implement the skeleton methods and classes. + +Your project's `test` branch does contain corresponding unit tests for verifying your solutions' correctness. + +# Hints + +- 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 not contribute any points at all. + +- General advice: Implement less but correctly. + +- Mind special cases i.e. `null` variable values or null values being contained in arrays. + +- In case of test failures both the IDEA debugger and logging statements are your friend. + +Executing `de.hdm_stuttgart.mi.sd1.ShowReachedPoints` in your project's test branch as a Java application +(not as Junit test!) shows your number of points reached so far. + +Do not model your implementations along unit test definitions i.e. avoid cheating this way! Such behaviour will be +regarded as an attempt at deception (Täuschungsversuch). + +# Exam system upload + +After finishing implementing: + +1. Export this project by hitting **»File âž” Export âž” Project to Zip File«**. +1. Use a self-explanatory file name like e.g. `solution1.zip`. +1. Go to your exam browser window and upload `solution1.zip` . +1. Complete by **clicking the »<span style="background: #527A35;color:white;">Speichern + weiter âžž </span>«** button. +1. Hit **<span style="background: #446684;color:white;"> 🠬 Speichern + zurück</span>** and check if your + upload is visible. +1. If you advance on implementing: Repeat steps 1. to 5.: Only the least uploaded `.zip` archive will become subject to + marking. diff --git a/Klausuren/Sd1/2023winter/Solve/pom.xml b/Klausuren/Sd1/2023winter/Solve/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..d22d8efbce697a1d1562d4f9d62f586f5e992a5d --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/pom.xml @@ -0,0 +1,129 @@ +<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_2023winter_solve</artifactId> + <version>0.9</version> + <packaging>jar</packaging> + + <name>sd1_2023winter</name> + + <url>https://freedocs.mi.hdm-stuttgart.de/sd1_sect_mavenCli.html</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <maven.compiler.release>17</maven.compiler.release> + + <freedocs.url>https://freedocs.mi.hdm-stuttgart.de</freedocs.url> + <mathjax.url>${freedocs.url}/lib/MathJax/es5/tex-chtml.js</mathjax.url> + <libhighlight.url>${freedocs.url}/lib/highlight.js</libhighlight.url> + </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>de.hdm_stuttgart.mi.exam</groupId> + <artifactId>unitmarking</artifactId> + <version>1.3</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.11.0</version> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-antrun-plugin</artifactId> + <version>3.1.0</version> + <executions> + <execution> + <phase>generate-sources</phase> + <goals> + <goal>run</goal> + </goals> + <configuration> + <target> + <echo>Javadoc root at file://${project.basedir}/target/site/apidocs/index.html</echo> + </target> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>3.5.0</version> + <configuration> + <release>17</release> + <doclint>all</doclint> + <show>public</show> + <docfilessubdirs>true</docfilessubdirs> + <addStylesheets> + <stylesheet>resources/jdocSupplement.css</stylesheet> + </addStylesheets> + + <windowtitle>Exam documentation</windowtitle> + <links> + <link>${freedocs.url}/doc/openjdk-21-doc/api/</link> + </links> + <additionalOptions> + <additionalOption>-html5 --allow-script-in-comments</additionalOption> + </additionalOptions> + <nohelp>true</nohelp> + + <header><![CDATA[ + <script type="text/javascript" src="${mathjax.url}"></script> + <script type="text/javascript" src="{@docRoot}/resources/jdocSupplement.js"></script> + + <link rel="stylesheet" href="${libhighlight.url}/styles/idea.min.css"> + <script src="${libhighlight.url}/highlight.min.js"></script> + <script type="text/javascript">hljs.highlightAll();</script>]]> + </header> + <bottom><![CDATA[Copyright © 2023 Stuttgart Media University / MI. Licensed under + <a style="font-weight:bold;" href="https://creativecommons.org/licenses/by/4.0/legalcode" target="_blank" + >Creative Commons Attribution 4.0 International Public License</a>.]]></bottom> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-assembly-plugin</artifactId> + <version>3.6.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.ShowReachedPoints</mainClass> + </manifest> + </archive> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/Klausuren/Sd1/2023winter/Solve/src/main/assembly/assembly.xml b/Klausuren/Sd1/2023winter/Solve/src/main/assembly/assembly.xml new file mode 100644 index 0000000000000000000000000000000000000000..85268e2965620878373d76337f524d8785fd0e1f --- /dev/null +++ b/Klausuren/Sd1/2023winter/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/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/Error.java b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/Error.java new file mode 100644 index 0000000000000000000000000000000000000000..608afde27906b5ce9931f90a9e310d5128cc79fc --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/Error.java @@ -0,0 +1,19 @@ +package de.hdm_stuttgart.mi.sd1.ignore_me; + +public class Error { + /** + * Summing up an int array's values + * + * @param values An array of int values + * @return The sum of all array values + */ +// public static int sum(int[] values) { +// +// int sum; +// +// for (i = 0; i <= values.length; i++) { +// sum += values[i]; +// } +// return sum; +// } +} diff --git a/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/WindSearch.java b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/WindSearch.java new file mode 100644 index 0000000000000000000000000000000000000000..fff07aa2d04e26bd3e6d9b15c7b5c6a80464cd95 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/WindSearch.java @@ -0,0 +1,26 @@ +package de.hdm_stuttgart.mi.sd1.ignore_me; + +import de.hdm_stuttgart.mi.sd1.task2.Direction; +import de.hdm_stuttgart.mi.sd1.task2.WindForecast; + +/** + * Sample code + */ +public class WindSearch { + + /** + * Main entry point + * + * @param args not used + */ + public static void main(String[] args) { + + final WindForecast forcast = new WindForecast(40, Direction.N); + + if (forcast.matchingConditions(30, 50, new Direction[]{Direction.N, Direction.NW})) { + System.out.println("Yeah, let's go for it! \uD83D\uDE0E"); + } else { + System.out.println("I hate waiting for the wind! \uD83E\uDD2C"); + } + } +} diff --git a/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLight.java b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLight.java new file mode 100644 index 0000000000000000000000000000000000000000..bf35b2a8d85609a1f91df75447007f30d677417c --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLight.java @@ -0,0 +1,97 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +/** + * <p>Valid German traffic light states.</p> + */ +public class A_TrafficLight { + /** + * <p>Traffic light state validation.</p> + * + * <p>German traffic lights feature three different colours red, yellow and green. Only the following four states + * are valid:</p> + * + * <table style="outline: 2px solid;border-spacing: 10ex 0;"> + * <caption style="background: lightgrey;text-align: left;"><em>Valid German traffic light states</em></caption> + * <tr> + * <td style="border: 2px solid black;border-radius: 10px;font-size:40px;background:black;"> + * <ul> + * <li style="color:red;"></li> + * <li style="color:black;"></li> + * <li style="color:black;"></li> + * </ul> + * </td> + * <td>Wait</td> + * <td style="border: 2px solid black;border-radius: 10px;font-size:40px;background:black;"> + * <ul> + * <li style="color:red;"></li> + * <li style="color:yellow;"></li> + * <li style="color:black;"></li> + * </ul> + * </td> + * <td>Start</td> + * <td style="border: 2px solid black;border-radius: 10px;font-size:40px;background:black;"> + * <ul> + * <li style="color:black;"></li> + * <li style="color:black;"></li> + * <li style="color:green;"></li> + * </ul> + * </td> + * <td>Go</td> + * <td style="border: 2px solid black;border-radius: 10px;font-size:40px;background:black;"> + * <ul> + * <li style="color:black;"></li> + * <li style="color:yellow;"></li> + * <li style="color:black;"></li> + * </ul> + * </td> + * <td>Stop</td> + * </tr> + * </table> + * + * <p>On contrary <em>any</em> other pattern due to e.g. broken bulbs or other technical failures is invalid:</p> + * + * <table style="outline: 2px solid;border-spacing: 10ex 0;"> + * <caption style="background:lightgrey;text-align:left;"> + * <em>Invalid German traffic light state examples</em> + * </caption> + * <tr> + * <td style="border: 2px solid black;border-radius: 10px;font-size:40px;background:black;"> + * <ul > + * <li style="color:red;"></li> + * <li style="color:black;"></li> + * <li style="color:green;"></li> + * </ul> + * </td> + * <td> + * <p>Wait or go?</p> + * <p>(Fix my</p> + * <p>control</p> + * <p>unit!)</p> + * </td> + * <td style="border: 2px solid black;border-radius: 10px;font-size:40px;background:black;"> + * <ul > + * <li style="color:black;"></li> + * <li style="color:black;"></li> + * <li style="color:black;"></li> + * </ul> + * </td> + * <td>Broken bulb(s)</td> + * <td>...</td> + * </tr> + * </table> + * + * @param red <code>true</code> represents »on«, <code>false</code> represents »off«. + * @param yellow <code>true</code> represents »on«, <code>false</code> represents »off«. + * @param green <code>true</code> represents »on«, <code>false</code> represents »off«. + * + * @return <code>true</code> if in a valid state, <code>false</code> otherwise. + */ + static public boolean stateIsValid(boolean red, boolean yellow, boolean green) { + return true == red & false == green | // (red, yellow, -) and (red, -, -) + false == red & (yellow ^ green); // ( -, yellow, -) and ( -, -, green) + + // Hint: yellow ^ green is equivalent to (yellow & !green) | (!yellow & green) + } + + private A_TrafficLight(){/* Ignore me: My sole purpose is suppressing default constructor javadoc generation */} +} diff --git a/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/B_Max.java b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/B_Max.java new file mode 100644 index 0000000000000000000000000000000000000000..ba8ac47518d0ed49d0c98f453cd515c8bd845241 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/B_Max.java @@ -0,0 +1,49 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +/** + * <p>Doing basic calculations.</p> + */ +public class B_Max { + /** + * <p>Get the largest basic calculation result of two values.</p> + * + * <p>We have four different basic calculation operations:</p> + * + * <ul style="list-style:none"> + * <li><code style="font-weight: bolder">+</code>: Addition</li> + * <li><code style="font-weight: bolder">-</code>: Subtraction</li> + * <li><code style="font-weight: bolder">*</code>: Multiplication</li> + * <li><code style="font-weight: bolder">/</code>: Division</li> + * </ul> + * + * <p>Given two values like e.g 4 and 0.1 we can construct four different basic calculation terms:</p> + * + * <ul style="list-style:none"> + * <li><code>4 + 0.1 == 4.1</code></li> + * <li><code>4 - 0.1 == 3.9</code></li> + * <li><code>4 * 0.1 == 0.4</code></li> + * <li><code style="background: lightgreen">4 / 0.1 == 40</code></li> + * </ul> + * + * <p>The above example features a maximum result value of 40 resulting from dividing 4 by 0.1 . + * Depending on both values the maximum may result from either of our four basic operations. We take a + * second set of example values 3 and -1:</p> + * + * <ul style="list-style:none"> + * <li><code>3 + (-1) == 2</code></li> + * <li><code style="background: lightgreen">3 - (-1) == 4</code></li> + * <li><code>3 * (-1) == -3</code></li> + * <li><code>3 / (-1) == -3</code></li> + * </ul> + * + * <p>This time we get a maximum of 4 by subtracting -1 from 3 .</p> + * + * @param first The first operand + * @param second The second operand + * @return The largest basic calculation result taking both arguments in their respective order. + */ + public static double getBasicCalculationMax(final double first, final double second) { + return Math.max(Math.max(Math.max(first + second, first - second), first * second), first / second); + } + private B_Max(){/* Ignore me, suppressing implicit default constructor Javadoc HTML generation */} +} diff --git a/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/C_WebUrl.java b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/C_WebUrl.java new file mode 100644 index 0000000000000000000000000000000000000000..5c678eeb6bbe2b522dba02e281a027d155e22938 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/C_WebUrl.java @@ -0,0 +1,83 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +/** + * <p>Handle web addresses.</p> + */ +public class C_WebUrl { + + /** + * <p>Accessing web sites e.g. <code>www.wikipedia.org</code> requires entering the address in a web browser:</p> + * + * <img style="outline: 2px solid;" + * src="doc-files/weburlBlank.png" alt="A web address without protocol specification" > + * + * <p>Entering <code>www.wikipedia.org</code> fulfills its purpose. However behind the scenes either a + * <code>http://</code> or <code>https://</code> protocol specification is being silently prepended:</p> + * + * <img style="outline: 2px solid;" + * src="doc-files/weburlProtocol.png" alt="A web address including a protocol specification"> + * + * <p>The current method adds a missing protocol specification according to the following rules:</p> + * + * <ul> + * <li>An address already starting with either <code>http://</code> or <code>https://</code> is just being + * copied.</li> + * + * <li> + * <p>An address not starting with either <code>http://</code> or <code>https://</code> receives a + * protocol prefix according to the <code>tlsSupport</code> parameter.</p> + * </li> + * </ul> + * <p>Some examples:</p> + * <table class="goikTableDefaults"> + * <caption>Optional protocol prefix examples for <code>www.wikipedia.org</code></caption> + * <tr> + * <th><code>address</code></th> + * <th><code>tlsSupport</code></th> + * <th>Return value</th> + * </tr> + * <tr> + * <td style="color:blue"><code>www.wikipedia.org</code></td> + * <td><code style="color:red">true</code></td> + * <td><code style="color:red">https</code>://<code style="color:blue">www.wikipedia.org</code></td> + * </tr> + * <tr> + * <td style="color:blue"><code>www.wikipedia.org</code></td> + * <td><code style="color:red">false</code></td> + * <td><code style="color:red">http</code>://<code style="color:blue">www.wikipedia.org</code></td> + * </tr> + * <tr> + * <td style="color:blue"><code>http://www.wikipedia.org</code></td> + * <td>Protocol specification <code>http://</code> present, value irrelevant</td> + * <td style="color:blue"><code>http://www.wikipedia.org</code></td> + * </tr> + * <tr> + * <td style="color:blue"><code>https://www.wikipedia.org</code></td> + * <td>Protocol specification <code>https://</code> present, value irrelevant</td> + * <td style="color:blue"><code>https://www.wikipedia.org</code></td> + * </tr> + * </table> + * + * @param address A website's address. May either be a raw name or a full http/https prefixed protocol address. + * @param tlsSupport If <code>true</code> the server supports + * <code><span style="color:red">https</span>://...</code> connections. Otherwise, only + * <code><span style="color:red">http</span>://...</code> is being supported. + * + * @return A fully <code>http://</code> or <code>https://</code> prefixed protocol address. + * + * <section class="implementationHints"> + * <h4 class="implementationHints">Hint:</h4> + * + * <p>{@link String#startsWith(String)}</p> + * </section> + */ + public static String amendWebAddress(final String address, final boolean tlsSupport) { + if (address.startsWith("http://") | address.startsWith("https://")) { + return address; + } else if (tlsSupport){ + return "https://" + address; + } else { + return "http://" + address; + } + } +} diff --git a/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/D_Array.java b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/D_Array.java new file mode 100644 index 0000000000000000000000000000000000000000..c2e8c019e1f2da2347cb7924ab6c805c73d34345 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/D_Array.java @@ -0,0 +1,77 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +/** + * Array helper method. + */ +public class D_Array { + + /** + * The special value -1 indicating two arrays are not being related by any sequence of right cyclic rotations. + * Example: {1, 2} and {1, 3}. + */ + static public final int NOT_CYCLICALLY_RELATED = -1 ; + + /** + * <p>Part 2: Check two arrays for being related by an integer number of successive right cyclic rotations or not.</p> + * + * <p>Consider a right cyclic array rotating example:</p> + * + * <pre> + * <span style="color:red">â¬â”€â”€â”€â”€â”€â”</span> + * {1, 7, <span style="color:blue">3</span>} ⇨ {<span style="color:blue">3</span>, 1, 7} + * <span style="color:red">⤻ ⤻</span> + * </pre> + * + * <p>The arrays <code>{1, 7, 3}</code> and <code>{3, 1, 7}</code> are thus being related by one right + * cyclic rotation.</p> + * + * <p>Arrays may also be related by a succession of multiple right cyclic rotations. Example:</p> + * + * <p><code>{1, 8, 3, 4}</code> and <code>{3, 4, 1, 8}</code> are being related by a sequence of two right cyclic + * rotations:</p> + * + * <pre> + * <span style="color:red"> â¬â”€â”€â”€â”€â”€â”€â”€â”€â” â¬â”€â”€â”€â”€â”€â”€â”€â”€â”</span> + * {1, 8, 3, <span style="color:blue">4</span>} ⇨ {<span style="color:blue">4</span>, 1, 8, <span + * style="color:orange">3</span>} ⇨ {<span style="color:orange">3</span>, <span style="color:blue">4</span>, 1, 8} + * <span style="color:red"> ⤻ ⤻ ⤻ ⤻ ⤻ ⤻</span> + * </pre> + * + * <p>In this case a value of 2 rotations is being returned.</p> + * + * <h4>Special cases: </h4> + * + * <ul> + * <li>Two identical arrays are being related by zero rotations.</li> + * <li>Two arrays of different size are always unrelated / {@link #NOT_CYCLICALLY_RELATED} .</li> + * </ul> + * + * @param array1 The first array. Values must remain untouched. + * @param array2 The second array. Values must remain untouched. + * + * @return Either the number of right cyclic rotations or the special value {@link #NOT_CYCLICALLY_RELATED} if both + * arrays are not being related by a sequence of cyclic rotations. + */ + static public int isRotatedBy(final int[] array1, int[] array2) { + final int length = array1.length; + if (length == array2.length) { + if (0 == length) { + return 0; + } + for (int rotation = 0; rotation < length; rotation++) { + boolean allValuesEqual = true; + for (int i = 0; i < length; i++) { + if (array1[i] != array2[(i + rotation) % length]) { + allValuesEqual = false; + break; + } + } + if (allValuesEqual) { + return rotation; + } + } + } + return NOT_CYCLICALLY_RELATED; // No rotation found + } + private D_Array(){/* Ignore me, suppressing implicit default constructor Javadoc HTML generation */} +} diff --git a/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..6152c2c29cb6d00991e889f9f08151683f7245e0 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java @@ -0,0 +1,22 @@ +/** + * <p>Classes here mostly (if not completely) contain static methods to be implemented.</p> + * + * <p>The ordering being implied by (test) class names and related methods reflect the author's opinion about ascending + * implementation difficulty. You are free to proceed differently. Hints:</p> + * + * <ul> + * <li>Run <code>mvn javadoc:javadoc</code> and open the generated + * <code><projectroot>/target/site/apidocs/index.html</code> file in your browser of choice.</li> + * + * <li>Read the generated documentation thoroughly. Make sure you do understand the intended method behaviour prior + * to implementing.</li> + * + * <li>Use the corresponding unit tests from your project's »test« branch checking your implementation's + * correctness. Executing <code>de.hdm_stuttgart.mi.sd1.ShowReachedPoints</code> reveals your number + * of examination points reached so far.</li> + * + * <li>The debugger is your friend</li> + * </ul> + * + */ +package de.hdm_stuttgart.mi.sd1.task1; \ No newline at end of file diff --git a/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/Direction.java b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/Direction.java new file mode 100644 index 0000000000000000000000000000000000000000..9ecc88117974116821a32a6fd5e72deea8a64c49 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/Direction.java @@ -0,0 +1,42 @@ +package de.hdm_stuttgart.mi.sd1.task2; + +/** <p>The 8 main wind directions.</p> + */ +public enum Direction { + /** + * North + */ + N, + /** + * Northeast + */ + NE, + /** + * East + */ + E, + + /** + * Southeast + */ + SE, + + /** + * South + */ + S, + + /** + * Southwest + */ + SW, + + /** + * West + */ + W, + /** + * Northwest + */ + NW +} diff --git a/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/WindForecast.java b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/WindForecast.java new file mode 100644 index 0000000000000000000000000000000000000000..640cc343c38ff93c06da42e25d28b5cf9fa1456c --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/WindForecast.java @@ -0,0 +1,64 @@ +package de.hdm_stuttgart.mi.sd1.task2; + +/** + * <p>Matching wind forecast conditions</p> + */ +public class WindForecast { + + private final Direction direction; + + private final int windSpeed; + + /** + * <p>Wind forecast by range and directions.</p> + * + * @param windSpeed Expected wind speed in Km/h. + * @param directions The main wid direction to be expected + */ + public WindForecast(final int windSpeed, final Direction directions) { + this.direction = directions; + this.windSpeed = windSpeed; + } + + /** + * <p>Check for matching conditions.</p> + * + * <p>Many water sports addicts depend on suitable wind conditions being described by wind speed and + * optionally wind direction.</p> + * + * <p>As an example a kitesurfer might want to get notified if the wind forecast at his or her suitable spot predicts + * wind ranging from 30 Km/h to 50 Km/h in speed and coming either from northern or northwestern direction. The + * wind prediction is wind at 40 Km from north. Corresponding code sample:</p> + * + * <pre><code class="java"> final WindForecast forecast = new WindForecast(40, Direction.N); + * + * if (forecast.matchingConditions(30, 50, new Direction[]{Direction.N, Direction.NW})) { + * System.out.println("Yeah, let's go for it! \uD83D\uDE0E"); + * else { + * System.out.println("I hate waiting for the wind! \uD83E\uDD2C"); + * }</code></pre> + * + * @param speedMinimum Minimum required wind speed. + * @param speedMaximum Maximum tolerable wind speed. + * @param directions List of favourable wind directions + * @return <code>true</code> if current wind's speed and one of the provided directions match the + * {@link #WindForecast(int, Direction)} criteria, <code>false</code> otherwise. + */ + public boolean matchingConditions(final int speedMinimum, final int speedMaximum, final Direction[] directions) { + + if (windSpeed < speedMinimum || speedMaximum < windSpeed) { + return false; + } + + if (0 == directions.length) { // Direction does not matter to customer + return true; + } else { + for (final Direction d: directions) { + if (d == direction) { + return true; + } + } + return false; + } + } +} diff --git a/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..b12e6627a104b0c0cc4c7151c2aef643bf94070f --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java @@ -0,0 +1,18 @@ +/** + * <p>This package hosts more advanced implementation tasks.</p> + * + * <ul> + * <li>Run <code>mvn javadoc:javadoc</code> and open the generated + * <code><projectroot>/target/site/apidocs/index.html</code> file in your browser of choice.</li> + * + * <li>Read the generated documentation thoroughly. Make sure you do understand the intended method behaviour prior + * to implementing.</li> + * + * <li>Use the corresponding unit tests from your project's »test« branch checking your implementation's + * correctness. Executing <code>de.hdm_stuttgart.mi.sd1.ShowReachedPoints</code> reveals your number + * of examination points reached so far.</li> + * + * <li>The debugger is your friend</li> + * </ul> + */ +package de.hdm_stuttgart.mi.sd1.task2; \ No newline at end of file diff --git a/Klausuren/Sd1/2023winter/Solve/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/weburlBlank.png b/Klausuren/Sd1/2023winter/Solve/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/weburlBlank.png new file mode 100644 index 0000000000000000000000000000000000000000..01376dac6c420ef680afbbb82f147dfa569b0766 Binary files /dev/null and b/Klausuren/Sd1/2023winter/Solve/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/weburlBlank.png differ diff --git a/Klausuren/Sd1/2023winter/Solve/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/weburlProtocol.png b/Klausuren/Sd1/2023winter/Solve/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/weburlProtocol.png new file mode 100644 index 0000000000000000000000000000000000000000..a9c648b8d28812201ab15b272b7e953c7c0fb642 Binary files /dev/null and b/Klausuren/Sd1/2023winter/Solve/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/weburlProtocol.png differ diff --git a/Klausuren/Sd1/2023winter/Solve/src/main/javadoc/resources/fonts/dejavu.css b/Klausuren/Sd1/2023winter/Solve/src/main/javadoc/resources/fonts/dejavu.css new file mode 100644 index 0000000000000000000000000000000000000000..4fec2b593cdcc719fd7edd6744a33a3395ca8401 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/src/main/javadoc/resources/fonts/dejavu.css @@ -0,0 +1,3 @@ +/* shame on you, javadoc! Still providing +@import url('resources/fonts/dejavu.css') line in stylesheet.css +*/ \ No newline at end of file diff --git a/Klausuren/Sd1/2023winter/Solve/src/main/javadoc/resources/jdocSupplement.css b/Klausuren/Sd1/2023winter/Solve/src/main/javadoc/resources/jdocSupplement.css new file mode 100644 index 0000000000000000000000000000000000000000..08840cdbf55d1f43368245d0a965659c4411b2ee --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/src/main/javadoc/resources/jdocSupplement.css @@ -0,0 +1,72 @@ +/* Javadoc extensions: */ + +ul > li > ul { + list-style-type: circle; +} + +table.goikTableDefaults, +table.goikTableDefaults>caption, +table.goikTableDefaults>tr>th, +table.goikTableDefaults>tr>td, +table.goikTableDefaults>tbody>tr>th, +table.goikTableDefaults>tbody>tr>td { + border: 2px solid black; + border-collapse: collapse; + padding: 1ex; + vertical-align: top; +} + +table.goikTableDefaults>caption { + /* border-top-style: solid; border-left-style: solid; border-right-style: solid' */ + border-bottom-style: none; + font-weight: bold; + background:#dee3e9; + text-align:left; + padding:8px 3px 3px 7px; +} + +table.goikTableDefaults>tbody>tr>td { + vertical-align:top; +} +table.goikTableDefaults { + border-spacing: 0px !important; +} + +table.indexTable { + border-collapse: collapse; + border-style: hidden; +} + +table.indexTable caption { + text-align: left; +} + +table.indexTable td, table.indexTable th { + border: 1px solid black; + padding: 0.5ex; +} + +em { + font-weight: bold; + font-style: normal; +} +section.implementationHints>h3 { + font-weight: bold; + background-color: rgb(222, 227, 233); +} + +code { + white-space: pre; +} + +.implementationHints { + background-color: hsl(120, 100%, 95%) !important; +} + +.myRed { + color: red; +} + +.myGreen { + color: limegreen; +} diff --git a/Klausuren/Sd1/2023winter/Solve/src/main/javadoc/resources/jdocSupplement.js b/Klausuren/Sd1/2023winter/Solve/src/main/javadoc/resources/jdocSupplement.js new file mode 100644 index 0000000000000000000000000000000000000000..97911e5581090aac5e37323427450f8c8c8a3f94 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/src/main/javadoc/resources/jdocSupplement.js @@ -0,0 +1,7 @@ +for(var i in document.links) { + var link = document.links[i]; + if (link.href && link.href.indexOf('http') === 0) { + link.target = '_blank'; + } +} + diff --git a/Klausuren/Sd1/2023winter/Solve/src/main/resources/log4j2.xml b/Klausuren/Sd1/2023winter/Solve/src/main/resources/log4j2.xml new file mode 100644 index 0000000000000000000000000000000000000000..130f87a144c4eb0107a846e580c8fa7f5e819fc1 --- /dev/null +++ b/Klausuren/Sd1/2023winter/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/2023winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/ShowReachedPoints.java b/Klausuren/Sd1/2023winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/ShowReachedPoints.java new file mode 100644 index 0000000000000000000000000000000000000000..c408929ee4caf2dcbc878db31e655e4cda14a3bb --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/ShowReachedPoints.java @@ -0,0 +1,26 @@ +package de.hdm_stuttgart.mi.sd1; + +import de.hdm_stuttgart.mi.exam.unitmarking.RunTests; + +import de.hdm_stuttgart.mi.sd1.task1.A_TrafficLightTest; +import de.hdm_stuttgart.mi.sd1.task1.B_MaxTest; +import de.hdm_stuttgart.mi.sd1.task1.C_WebUrlTest; +import de.hdm_stuttgart.mi.sd1.task1.D_ArrayTest; + +import de.hdm_stuttgart.mi.sd1.task2.WindForecastTest; + +public class ShowReachedPoints { + + /** + * Revealing total number of reached points from all tasks. + * + * @param args Unused + */ + public static void main(String[] args) { + RunTests.exec( + "Task 1", + A_TrafficLightTest.class, B_MaxTest.class, C_WebUrlTest.class, D_ArrayTest.class + ); + RunTests.exec("Task 2", WindForecastTest.class); + } +} diff --git a/Klausuren/Sd1/2023winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLightTest.java b/Klausuren/Sd1/2023winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLightTest.java new file mode 100644 index 0000000000000000000000000000000000000000..3e3960d0433ee029f306e6a74bd417c112a6b177 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLightTest.java @@ -0,0 +1,28 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import static de.hdm_stuttgart.mi.sd1.task1.A_TrafficLight.stateIsValid; + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class A_TrafficLightTest extends ExaminationTestDefaults { + + @Test + @Marking(points = 18) + public void test_100() { + Assert.assertFalse( stateIsValid(false, false, false)); + Assert.assertTrue( stateIsValid(false, false, true)); + Assert.assertTrue( stateIsValid(false, true, false)); + Assert.assertFalse( stateIsValid(false, true, true)); + Assert.assertTrue( stateIsValid(true, false, false)); + Assert.assertFalse( stateIsValid(true, false, true)); + Assert.assertTrue( stateIsValid(true, true, false)); + Assert.assertFalse( stateIsValid(true, true, true)); + } +} diff --git a/Klausuren/Sd1/2023winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task1/B_MaxTest.java b/Klausuren/Sd1/2023winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task1/B_MaxTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d1e1779072d56c936ec178c43924e44fa6b20225 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task1/B_MaxTest.java @@ -0,0 +1,37 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class B_MaxTest extends ExaminationTestDefaults { + static final public double PRECISION = 1.E-12; + + @Test + @Marking(points = 15) + public void test() { + assertMaximum(12, 4, 3, '*'); + assertMaximum(5, 2, -3, '-'); + assertMaximum(5.1, 0.1, 5, '+'); + assertMaximum(35, 7, 0.2, '/'); + assertMaximum(-1.4,-7, 0.2, '*'); + assertMaximum(4,2, 2, '+'); + } + + private static void assertMaximum(final double expected, final double first, final double second, char operation) { + + final StringBuilder errMsg = new StringBuilder("Expected maximum is " + expected + " == " + first + " " + + operation + " "); + + if (second < 0) { + errMsg.append("(" + second + ")"); + } else { + errMsg.append(second); + } + Assert.assertEquals(errMsg.toString(), expected, B_Max.getBasicCalculationMax(first, second), PRECISION); + } +} diff --git a/Klausuren/Sd1/2023winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task1/C_WebUrlTest.java b/Klausuren/Sd1/2023winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task1/C_WebUrlTest.java new file mode 100644 index 0000000000000000000000000000000000000000..4df40473b27a8d74580319e3d44529c7ff71844c --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task1/C_WebUrlTest.java @@ -0,0 +1,66 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + + + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class C_WebUrlTest extends ExaminationTestDefaults { + + static private final String dnsNames[] = { + "www.der-postillon.com", "www.duh.de", "www.amnesty.org" + }; + + + @Test + @Marking(points = 14) + public void test() { + + for(final String dns: dnsNames) { + final String + httpUrl = "http://" + dns, + httpsUrl = "https://" + dns, + + actualByHttpsTlsTrue = C_WebUrl.amendWebAddress(httpsUrl, true), + actualByHttpsTlsFalse = C_WebUrl.amendWebAddress(httpsUrl, false), + + actualByHttpTlsTrue = C_WebUrl.amendWebAddress(httpUrl, true), + actualByHttpTlsFalse = C_WebUrl.amendWebAddress(httpUrl, false), + + actualByDnsTlsTrue = C_WebUrl.amendWebAddress(dns, true), + actualByDnsTlsFalse = C_WebUrl.amendWebAddress(dns, false); + + Assert.assertEquals( + "Passing '" + httpsUrl + "' should return '" + httpsUrl + "' rather than '" + actualByHttpsTlsTrue + "'", + httpsUrl, actualByHttpsTlsTrue); + + Assert.assertEquals( + "Passing '" + httpsUrl + "' should return '" + httpsUrl + "' rather than '" + actualByHttpsTlsFalse + "'", + httpsUrl, actualByHttpsTlsFalse); + + Assert.assertEquals( + "Passing '" + httpUrl + "' should return '" + httpUrl + "' rather than '" + actualByHttpTlsTrue + "'", + httpUrl, actualByHttpTlsTrue); + + Assert.assertEquals( + "Passing '" + httpUrl + "' should return '" + httpUrl + "' rather than '" + actualByHttpTlsFalse + "'", + httpUrl, actualByHttpTlsFalse); + + + Assert.assertEquals( + "Passing '" + dns + "' when tlsSupport is 'true' should return '" + httpsUrl + "' rather than " + actualByDnsTlsTrue, + httpsUrl, actualByDnsTlsTrue); + + Assert.assertEquals( + "Passing '" + dns + "' when tlsSupport is 'false' should return '" + httpUrl + "' rather than " + actualByDnsTlsFalse, + httpUrl, actualByDnsTlsFalse); + + } + } +} diff --git a/Klausuren/Sd1/2023winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task1/D_ArrayTest.java b/Klausuren/Sd1/2023winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task1/D_ArrayTest.java new file mode 100644 index 0000000000000000000000000000000000000000..24b763ada8c1814fa8ec239998836bee384e0f9d --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task1/D_ArrayTest.java @@ -0,0 +1,118 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import java.util.Arrays; + +import static de.hdm_stuttgart.mi.sd1.task1.D_Array.NOT_CYCLICALLY_RELATED; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class D_ArrayTest extends ExaminationTestDefaults { + + private static void assertRelatedByRotation(final int expectedRotation, final int[] array1, int[] array2) { + + final int[] array1Copy = Arrays.copyOf(array1, array1.length), + array2Copy = Arrays.copyOf(array2, array2.length); + + final String errorMessage; + if (NOT_CYCLICALLY_RELATED == expectedRotation) { + errorMessage = Arrays.toString(array1) + " and " + Arrays.toString(array2) + + " are not being cyclically related."; + } else { + errorMessage = Arrays.toString(array1) + " and " + Arrays.toString(array2) + + " are being cyclically related by " + expectedRotation + " right rotation(s)."; + } + Assert.assertEquals(errorMessage, expectedRotation, D_Array.isRotatedBy(array1, array2)); + + Assert.assertArrayEquals("You must not change values in array1 parameter", array1Copy, array1); + Assert.assertArrayEquals("You must not change values in array2 parameter", array2Copy, array2); + } + + @Test + public void test010_Minimum() { + assertRelatedByRotation(0, new int[]{}, new int[]{}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{}, new int[]{1}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{3}, new int[]{}); + } + @Test + public void test020One() { + assertRelatedByRotation(0, new int[]{77}, new int[]{77}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{8}, new int[]{77}); + } + + @Test + @Marking(points = 2) + public void test030Two() { + assertRelatedByRotation(0, new int[]{-1, 5}, new int[]{-1, 5}); + assertRelatedByRotation(1, new int[]{-1, 5}, new int[]{5, -1}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{-1, 5}, new int[]{-5, 1}); + } + @Test + @Marking(points = 2) + public void test040Three() { + assertRelatedByRotation( 0, new int[]{2, -6, 9}, new int[]{ 2, -6, 9}); + assertRelatedByRotation( 1, new int[]{2, -6, 9}, new int[]{ 9, 2, -6}); + assertRelatedByRotation( 2, new int[]{2, -6, 9}, new int[]{-6, 9, 2}); + + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{2, -6, 9}, new int[]{ 2, 9, -6}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{2, -6, 9}, new int[]{-6, 2, 9}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{2, -6, 9}, new int[]{-6, 2}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{-1, 2, 4}, new int[]{-1, 2, 5}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{-1, 2, 4}, new int[]{-2, 2, 4}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{-1, 2, 4}, new int[]{-1, 3, 4}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{-1, 2, 4}, new int[]{-1, 3, 4, 3}); + assertRelatedByRotation(NOT_CYCLICALLY_RELATED, new int[]{-1, 2, 4, 1}, new int[]{-1, 3, 4}); + } + @Test + @Marking(points = 2) + public void test050Twenty() { + assertRelatedByRotation( 0, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}); + + assertRelatedByRotation( 1, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{10, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + + assertRelatedByRotation( 2, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{9, 10, 1, 2, 3, 4, 5, 6, 7, 8}); + + assertRelatedByRotation( 3, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{8, 9, 10, 1, 2, 3, 4, 5, 6, 7}); + + assertRelatedByRotation( 4, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{7, 8, 9, 10, 1, 2, 3, 4, 5, 6}); + + assertRelatedByRotation( 5, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{6, 7, 8, 9, 10, 1, 2, 3, 4, 5}); + + assertRelatedByRotation( 6, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{5, 6, 7, 8, 9, 10, 1, 2, 3, 4}); + + assertRelatedByRotation( 7, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{4, 5, 6, 7, 8, 9, 10, 1, 2, 3}); + + assertRelatedByRotation( 8, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{3, 4, 5, 6, 7, 8, 9, 10, 1, 2}); + + assertRelatedByRotation( 9, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{2, 3, 4, 5, 6, 7, 8, 9, 10, 1}); + + assertRelatedByRotation( NOT_CYCLICALLY_RELATED, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{1, 2, 3, 4, 6, 5, 7, 8, 9, 10}); + + assertRelatedByRotation( NOT_CYCLICALLY_RELATED, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{1, 2, 3, 4, 6, 5, 7, 8, 9}); + + assertRelatedByRotation( NOT_CYCLICALLY_RELATED, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, + /* */ new int[]{1, 2, 3, 4, 6, 5, 7, 8, 9, 10}); + + assertRelatedByRotation( NOT_CYCLICALLY_RELATED, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + /* */ new int[]{}); + + + } +} diff --git a/Klausuren/Sd1/2023winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task2/WindForecastTest.java b/Klausuren/Sd1/2023winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task2/WindForecastTest.java new file mode 100644 index 0000000000000000000000000000000000000000..00f5f04be115f99a51be06a185076eebd2760190 --- /dev/null +++ b/Klausuren/Sd1/2023winter/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/task2/WindForecastTest.java @@ -0,0 +1,56 @@ +package de.hdm_stuttgart.mi.sd1.task2; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.exam.unitmarking.reflect.ObjectWrapper; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import static de.hdm_stuttgart.mi.sd1.task2.Direction.*; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) + +public class WindForecastTest extends ExaminationTestDefaults { + + final ObjectWrapper<WindForecast> forecast_30_S = + new ObjectWrapper<>(WindForecast.class, 30, S); + + @Test + @Marking(points = 10) + public void test_100_noDirection() { + + Assert.assertTrue("Forecast speed 30 being within [30, 40] expects true", + forecast_30_S.invoke(boolean.class, "matchingConditions", 30, 40, new Direction[]{})); + + Assert.assertTrue("Forecast speed 30 being within [10, 40] expects true", + forecast_30_S.invoke(boolean.class, "matchingConditions", 10, 40, new Direction[]{})); + + Assert.assertTrue("Forecast speed 30 being within [20, 30] expects true", + forecast_30_S.invoke(boolean.class, "matchingConditions", 20, 30, new Direction[]{})); + + Assert.assertFalse("Forecast speed 30 outside [31, 40] expects false", + forecast_30_S.invoke(boolean.class, "matchingConditions", 31, 40, new Direction[]{})); + + Assert.assertFalse("Forecast speed 30 outside [20, 29] expects false", + forecast_30_S.invoke(boolean.class, "matchingConditions", 20, 29, new Direction[]{})); + } + + @Test + @Marking(points = 5) + public void test_200_Direction() { + + Assert.assertTrue("Forecast speed 30 being within [30, 40] and direction containing S expects true", + forecast_30_S.invoke(boolean.class, "matchingConditions", 30, 40, + new Direction[]{SE, SW, S})); + + Assert.assertFalse("Forecast speed 30 not within [31, 40] expects false", + forecast_30_S.invoke(boolean.class, "matchingConditions", 31, 40, + new Direction[]{SE, SW, S})); + + Assert.assertFalse("Forecast speed 30 being within [30, 40] but direction not containing S expects false", + forecast_30_S.invoke(boolean.class, "matchingConditions", 30, 40, + new Direction[]{N,NE,E,W,NW})); + } +}