From 776f998428db46bff9d92c4132a616030225f7e9 Mon Sep 17 00:00:00 2001
From: Christopher Bohn <bohn@unl.edu>
Date: Sat, 26 Oct 2024 12:15:56 -0500
Subject: [PATCH] Added starter code for Week 10 assignments

---
 isbn/.gitignore                               | 62 ++++++++++++++
 isbn/pom.xml                                  | 36 ++++++++
 .../isbn/implementation/ISBNVerifier.java     | 35 ++++++++
 .../isbn/meta/GenerateVerifierTestSuite.java  | 84 +++++++++++++++++++
 .../cse/soft160/isbn/ISBNVerifierTest.java    | 17 ++++
 tdd_homework/.gitignore                       | 62 ++++++++++++++
 tdd_homework/README.md                        | 17 ++++
 tdd_homework/documentation/.gitkeep           |  0
 tdd_homework/pom.xml                          | 43 ++++++++++
 .../unl/cse/soft160/tdd_homework/Cart.java    | 21 +++++
 .../cse/soft160/tdd_homework/CartTest.java    | 12 +++
 11 files changed, 389 insertions(+)
 create mode 100644 isbn/.gitignore
 create mode 100644 isbn/pom.xml
 create mode 100644 isbn/src/main/java/edu/unl/cse/soft160/isbn/implementation/ISBNVerifier.java
 create mode 100644 isbn/src/main/java/edu/unl/cse/soft160/isbn/meta/GenerateVerifierTestSuite.java
 create mode 100644 isbn/src/test/java/edu/unl/cse/soft160/isbn/ISBNVerifierTest.java
 create mode 100644 tdd_homework/.gitignore
 create mode 100644 tdd_homework/README.md
 create mode 100644 tdd_homework/documentation/.gitkeep
 create mode 100644 tdd_homework/pom.xml
 create mode 100644 tdd_homework/src/main/java/edu/unl/cse/soft160/tdd_homework/Cart.java
 create mode 100644 tdd_homework/src/test/java/edu/unl/cse/soft160/tdd_homework/CartTest.java

diff --git a/isbn/.gitignore b/isbn/.gitignore
new file mode 100644
index 0000000..f35f60a
--- /dev/null
+++ b/isbn/.gitignore
@@ -0,0 +1,62 @@
+# 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
diff --git a/isbn/pom.xml b/isbn/pom.xml
new file mode 100644
index 0000000..ca0d6c8
--- /dev/null
+++ b/isbn/pom.xml
@@ -0,0 +1,36 @@
+<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>
diff --git a/isbn/src/main/java/edu/unl/cse/soft160/isbn/implementation/ISBNVerifier.java b/isbn/src/main/java/edu/unl/cse/soft160/isbn/implementation/ISBNVerifier.java
new file mode 100644
index 0000000..66422b2
--- /dev/null
+++ b/isbn/src/main/java/edu/unl/cse/soft160/isbn/implementation/ISBNVerifier.java
@@ -0,0 +1,35 @@
+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);
+    }
+}
diff --git a/isbn/src/main/java/edu/unl/cse/soft160/isbn/meta/GenerateVerifierTestSuite.java b/isbn/src/main/java/edu/unl/cse/soft160/isbn/meta/GenerateVerifierTestSuite.java
new file mode 100644
index 0000000..d864976
--- /dev/null
+++ b/isbn/src/main/java/edu/unl/cse/soft160/isbn/meta/GenerateVerifierTestSuite.java
@@ -0,0 +1,84 @@
+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);
+    }
+}
diff --git a/isbn/src/test/java/edu/unl/cse/soft160/isbn/ISBNVerifierTest.java b/isbn/src/test/java/edu/unl/cse/soft160/isbn/ISBNVerifierTest.java
new file mode 100644
index 0000000..5476b55
--- /dev/null
+++ b/isbn/src/test/java/edu/unl/cse/soft160/isbn/ISBNVerifierTest.java
@@ -0,0 +1,17 @@
+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);
+    }
+
+}
diff --git a/tdd_homework/.gitignore b/tdd_homework/.gitignore
new file mode 100644
index 0000000..f35f60a
--- /dev/null
+++ b/tdd_homework/.gitignore
@@ -0,0 +1,62 @@
+# 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
diff --git a/tdd_homework/README.md b/tdd_homework/README.md
new file mode 100644
index 0000000..7345d1c
--- /dev/null
+++ b/tdd_homework/README.md
@@ -0,0 +1,17 @@
+# 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
diff --git a/tdd_homework/documentation/.gitkeep b/tdd_homework/documentation/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/tdd_homework/pom.xml b/tdd_homework/pom.xml
new file mode 100644
index 0000000..7ad3eee
--- /dev/null
+++ b/tdd_homework/pom.xml
@@ -0,0 +1,43 @@
+<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>
diff --git a/tdd_homework/src/main/java/edu/unl/cse/soft160/tdd_homework/Cart.java b/tdd_homework/src/main/java/edu/unl/cse/soft160/tdd_homework/Cart.java
new file mode 100644
index 0000000..c903e74
--- /dev/null
+++ b/tdd_homework/src/main/java/edu/unl/cse/soft160/tdd_homework/Cart.java
@@ -0,0 +1,21 @@
+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;
+    }
+}
diff --git a/tdd_homework/src/test/java/edu/unl/cse/soft160/tdd_homework/CartTest.java b/tdd_homework/src/test/java/edu/unl/cse/soft160/tdd_homework/CartTest.java
new file mode 100644
index 0000000..9ec96bc
--- /dev/null
+++ b/tdd_homework/src/test/java/edu/unl/cse/soft160/tdd_homework/CartTest.java
@@ -0,0 +1,12 @@
+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");
+    }
+}
-- 
GitLab