diff --git a/Sd1/P/Etest/MaxArrayDiff/Solution/.gitignore b/Sd1/P/Etest/MaxArrayDiff/Solution/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..4e247eee2103b4d4a35eba38166587fee1391f0e --- /dev/null +++ b/Sd1/P/Etest/MaxArrayDiff/Solution/.gitignore @@ -0,0 +1,4 @@ +/.settings +/target +/.classpath +/.project diff --git a/Sd1/P/Etest/MaxArrayDiff/Solution/pom.xml b/Sd1/P/Etest/MaxArrayDiff/Solution/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..35aaf2a423b2c78be76ecaa6ba65dd10634bc853 --- /dev/null +++ b/Sd1/P/Etest/MaxArrayDiff/Solution/pom.xml @@ -0,0 +1,58 @@ +<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.de.sd1</groupId> + <artifactId>maxarraydiff</artifactId> + <version>2.0</version> + <packaging>jar</packaging> + + <name>vowel</name> + <url>http://www.mi.hdm-stuttgart.de/freedocs/topic/de.hdm_stuttgart.mi.swd1/index.html</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <javadocDestdir>~/tmp</javadocDestdir> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.3.2</version> + <configuration> + <source>1.7</source> + <target>1.7</target> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>2.9.1</version> + <configuration> + <linksource>true</linksource> + </configuration> + </plugin> + </plugins> + + <resources> + <resource> + <directory>src/main/java</directory> + <includes> + <include> **/*.properties</include> + </includes> + </resource> + </resources> + </build> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.11</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/Sd1/P/Etest/MaxArrayDiff/Solution/src/main/java/de/hdm_stuttgart/mi/sd1/maxarraydiff/Calc.java b/Sd1/P/Etest/MaxArrayDiff/Solution/src/main/java/de/hdm_stuttgart/mi/sd1/maxarraydiff/Calc.java new file mode 100644 index 0000000000000000000000000000000000000000..eb1e4a4bb25b8276c6c953880a7f1cbee59bc9a1 --- /dev/null +++ b/Sd1/P/Etest/MaxArrayDiff/Solution/src/main/java/de/hdm_stuttgart/mi/sd1/maxarraydiff/Calc.java @@ -0,0 +1,33 @@ +package de.hdm_stuttgart.mi.sd1.maxarraydiff; + +/** + * Array calculations. + * + */ +public class Calc { + + /** + * Calculate the maximum of all mutual absolute + * difference values. Example: + * + * values = {1, 7, 2, -3, 4} + * + * The maximum is 7 - (-3) = 10 + * + * + * @param values An unordered list of integer values + * @return The number of vowels being contained in s. + */ + public static int maxArrayDiff (final int [] values) { + + int maxDiff = 0; + for (int i = 0; i < values.length; i++) { + for (int j = i + 1; j < values.length; j++) { + if (maxDiff < Math.abs(values[i] -values[j])) { + maxDiff = Math.abs(values[i] -values[j]); + } + } + } + return maxDiff; + } +} diff --git a/Sd1/P/Etest/MaxArrayDiff/Solution/src/main/java/de/hdm_stuttgart/mi/sd1/maxarraydiff/package-info.java b/Sd1/P/Etest/MaxArrayDiff/Solution/src/main/java/de/hdm_stuttgart/mi/sd1/maxarraydiff/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..caccbbf6b1a31ade531cea571e2c75c823ffb6db --- /dev/null +++ b/Sd1/P/Etest/MaxArrayDiff/Solution/src/main/java/de/hdm_stuttgart/mi/sd1/maxarraydiff/package-info.java @@ -0,0 +1,5 @@ +/** + * Computing array value differences + * + */ +package de.hdm_stuttgart.mi.sd1.maxarraydiff; \ No newline at end of file diff --git a/Sd1/P/Etest/MaxArrayDiff/Solution/src/test/java/de/hdm_stuttgart/mi/sd1/fraction/CalcTest.java b/Sd1/P/Etest/MaxArrayDiff/Solution/src/test/java/de/hdm_stuttgart/mi/sd1/fraction/CalcTest.java new file mode 100644 index 0000000000000000000000000000000000000000..acca1325c9957db507ad98b5d3039f0dffb5ee3b --- /dev/null +++ b/Sd1/P/Etest/MaxArrayDiff/Solution/src/test/java/de/hdm_stuttgart/mi/sd1/fraction/CalcTest.java @@ -0,0 +1,33 @@ +package de.hdm_stuttgart.mi.sd1.fraction; + +import org.junit.Assert; +import org.junit.Test; + +import de.hdm_stuttgart.mi.sd1.maxarraydiff.Calc; + +@SuppressWarnings("javadoc") +public class CalcTest { + + @Test public void testZero() { + Assert.assertEquals(0, Calc.maxArrayDiff(new int[]{})); + } + + @Test public void testOne() { + Assert.assertEquals(0, Calc.maxArrayDiff(new int[]{-3})); + } + + @Test public void testTwo() { + Assert.assertEquals(4, Calc.maxArrayDiff(new int[]{1, -3})); + } + + @Test public void testThree() { + Assert.assertEquals(13, Calc.maxArrayDiff(new int[]{1, 4, -9})); + } + + @Test public void testMulti() { + Assert.assertEquals(17, Calc.maxArrayDiff(new int[]{ -1, 0, -5, 3, 5, 12, 8})); + } + + + +}