Skip to content
Snippets Groups Projects
Verified Commit 776f9984 authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Added starter code for Week 10 assignments

parent d5b2f2e7
No related branches found
No related tags found
No related merge requests found
# Mac file finder metadata
.DS_Store
# Windows file metadata
._*
# Thumbnail image caches
Thumbs.db
ethumbs.db
# MS Office temporary file
~*
# Emacs backup file
*~
# Common
[Bb]in/
[Bb]uild/
[Oo]bj/
[Oo]ut/
[Tt]mp/
[Xx]86/
[Ii][Aa]32/
[Xx]64/
[Xx]86_64/
[Xx]86-64/
[Aa]rm
[Aa]32
[Tt]32
[Aa]64
*.tmp
*.bak
*.bk
*.swp
# Java files
*.class
javadoc/
# Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# JetBrains (IntelliJ IDEA, PyCharm, etc) files
.idea/
cmake-build-*/
*.iml
*.iws
*.ipr
# Eclipse files
.settings/
.project
.classpath
.buildpath
.loadpath
.factorypath
local.properties
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.unl.cse.soft160.isbn</groupId>
<artifactId>isbn</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>isbn</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
package edu.unl.cse.soft160.isbn.implementation;
public class ISBNVerifier {
private static String cleanISBN(String isbn) {
// remove non-numerics
String clean = "";
for (int i = 0; i < isbn.length(); i++) {
Character character = isbn.charAt(i);
if (Character.isDigit(character)) {
clean += character;
}
}
return clean;
}
private static boolean hasCorrectCheckDigit(String isbn) {
int checksum = 0;
for (int i = 0; i < 13; i++) {
char character = isbn.charAt(i);
int digit = Character.getNumericValue(character);
if (i % 2 == 0) {
checksum = checksum + digit;
} else {
checksum = checksum + (digit * 3);
}
}
return checksum % 10 == 0;
}
public static boolean isValidISBN(String inputISBN) {
String isbn = cleanISBN(inputISBN);
return isbn.length() == 13 && hasCorrectCheckDigit(isbn);
}
}
package edu.unl.cse.soft160.isbn.meta;
import java.util.Random;
import edu.unl.cse.soft160.isbn.implementation.ISBNVerifier;
public class GenerateVerifierTestSuite {
private static Random random = new Random();
public enum TestType {
VALID, INVALID,
}
private static int getRandomDigit() {
return random.nextInt(10);
}
private static TestType getRandomType() {
return TestType.values()[random.nextInt(TestType.values().length)];
}
private static String corruptString(String string) {
char nonDigit = (char) ('A' + random.nextInt('Z' + 1 - 'A'));
int index = random.nextInt(string.length());
return string.substring(0, index) + nonDigit + string.substring(index + 1);
}
private static void printResults(String testCases, int validISBNCount, int invalidISBNCount) {
System.out.println(testCases);
}
private static String createTestCase(String isbn, TestType type, int testCounter) {
String truthString = Boolean.toString(type == TestType.VALID);
String test = "\t@Test\n\tpublic void test" + testCounter + "() {\n";
test += "\t\tboolean result = ISBNVerifier.isValidISBN(\"" + isbn + "\");\n";
test += "\t\tassert" + truthString.substring(0,1).toUpperCase() + truthString.substring(1) + "(result);\n";
test += "\t}\n\n";
return test;
}
private static String delimitISBN(String isbn, String delimiter) {
String result = isbn.substring(0, 3) + delimiter;
result += isbn.substring(3, 4) + delimiter;
result += isbn.substring(4, 7) + delimiter;
result += isbn.substring(7, 12) + delimiter;
result += isbn.substring(12, 13);
return result;
}
private static String createISBN(TestType type) {
String prefix = "979000000000";
int checkDigit = (120 - (9 * 1) + (7 * 3) + (9 * 1)) % 10;
return prefix + checkDigit;
}
public static void main(String... arguments) {
String testCases = "";
int validISBNCount = 0;
int invalidISBNCount = 0;
// Generate test case number 0
TestType type0 = getRandomType();
String isbn0 = createISBN(type0);
String test0 = createTestCase(isbn0, type0, 0);
testCases += test0;
// Generate test case number 1
TestType type1 = getRandomType();
String isbn1 = createISBN(type1);
String test1 = createTestCase(isbn1, type1, 1);
testCases += test1;
// Generate test case number 2
TestType type2 = getRandomType();
String isbn2 = createISBN(type2);
String test2 = createTestCase(isbn2, type2, 2);
testCases += test2;
// Generate test case number 3
TestType type3 = getRandomType();
String isbn3 = createISBN(type3);
String test3 = createTestCase(isbn3, type3, 3);
testCases += test3;
// Print the test cases
printResults(testCases, validISBNCount, invalidISBNCount);
}
}
package edu.unl.cse.soft160.isbn;
import static org.junit.Assert.*;
import org.junit.Test;
import edu.unl.cse.soft160.isbn.implementation.ISBNVerifier;
public class ISBNVerifierTest {
@Test
public void testSimpleExample() {
boolean result = ISBNVerifier.isValidISBN("979-3-565-87570-1");
assertTrue(result);
}
}
# Mac file finder metadata
.DS_Store
# Windows file metadata
._*
# Thumbnail image caches
Thumbs.db
ethumbs.db
# MS Office temporary file
~*
# Emacs backup file
*~
# Common
[Bb]in/
[Bb]uild/
[Oo]bj/
[Oo]ut/
[Tt]mp/
[Xx]86/
[Ii][Aa]32/
[Xx]64/
[Xx]86_64/
[Xx]86-64/
[Aa]rm
[Aa]32
[Tt]32
[Aa]64
*.tmp
*.bak
*.bk
*.swp
# Java files
*.class
javadoc/
# Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# JetBrains (IntelliJ IDEA, PyCharm, etc) files
.idea/
cmake-build-*/
*.iml
*.iws
*.ipr
# Eclipse files
.settings/
.project
.classpath
.buildpath
.loadpath
.factorypath
local.properties
# Robot Requirements
1. If the driver presses the "Up" arrow, then the cart shall increase its speed by 1,000 furlongs per fortnight.
2. If the driver presses the "Down" arrow, then the cart shall decrease its speed by 1,000 furlongs per fortnight.
3. The cart shall not travel faster than 15,000 furlongs per fortnight on smooth terrain, 10,000 furlongs per fortnight on moderate terrain, and 5,000 furlongs per fortnight on rough terrain.
4. If the driver presses the "Right" or "Left" arrow, then the cart's wheels shall deflect 5° right or left, as appropriate.
5. The cart shall not deflect its wheels more than 30° away from "forward" in either direction.
6. If the driver presses the "Emergency Stop" button, then the cart shall perform an emergency stop.
7. If the cart is traveling faster than its maximum speed, then it shall decrease its speed by 1,000 furlongs per fortnight.
8. If the short-range radar detects that the cart is overtaking a moving object, then the cart shall decrease its speed by 1,000 furlongs per fortnight.
9. If the short-range radar detects a stationary object in the cart's path, then the cart shall perform an emergency stop.
10. If the short-range radar detects an object in the cart's path that is approaching the cart, then the cart's wheels shall deflect 5° to avoid a collision.
11. If no other action is required, then the cart shall display its current speed and heading.
12. If the cart's wheels are turned too far away from "forward", then it the cart's wheels shall deflect in the direction necessary to return to tolerances.
13. An emergency stop, whether commanded by the driver or directed by the cart's safety logic, shall override all other possible actions *except* turning to avoid a collision.
14. If the cart cannot perform a required action, it shall display a message explaining why.
15. If the cart's previous action was an emergency stop, and if the cart has not stopped, then the cart shall display a message explaining why.
\ No newline at end of file
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.unl.cse.soft160.tdd_homework</groupId>
<artifactId>tdd_homework</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>tdd_homework</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
package edu.unl.cse.soft160.tdd_homework;
public class Cart {
public enum DriverInput {
NO_INPUT, UP_ARROW, DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW, EMERGENCY_STOP,
}
public enum Terrain {
SMOOTH, MODERATE, ROUGH,
}
public enum Action {
ACCELERATE, DECELERATE, DEFLECT_WHEELS_LEFT, DEFLECT_WHEELS_RIGHT,
EMERGENCY_STOP, DISPLAY_SPEED_AND_HEADING, DISPLAY_MESSAGE,
}
public static Action act(DriverInput input, int currentSpeed, int currentWheelDeflection,
Terrain terrain, int rateOfApproach, Action lastActionTaken) {
return Action.DISPLAY_SPEED_AND_HEADING;
}
}
package edu.unl.cse.soft160.tdd_homework;
import static org.junit.Assert.*;
import org.junit.Test;
public class CartTest {
@Test
public void testAct() {
fail("Not yet implemented");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment