Skip to content
Snippets Groups Projects
Commit 2b89f297 authored by Goik Martin's avatar Goik Martin
Browse files

Arraydif example

parent e51cd37b
No related branches found
No related tags found
No related merge requests found
/.settings
/target
/.classpath
/.project
<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>
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;
}
}
/**
* Computing array value differences
*
*/
package de.hdm_stuttgart.mi.sd1.maxarraydiff;
\ No newline at end of file
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}));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment