From 78b7d8b53faebe9918d3739f631b35159c2003c6 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Mon, 8 Jul 2024 03:40:57 +0000 Subject: [PATCH] Initial commit --- .gitignore | 155 ++++++++++++++ .travis.yml | 20 ++ README.md | 38 ++++ instructions/part1/README-BasicArrayUtils.md | 169 ++++++++++++++++ instructions/part1/README-BasicStringUtils.md | 157 +++++++++++++++ .../part1/README-IntegerArrayUtils.md | 113 +++++++++++ instructions/part1/README-IntegerUtils.md | 137 +++++++++++++ .../part1/README-RockPaperSissorsEvaluator.md | 111 ++++++++++ instructions/part2/README-ArrayUtils.md | 189 ++++++++++++++++++ instructions/part2/README-MultiplesDeleter.md | 144 +++++++++++++ instructions/part2/README-StringUtils.md | 166 +++++++++++++++ .../part3/README-AnimalsPetsOwners.md | 127 ++++++++++++ instructions/part4/README-JumpToTheFlag.md | 82 ++++++++ instructions/part5/README-Palindrome.md | 51 +++++ pom.xml | 32 +++ .../assessment1/part1/BasicArrayUtils.java | 38 ++++ .../assessment1/part1/BasicStringUtils.java | 47 +++++ .../assessment1/part1/IntegerArrayUtils.java | 30 +++ .../assessment1/part1/IntegerUtils.java | 32 +++ .../part1/RockPaperSissorsEvaluator.java | 35 ++++ .../assessment1/part2/ArrayUtils.java | 55 +++++ .../assessment1/part2/MultiplesDeleter.java | 43 ++++ .../assessment1/part2/StringUtils.java | 56 ++++++ .../assessment1/part3/Animal.java | 8 + .../assessment1/part3/Cat.java | 43 ++++ .../assessment1/part3/Dog.java | 43 ++++ .../assessment1/part3/Pet.java | 61 ++++++ .../assessment1/part3/PetOwner.java | 80 ++++++++ .../assessment1/part4/Jumper.java | 11 + .../assessment1/part5/Palindrome.java | 8 + .../assessment1/UnitTestingUtils.java | 27 +++ .../part1/BasicArrayUtilsTest.java | 61 ++++++ .../part1/BasicStringUtilsTest.java | 88 ++++++++ .../part1/IntegerArrayUtilsTest.java | 48 +++++ .../assessment1/part1/IntegerUtilsTest.java | 48 +++++ .../part1/RockPaperSissorsEvaluatorTest.java | 52 +++++ .../assessment1/part2/ArrayUtilsTest.java | 79 ++++++++ .../part2/MultiplesDeleterTest.java | 69 +++++++ .../assessment1/part2/StringUtilsTest.java | 80 ++++++++ .../assessment1/part3/CatTest.java | 94 +++++++++ .../assessment1/part3/DogTest.java | 94 +++++++++ .../assessment1/part3/PetOwnerTest.java | 178 +++++++++++++++++ .../assessment1/part3/PetTest.java | 49 +++++ .../assessment1/part4/JumperTest.java | 66 ++++++ .../assessment1/part5/PalindromeTest.java | 66 ++++++ 45 files changed, 3380 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 README.md create mode 100644 instructions/part1/README-BasicArrayUtils.md create mode 100644 instructions/part1/README-BasicStringUtils.md create mode 100644 instructions/part1/README-IntegerArrayUtils.md create mode 100644 instructions/part1/README-IntegerUtils.md create mode 100644 instructions/part1/README-RockPaperSissorsEvaluator.md create mode 100644 instructions/part2/README-ArrayUtils.md create mode 100644 instructions/part2/README-MultiplesDeleter.md create mode 100644 instructions/part2/README-StringUtils.md create mode 100644 instructions/part3/README-AnimalsPetsOwners.md create mode 100644 instructions/part4/README-JumpToTheFlag.md create mode 100644 instructions/part5/README-Palindrome.md create mode 100644 pom.xml create mode 100644 src/main/java/com/zipcodewilmington/assessment1/part1/BasicArrayUtils.java create mode 100644 src/main/java/com/zipcodewilmington/assessment1/part1/BasicStringUtils.java create mode 100644 src/main/java/com/zipcodewilmington/assessment1/part1/IntegerArrayUtils.java create mode 100644 src/main/java/com/zipcodewilmington/assessment1/part1/IntegerUtils.java create mode 100644 src/main/java/com/zipcodewilmington/assessment1/part1/RockPaperSissorsEvaluator.java create mode 100644 src/main/java/com/zipcodewilmington/assessment1/part2/ArrayUtils.java create mode 100644 src/main/java/com/zipcodewilmington/assessment1/part2/MultiplesDeleter.java create mode 100644 src/main/java/com/zipcodewilmington/assessment1/part2/StringUtils.java create mode 100644 src/main/java/com/zipcodewilmington/assessment1/part3/Animal.java create mode 100644 src/main/java/com/zipcodewilmington/assessment1/part3/Cat.java create mode 100644 src/main/java/com/zipcodewilmington/assessment1/part3/Dog.java create mode 100644 src/main/java/com/zipcodewilmington/assessment1/part3/Pet.java create mode 100644 src/main/java/com/zipcodewilmington/assessment1/part3/PetOwner.java create mode 100644 src/main/java/com/zipcodewilmington/assessment1/part4/Jumper.java create mode 100644 src/main/java/com/zipcodewilmington/assessment1/part5/Palindrome.java create mode 100644 src/test/java/com/zipcodewilmington/assessment1/UnitTestingUtils.java create mode 100644 src/test/java/com/zipcodewilmington/assessment1/part1/BasicArrayUtilsTest.java create mode 100644 src/test/java/com/zipcodewilmington/assessment1/part1/BasicStringUtilsTest.java create mode 100644 src/test/java/com/zipcodewilmington/assessment1/part1/IntegerArrayUtilsTest.java create mode 100644 src/test/java/com/zipcodewilmington/assessment1/part1/IntegerUtilsTest.java create mode 100644 src/test/java/com/zipcodewilmington/assessment1/part1/RockPaperSissorsEvaluatorTest.java create mode 100644 src/test/java/com/zipcodewilmington/assessment1/part2/ArrayUtilsTest.java create mode 100644 src/test/java/com/zipcodewilmington/assessment1/part2/MultiplesDeleterTest.java create mode 100644 src/test/java/com/zipcodewilmington/assessment1/part2/StringUtilsTest.java create mode 100644 src/test/java/com/zipcodewilmington/assessment1/part3/CatTest.java create mode 100644 src/test/java/com/zipcodewilmington/assessment1/part3/DogTest.java create mode 100644 src/test/java/com/zipcodewilmington/assessment1/part3/PetOwnerTest.java create mode 100644 src/test/java/com/zipcodewilmington/assessment1/part3/PetTest.java create mode 100644 src/test/java/com/zipcodewilmington/assessment1/part4/JumperTest.java create mode 100644 src/test/java/com/zipcodewilmington/assessment1/part5/PalindromeTest.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..de469bb --- /dev/null +++ b/.gitignore @@ -0,0 +1,155 @@ +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# CMake +cmake-build-debug/ + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +*.iml +.idea/** +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# CMake +cmake-build-debug/ + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm + # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + + # User-specific stuff: + .idea/**/workspace.xml + .idea/**/tasks.xml + .idea/dictionaries + + # Sensitive or high-churn files: + .idea/**/dataSources/ + .idea/**/dataSources.ids + .idea/**/dataSources.xml + .idea/**/dataSources.local.xml + .idea/**/sqlDataSources.xml + .idea/**/dynamic.xml + .idea/**/uiDesigner.xml + + # Gradle: + .idea/**/gradle.xml + .idea/**/libraries + + # CMake + cmake-build-debug/ + + # Mongo Explorer plugin: + .idea/**/mongoSettings.xml + + ## File-based project format: + *.iws + + ## Plugin-specific files: + + # IntelliJ + /out/ + + # mpeltonen/sbt-idea plugin + .idea_modules/ + + # JIRA plugin + atlassian-ide-plugin.xml + + # Cursive Clojure plugin + .idea/replstate.xml + + # Crashlytics plugin (for Android Studio and IntelliJ) + com_crashlytics_export_strings.xml + crashlytics.properties + crashlytics-build.properties + fabric.properties +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +.project +.classpath +.settings + + +#maven build target +target/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e45a8e6 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,20 @@ +sudo: false +language: java + +deploy: + provider: script + script: + - "mvn test -Dtest=BasicArrayUtilsTest" + - "mvn test -Dtest=BasicStringUtilsTest" + - "mvn test -Dtest=IntegerArrayUtilsTest" + - "mvn test -Dtest=IntegerUtilsTest" + - "mvn test -Dtest=RockPaperSissorsEvaluatorTest" + - "mvn test -Dtest=ArrayUtilsTest" + - "mvn test -Dtest=MultiplesDeleterTest" + - "mvn test -Dtest=StringUtilsTest" + - "mvn test -Dtest=CatTest" + - "mvn test -Dtest=DogTest" + - "mvn test -Dtest=PetOwnerTest" + - "mvn test -Dtest=PetTest" + - "mvn test -Dtest=JumperTest" + - "mvn test -Dtest=PalindromeTest" \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4f1803a --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# ZipCodeWilmington Assessment 1 + + +## **Getting Started** +* Complete each of the asks in each of the `README.md` files found in the [instructions directory](./instructions) + * Begin by completing section 1. + * [BasicArrayUtils](./instructions/part1/README-BasicArrayUtils.md) + * [BasicStringUtils](./instructions/part1/README-BasicStringUtils.md) + * [IntegerArrayUtils](./instructions/part1/README-IntegerArrayUtils.md) + * [IntegerUtils](./instructions/part1/README-IntegerUtils.md) + * [RockPaperScissorsEvaluator](./instructions/part1/README-RockPaperSissorsEvaluator.md) + + * Continue by completing section 2. + * [ArrayUtils](./instructions/part2/README-ArrayUtils.md) + * [MultiplesDeleter](./instructions/part2/README-MultiplesDeleter.md) + * [StringUtils](./instructions/part2/README-StringUtils.md) + + * Advance further by completing section 3. + * [AnimalsPetsOwners](./instructions/part3/README-AnimalsPetsOwners.md) + * Go on to section 4. + * [JumpToTheFlag](./instructions/part4/README-JumpToTheFlag.md) + * Finish by completing section 5. + * [Palindrome](./instructions/part5/README-Palindrome.md) + +## **Frequently Asked Questions** +* Can I use content from my old labs? + * Yes. +* Can I use content from the web / google? + * Yes. +* Can I **contact** someone other than an instructor for help? + * No. +* Can I modify the tests? + * **No**-- Absolutely not. You are forbidden from modifying the tests. +* What if the tests are requesting something different than the instructions / comments? + * Code against **the tests**, not the instructions. +* What are the `Sample Script` and `Sample Output` portions of each `README`? + * Each `README` contains sample code which illustrates the _behavior_ of the respective method. + * **Refer to the tests** to have a better understanding of the intended behavior. diff --git a/instructions/part1/README-BasicArrayUtils.md b/instructions/part1/README-BasicArrayUtils.md new file mode 100644 index 0000000..f9221d9 --- /dev/null +++ b/instructions/part1/README-BasicArrayUtils.md @@ -0,0 +1,169 @@ +# BasicArrayUtils +* Ensure each of the test cases in the class [BasicArrayUtilsTest]() successfully passes upon completion of each of the method stubs in the class [BasicArrayUtils](). + * `String getFirstElement(String[])` + * `String getSecondElement(String[])` + * `String getLastElement(String[])` + * `String getSecondToLastElement(String[])` + + + + + + + +



+## `String getFirstElement(String[] stringArray)` +* **Description** + * Given a string array, `stringArray`, return the first element of the array. +### Example +* Sample Script + + ``` + // Given + String[] inputArray = {"The", "quick", "brown"}; + + // When + String outcome = BasicArrayUtils.getFirstElement(inputArray); + + // Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + The + ``` + + + + + + + + + +



+## `String getSecondElement(String[] stringArray)` +* **Description** + * Given a string array, `stringArray`, return the first element of the array. +### Example +* Sample Script + + ``` + // Given + String[] inputArray = {"The", "quick", "brown"}; + + // When + String outcome = BasicArrayUtils.getSecondElement(inputArray); + + // Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + quick + ``` + + + + + + + + + + + + + + + + + + + + + + + + + + +



+## `String getLastElementTest(String[] stringArray)` +* **Description** + * Given a string array, `stringArray`, return the second element of the array. +### Example +* Sample Script + + ``` + // Given + String[] inputArray = {"The", "quick", "brown"}; + + // When + String outcome = BasicArrayUtils.getLastElement(inputArray); + + // Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + brown + ``` + + + + + + + + + + + + + + + + + + + + +



+## `String getSecondToLastElement(String[] stringArray)` +* **Description** + * Given a string array, `stringArray`, return the second to last element of the array. +### Example +* Sample Script + + ``` + // Given + String[] inputArray = {"The", "quick", "brown"}; + + // When + String outcome = BasicArrayUtils.getSecondToLastElement(inputArray); + + // Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + quick + ``` + diff --git a/instructions/part1/README-BasicStringUtils.md b/instructions/part1/README-BasicStringUtils.md new file mode 100644 index 0000000..db11799 --- /dev/null +++ b/instructions/part1/README-BasicStringUtils.md @@ -0,0 +1,157 @@ +# BasicStringUtils +* Ensure each of the test cases in the class [BasicStringUtilsTest]() successfully passes upon completion of each of the method stubs in the class [BasicStringUtils](). + * `String camelCase(String)` + * `String reverse(String)` + * `String reverseThenCamelCase(String)` + * `String removeFirstAndLastCharacter(String)` + * `String invertCasing(String)` + + + + + + + +



+## `String camelCase(String str)` +* **Description** + * Given a string, `str`, return an identical String with the first character capitalized. +### Example +* Sample Script + + ``` + // : Given + String input = "jumping jacks"; + + // : When + String outcome = BasicStringUtils.camelCase(input); + + // : Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + Jumping jacks + ``` + + + + + + + + + + + + + +



+## `String reverse(String str)` +* **Description** + * Given a string array `str`, return a string with identical contents, in the reverse order + +### Example +* Sample Script + + ``` + // : Given + String input = "Leon"; + + // : When + String outcome = BasicStringUtils.reverse(input); + + // : Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + noeL + ``` + + + + + + + + + +



+## `String reverseThenCamelCase(String str)` +* **Description** + * Given a string, `str`, return a string with identical contents, in reverse order, with first character capitalized +### Example +* Sample Script + + ``` + // : Given + String input = "Leon"; + + // : When + String outcome = BasicStringUtils.reverseThenCamelCase(input); + + // : Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + NoeL + ``` + + + + + + + + + + +



+## `String removeFirstAndLastCharacter(String str)` +* **Description** + * Given a string, `str`, return a string with identical contents excluding first and last character. +### Example +* Sample Script + + ``` + // : Given + String input = "Jack Jumpz; + + // : When + String outcome = BasicStringUtils.removeFirstAndLastCharacter(input); + + // : Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + ack jump + ``` + + + + + + + + + + diff --git a/instructions/part1/README-IntegerArrayUtils.md b/instructions/part1/README-IntegerArrayUtils.md new file mode 100644 index 0000000..8e1a46f --- /dev/null +++ b/instructions/part1/README-IntegerArrayUtils.md @@ -0,0 +1,113 @@ +# IntegerArrayUtils +* Ensure each of the test cases in the class [IntegerArrayUtilsTest]() successfully passes upon completion of each of the method stubs in the class [IntegerArrayUtils](). + * `Integer getSum(Integer[] intArray)` + * `Integer getProduct(Integer[] intArray)` + * `Double getAverage(Integer[] intArray)` + + + + + + + +



+## `Integer getSum(Integer[] intArray)` +* **Description** + * Given an Integer array, `intArray`, return the sum of all values in the array. +### Example +* Sample Script + + ``` + // : Given + Integer[] input = { 1, 2, 3, 4, 5}; + + // : When + Integer outcome = IntegerArrayUtils.getSum(input); + + // : Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + 15 + ``` + + + + + + + + + + + + + + + + +



+## `Integer getProduct(Integer[] intArray)` +* **Description** + * Given an Integer array, `intArray`, return the product of all values in the array. +### Example +* Sample Script + + ``` + // : Given + Integer[] input = { 1, 2, 3, 4, 5}; + + // : When + Integer outcome = IntegerArrayUtils.getProduct(input); + + // : Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + 120 + ``` + + + + + + + + + + +



+## `Integer getAverage(Integer[] intArray)` +* **Description** + * Given an Integer array, `intArray`, return the sum of all values in the array. +### Example +* Sample Script + + ``` + // : Given + Integer[] input = { 1, 2, 3, 4, 5}; + + // : When + Integer outcome = IntegerArrayUtils.getAverage(input); + + // : Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + 3.0 + ``` \ No newline at end of file diff --git a/instructions/part1/README-IntegerUtils.md b/instructions/part1/README-IntegerUtils.md new file mode 100644 index 0000000..1c6b295 --- /dev/null +++ b/instructions/part1/README-IntegerUtils.md @@ -0,0 +1,137 @@ +# IntegerUtils +* Ensure each of the test cases in the class [IntegerUtilsTest]() successfully passes upon completion of each of the method stubs in the class [IntegerUtils](). + * `Integer getSumOfN(int n)` + * `Integer getProductOfN(int n)` + * `Integer reverseDigits(int val)` + + + + + + + + + +



+## `Integer getSumOfN(Integer n)` +* **Description** + * Given an Integer, `n`, return the sum of all integers from 0 up to and including `n` +### Example +* Sample Script + + ``` + // : Given + Integer input = 4; + + // : When + Integer outcome = IntegerUtils.getSumOfN(input); + + // : Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + 10 + ``` + + + + + + + + + + + + + + + + +



+## `Integer getProductOfN(Integer n)` +* **Description** + * Given an Integer , `n`, return the product of all integers from 0 up to and includingg `n`. +### Example +* Sample Script + + ``` + // : Given + Integer input = 7; + + // : When + Integer outcome = IntegerUtils.getProductOfN(input); + + // : Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + 5040 + ``` + + + + + + + + + + +



+## `Integer reverseDigits(Integer n)` +* **Description** + * Given an Integer, `n`, return integer an with identical digits in the reverse order +### Example +* Sample Script + + ``` + // : Given + Integer input = 12345 + + // : When + Integer outcome = IntegerUtils.reverseDigits(input); + + // : Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + 54321 + ``` + + + + + + + + + + + + + + + + + + + + + + diff --git a/instructions/part1/README-RockPaperSissorsEvaluator.md b/instructions/part1/README-RockPaperSissorsEvaluator.md new file mode 100644 index 0000000..d58003c --- /dev/null +++ b/instructions/part1/README-RockPaperSissorsEvaluator.md @@ -0,0 +1,111 @@ +# RockPaperScissorsEvaluator + +* Ensure each of the test cases in the class [RockPaperScissorsEvaluatorTest]() successfully passes upon completion of each of the method stubs in the class [RockPaperScissorsEvaluator](). + * `String getWinningMove(String handSign)` + * `String getLosingMove(String handSign)` + * `String getWinner(String handSignOfPlayer1, String handSignOfPlayer2)` + + + + + + + +



+ + + +## `String getWinningMove(String handSign)` +* **Description** + * Given a String representative of a hand sign, named `handSign`, in [Rock Paper Scissors](https://en.wikipedia.org/wiki/Rock-paper-scissors), return the String representation of the hand sign which would defeat the respective `handSign`. +### Example +* Sample Script + + ``` + // : Given + RockPaperScissors rps = new RockPaperScissors(); + String input = "rock"; + + // : When + String outcome = rps.getWinningMove(input); + + // : Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + paper + ``` + + + + + + + + + +



+## `String getLosingMove(String handSign)` +* **Description** + * Given a String representative of a hand sign, named `handSign`, in [Rock Paper Scissors](https://en.wikipedia.org/wiki/Rock-paper-scissors), return the String representation of the hand sign which would be defeated by the respective `handSign`. +### Example +* Sample Script + + ``` + // : Given + RockPaperScissors rps = new RockPaperScissors(); + String input = "rock"; + + // : When + String outcome = rps.getLosingMove(input); + + // : Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + scissors + ``` + + + + + + + +



+## `String getWinner(String handSignOfPlayer1, String handSignOfPlayer2)` +* **Description** + * Given two Strings, named `handSignOfPlayer1`, and `handSignOfPlayer2`, representative of the hand signs of two Rock Paper Scissor players, return the String representation of the hand sign which would be the victor. +### Example +* Sample Script + + ``` + // : Given + RockPaperScissors rps = new RockPaperScissors(); + String handSignOfPlayer1 = "rock"; + String handSignOfPlayer2 = "paper"; + + // : When + String outcome = rps.getWinner(handSignOfPlayer1, handSignOfPlayer2); + + // : Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + paper + ``` diff --git a/instructions/part2/README-ArrayUtils.md b/instructions/part2/README-ArrayUtils.md new file mode 100644 index 0000000..82b4bd3 --- /dev/null +++ b/instructions/part2/README-ArrayUtils.md @@ -0,0 +1,189 @@ +# ArrayUtils +* Ensure each of the test cases in the class [Arrayutils]() successfully passes upon completion of each of the method stubs in the class [ArrayutilsTest](). + * `Integer getNumberOfOccurrences(Object[] objectArray, Object objectToCount)` + * `Object[] removeValue(Object[] objectArray, Object objectToRemove)` + * `Object getMostCommon(Object[] objectArray)` + * `Object getLeastCommon(Object[] objectArray)` + * `Object[] mergeArrays(Object[] objectArray, Object[] objectArrayToAdd)` + + + + + + + +



+## `Integer getNumberOfOccurrences(Object[] objectArray, Object objectToCount)` +* **Description** + * Given an array of objects of any `type` and an `object` of the same `type`, return the number of times the `object` occurs in the array. + +### Example +* Sample Script + + ``` + // Given + Integer valueToEvaluate = 7; + Integer expected = 3; + Integer[] inputArray = {1, 2, 7, 8, 4, 5, 7, 0, 9, 8, 7}; + + // When + Integer outcome = ArrayUtils.getNumberOfOccurrences(inputArray, valueToEvaluate); + + // Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + 3 + ``` + + + + + + + + + +



+## `Object[] removeValue(Object[] objectArray, Object objectToRemove)` +* **Description** + * Given an array of objects, named `objectArray`, and an object `objectToCount`, return the number of times the `objectToCount` appears in the `objectArray` + +### Example +* Sample Script + + ``` + // : Given + Integer valueToRemove = 4; + Integer[] inputArray = {5, 6, 4, 2, 9, 3, 0}; + + // : When + Integer[] outcome = (Integer[]) ArrayUtils.removeValue(inputArray, valueToRemove); + + // : Then + String outcomeStr = Arrays.toString(outcome); + System.out.println(outcomeStr); + ``` + + +* Sample Output + + ``` + [5, 6, 2, 9, 3, 0] + ``` + + + + + + + +



+## `Object getMostCommon(Object[] objectArray)` +* **Description** + * Given an array of objects, named `objectArray` return the most frequently occuring object in the array. + +### Example +* Sample Script + + ``` + // Given + Integer expected = 1; + Integer[] inputArray = {1,1,1,1,2,2,2,3,3,4}; + + // When + Integer outcome = ArrayUtils.getMostCommon(inputArray); + + // Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + 1 + ``` + + + + + +



+## `Object getLeastCommon(Object[] objectArray)` +* **Description** + * Given an array of objects, named `objectArray` return the least frequently occuring object in the array. + +### Example +* Sample Script + + ``` + // Given + Integer expected = 4; + Integer[] inputArray = {1,1,1,1,2,2,2,3,3,4}; + + // When + Integer outcome = ArrayUtils.getLeastCommon(inputArray); + + // Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + 4 + ``` + + + + + + + + + + + + + + + +



+ +## `Object mergeArrays(Object[] objectArray)` +* **Description** + * given two arrays `objectArray` and `objectArrayToAdd`, return an array containing all elements in `objectArray` and `objectArrayToAdd` + +### Example + +* Sample Script + + ``` + // Given + Integer[] objectArray = {1,1,1,2,2,2}; + Integer[] objectArrayToAdd = {3,3,3,4,4,4}; + + // When + Integer[] outcome = (Integer[]) ArrayUtils.mergeArrays(array1, array2); + + // Then + String outcomeStr = Arrays.toString(outcome); + System.out.println(outcomeStr); + ``` + + + +* Sample Output + + ``` + [1,1,1,2,2,2,3,3,3,4,4,4] + ``` diff --git a/instructions/part2/README-MultiplesDeleter.md b/instructions/part2/README-MultiplesDeleter.md new file mode 100644 index 0000000..8055029 --- /dev/null +++ b/instructions/part2/README-MultiplesDeleter.md @@ -0,0 +1,144 @@ +# MultiplesDeleter +* Ensure each of the test cases in the class [MultiplesDeleter]() successfully passes upon completion of each of the method stubs in the class [MultiplesDeleterTest](). + * `Integer[] deleteEvens(Integer[] intArray)` + * `Integer[] deleteOdds(Integer[] intArray)` + * `Integer[] deleteMultiplesOf3(Integer[] intArray)` + * `Integer[] deleteMultiplesOfN(Integer[] intArray)` + + + + + + + +



+## `Integer[] deleteEvens(Integer[] intArray)` +* **Description** + * Given an array of integers, named `ints` return an identical array with odds removed. + +### Example +* Sample Script + + ``` + // Given + MultiplesDeleter deleter = new MultiplesDeleter(); + Integer[] inputArray = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + + // When + Integer[] outcome = q1.deleteEvens(inputArray); + + // Then + String outcomeStr = Arrays.toString(outcome); + System.out.println(outcomeStr); + ``` + + + +* Sample Output + + ``` + [1, 3, 5, 7, 9] + ``` + + + + + + + + + +



+## `Integer[] deleteOdds(Integer[] intArray)` +* **Description** + * Given an array of integers, named `ints` return an identical array with odds removed + +### Example +* Sample Script + + ``` + // Given + Integer[] inputArray = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + + // When + Integer[] outcome = deleter.deleteOdds(inputArray); + + // Then + String outcomeStr = Arrays.toString(outcome); + System.out.println(outcomeStr); + ``` + + + +* Sample Output + + ``` + [2, 4, 6, 8, 10] + ``` + + + + + + + +



+## `Integer[] deleteMultiplesOf3(Integer[] ints)` +* **Description** + * Given an array of integers, named `ints` return an identical array with numbers indivisible by 3 removed. + +### Example +* Sample Script + + ``` + // Given + Integer[] inputArray = { 3, 6, 9, 12, 15, 4, 7, 10, 13, 16}; + + // When + Integer[] outcome = deleter.deleteMultiplesOf3(inputArray); + + // Then + String outcomeStr = Arrays.toString(outcome); + System.out.println(outcomeStr); + ``` + + + +* Sample Output + + ``` + [4, 7, 10, 13, 16] + ``` + + + + + +



+## `Integer[] deleteMultiplesOfN(Integer[] ints, int multiple)` +* **Description** + * Given an array of integers, named `ints` return an identical array with numbers indivisible by `multiple` removed. + +### Example +* Sample Script + + ``` + // Given + Integer multiple = 6; + Integer[] inputArray = { 6, 12, 18, 24, 30, 4, 7, 10, 13, 16}; + + // When + Integer[] outcome = deleter.deleteMultiplesOfN(inputArray, multiple); + + // Then + String outcomeStr = Arrays.toString(outcome); + System.out.println(outcomeStr); + ``` + + + +* Sample Output + + ``` + [4, 7, 10, 13, 16] + ``` diff --git a/instructions/part2/README-StringUtils.md b/instructions/part2/README-StringUtils.md new file mode 100644 index 0000000..ae20d27 --- /dev/null +++ b/instructions/part2/README-StringUtils.md @@ -0,0 +1,166 @@ +# StringUtils +* Ensure each of the test cases in the class [StringUtils]() successfully passes upon completion of each of the method stubs in the class [StringUtilsTest](). + * `String[] getWords(String sentence)` + * `String getFirstWord(String sentence)` + * `String reverseFirstWord(String sentence)` + * `String reverseFirstWordThenCamelCase(String sentence)` + * `String removeCharacterAtIndex(String str, int index)` + + + + + + + +



+## `String[] getWords(String sentence)` +* **Description** + * Given a string containing words delimited by spaces, representative of a sentence, return an array of strings, each element representative of a respective word in the sentence. + +### Example +* Sample Script + + ``` + // Given + String inputString = "Once upon a time there was a method"; + + // When + String[] outcome = StringUtils.getWords(inputString); + + // Then + String outcomeStr = Arrays.toString(outcome); + System.out.println(outcomeStr); + ``` + +* Sample Output + + ``` + [Once, upon, a, time, there, was, a, method] + ``` + + + + + + + + + +



+## `String getFirstWord(String sentence)` +* **Description** + * given a string containing words delimited by spaces, representative of a sentence, return the first word of the sentence + +### Example +* Sample Script + + ``` + // Given + String inputString = "Make sure to commit your code"; + + // When + String outcome = StringUtils.getFirstWord(inputString); + + // Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + Make + ``` + + + + +



+## `String reverseFirstWord(String sentence)` +* **Description** + * given a string containing words delimited by spaces, representative of a sentence, return the first word with identical contents in reverse order. + +### Example +* Sample Script + + ``` + // Given + String inputString = "Super class sea turtle"; + + // When + String outcome = StringUtils.reverseFirstWord(inputString); + + // Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + repuS + ``` + + + + + +



+## `String reverseFirstWordThenCamelCase(String sentence)` +* **Description** + * given a string containing words delimited by spaces, representative of a sentence, return the first word with identical contents in reverse order with the first character capitalized. + +### Example +* Sample Script + + ``` + // Given + String inputString = "Spoons are for scooping"; + + // When + String actual = StringUtils.reverseFirstWordThenCamelCase(inputString); + + // Then + System.out.println(outcome); + ``` + +* Sample Output + + ``` + Snoops + ``` + + + + + + +



+## `String removeCharacterAtIndex(String str, int index)` +* **Description** + * given a string and index, return an identical string excluding the character at the specified index. + +### Example +* Sample Script + ``` + // Given + String inputString = "Goal"; + Integer characterIndex = 2; + + // When + String outcome = StringUtils.removeCharacterAtIndex(inputString, characterIndex); + + // Then + System.out.println(outcome); + ``` + + + +* Sample Output + + ``` + Gol + ``` + diff --git a/instructions/part3/README-AnimalsPetsOwners.md b/instructions/part3/README-AnimalsPetsOwners.md new file mode 100644 index 0000000..96b481c --- /dev/null +++ b/instructions/part3/README-AnimalsPetsOwners.md @@ -0,0 +1,127 @@ +# AnimalsPetsOwners +* **Objective:** To implement a `PetsOwner` which manipulates composite `Pet` objects. + +## Pet +* Ensure each of the test cases in the class [Pet]() successfully passes upon completion of each of the method stubs in the class [PetTest](). + * `Pet()` + * `Pet(String)` + * `Pet(int)` + * `Pet(String, int)` + * `String getName()` + * `Integer getAge()` + * `void setOwner(PetOwner owner)` + * `PetOwner getOwner()` + + + + +




+ +### Part 1; Defining instance variables +* To create a programmatic representation of a `Pet`, begin by declaring an instance variable for each of the following properties: + * `String name` + * a collection of characters, representative of a name. + * `Integer age` + * an integer, representative of an age in years. + * `PetOwner owner` + * the owner of this `Pet`. + + + + + + + + + + + + + + + +




+ +### Part 2; Defining construction +* Define a `Pet` constructor whose parameters are used to initialize its instance variables. +* A `Pet` can be constructed in 4 ways. + 1. `Pet()` + * Upon [nullary construction](https://en.wikipedia.org/wiki/Nullary_constructor), pet has `age` of 0 and `name` of "". + 2. `Pet(String)` + * Upon construction, `name` field should be set to respective parameter value, pet has default age of 0. + 3. `Pet(int)` + * Upon construction, `age` field should be set to respective parameter value, pet has default name of "". + 4. `Pet(String, int)` + * `name` and `age` variables should set to respective parameter values. + + + + + + + + + + + + + + + +




+ +### Part 3; Defining methods + +* **Getters and Setters** + * Define a [getter and setter](https://en.wikipedia.org/wiki/Mutator_method#Java_example) for each of the instance variables declared in the `Pet` class. + * `String getName()` + * `Integer getAge()` + * `void setOwner()` + * `PetOwner getOwner()` + + + + + + + + + + + + + + + + + + + +




+ +### Part 4; Pet elucidation + +* **Dog** + * Ensure `Dog` supports all methods of pet construction. + * The mechanism by which a `Dog` speaks is by barking; ensure a dog's `speak` method returns `bark` as a string. + +* **Cat** + * Ensure `Cat` supports all methods of pet construction. + * The mechanism by which a `Cat` speaks is by meowing; ensure a cat's `speak` method returns `meow` as a string. + + + + +




+### Part 5; PetOwner +* Ensure each of the test cases in the class [PetOwner]() successfully passes upon completion of each of the method stubs in the class [PetOwner](). + * `PetOwner(String name, Pet... pets)` + * `void addPet(Pet pet)` + * `void removePet(Pet pet)` + * `Boolean isOwnerOf(Pet pet)` + * `Integer getYoungetPetAge()` + * `Integer getOldestPetAge()` + * `Double getAveragePetAge()` + * `Integer getNumberOfPets()` + * `String getName()` + * `Pet[] getPets()` \ No newline at end of file diff --git a/instructions/part4/README-JumpToTheFlag.md b/instructions/part4/README-JumpToTheFlag.md new file mode 100644 index 0000000..0eddfa2 --- /dev/null +++ b/instructions/part4/README-JumpToTheFlag.md @@ -0,0 +1,82 @@ +## Jump The Flag + +Tariq, the Kangaroo, is trying to reach a flag that's `flagHeight` units above the ground. In his attempt to reach the flag, Tariq can make any number of jumps up the rock wall where it's mounted; however, he can only move up the wall (meaning he cannot overshoot the flag and move down to reach it). There are 2 types of jumps: + +1. A jump of height 1. +2. A jump of height `jumpHeight`. + + +Tariq wants your help determining the minimum number of jumps it will take him to collect the flag. Complete the jumps function in your editor. It has 2 parameters: + +1. An integer, `flagHeight`, the height of the flag. +2. An integer, `jumpHeight`, the number of units he ascends in a jump of type 2. + + +It must return an integer denoting the minimum number of times Tariq must jump to collect the flag. + + + +### Input Format + +```java +public int jumps(int flagHeight, int jumpHeight) { +} +``` + +**Constraints** + +``` +1 ≤ flagHeight ≤ 109 +1 ≤ jumpHeight ≤ 109 +``` + +**Output Format** + +Your function must return an integer denoting the minimum number of jumps Tariq must make to collect the flag. + + + +# Test Cases + +### Sample Test 0 + +```java +// Should assert to true +Jumper jumper = new Jumper(); +Integer expected = jumper.jumps(3,1); +Integer actual = 3; +Assert.assertEquals(expected, actual); +``` + +* **Explanation** + * As Tariq can only jump 1 unit or `jumpHeight` units and `jumpHeight = 1`, Tariq can only ever make 1-unit jumps. This means that it will take him 3 steps to reach the flag, so we return 3. + + + +### Sample Test 1 + +```java +// Should assert to true +Jumper jumper = new Jumper(); +Integer expected = jumper.jumps(3,2); +Integer actual = 2; +Assert.assertEquals(expected, actual); +``` + +* **Explanation** + * Tariq will jump `jumpHeight = 2` units, and then jump 1 more unit to reach the flag. Thus, we return 2. + + + +### Sample Test 2 + +```java +// Should assert to true +Jumper jumper = new Jumper(); +Integer expected = jumper.jumps(3,3); +Integer actual = 1; +Assert.assertEquals(expected, actual); +``` + +* **Explanation** + * Tariq will make a single jump `jumpHeight = 3` units up the rock wall and reach the flag, so we return 1. diff --git a/instructions/part5/README-Palindrome.md b/instructions/part5/README-Palindrome.md new file mode 100644 index 0000000..5867c17 --- /dev/null +++ b/instructions/part5/README-Palindrome.md @@ -0,0 +1,51 @@ +## Palindrome Counter + +* Complete the `countPalindromes` function in your editor. +* It has 1 parameter: a string, `s`. +* It must return an integer denoting the number of palindromic substrings of `s`. + +**Output Format** + +* Your function must return an integer denoting the number of different palindromic substrings of s. + + +**Sample Input 0** + +``` +Palindrome palindrome = new Palindrome(); +Integer expected = palindrome.countPalindromes("aaa"); +Integer actual = 6; +Assert.assertEquals(expected, actual); +``` + +***Explanation*** + +* There are 6 possible substrings of `s`: {"a", "a", "a", "aa", "aa", "aaa"}. +* All of them are palindromes, so we return 6. + +**Sample Input 1** + +``` +Palindrome palindrome = new Palindrome(); +Integer expected = palindrome.countPalindromes("abccba"); +Integer actual = 9; +Assert.assertEquals(expected, actual); +``` + +***Explanation*** + +* There are 21 possible substrings of `s`, the following 9 of which are palindromes: {"a", "a", "b", "b", "c", "c", "cc", "bccb", "abccba"}. +* Thus, we return 9. + +**Sample Input 2** + +``` +Palindrome palindrome = new Palindrome(); +Integer expected = palindrome.countPalindromes("daata"); +Integer actual = 7; +Assert.assertEquals(expected, actual); +``` + +***Explanation*** +* There are 15 possible substrings of s, the following 7 of which are palindromes: {"a", "a", "a", "aa", "ata", "d","t"}. +* Thus, we return 7. diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..b029312 --- /dev/null +++ b/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + com.zipcodewilmington.assessment1 + question1 + 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + + + + junit + junit + 4.12 + + + + + \ No newline at end of file diff --git a/src/main/java/com/zipcodewilmington/assessment1/part1/BasicArrayUtils.java b/src/main/java/com/zipcodewilmington/assessment1/part1/BasicArrayUtils.java new file mode 100644 index 0000000..ef714b5 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/assessment1/part1/BasicArrayUtils.java @@ -0,0 +1,38 @@ +package com.zipcodewilmington.assessment1.part1; + +/** + * Created by leon on 2/16/18. + */ +public class BasicArrayUtils { + /** + * @param stringArray an array of String objects + * @return the first element in the array + */ + public static String getFirstElement(String[] stringArray) { + return null; + } + + /** + * @param stringArray an array of String objects + * @return the second element in the array + */ + public static String getSecondElement(String[] stringArray) { + return null; + } + + /** + * @param stringArray an array of String objects + * @return the last element in the array + */ + public static String getLastElement(String[] stringArray) { + return null; + } + + /** + * @param stringArray an array of String objects + * @return the second to last element in the array + */ + public static String getSecondToLastElement(String[] stringArray) { + return null; + } +} diff --git a/src/main/java/com/zipcodewilmington/assessment1/part1/BasicStringUtils.java b/src/main/java/com/zipcodewilmington/assessment1/part1/BasicStringUtils.java new file mode 100644 index 0000000..ca13f2d --- /dev/null +++ b/src/main/java/com/zipcodewilmington/assessment1/part1/BasicStringUtils.java @@ -0,0 +1,47 @@ +package com.zipcodewilmington.assessment1.part1; + +/** + * Created by leon on 2/16/18. + */ +public class BasicStringUtils { + /** + * @param str string input from client + * @return string with identical content, and the first character capitalized + */ + public static String camelCase(String str) { + return null; + } + + /** + * @param str string input from client + * @return string with identical contents, in the reverse order + */ + public static String reverse(String str) { + return null; + } + + /** + * @param str string input from client + * @return string with identical contents, in reverse order, with first character capitalized + */ + public static String reverseThenCamelCase(String str) { + return null; + } + + + /** + * @param str a string input from user + * @return string with identical contents excluding first and last character + */ + public static String removeFirstAndLastCharacter(String str) { + return null; + } + + /** + * @param str a string input from user + * @return string with identical characters, each with opposite casing + */ + public static String invertCasing(String str) { + return null; + } +} diff --git a/src/main/java/com/zipcodewilmington/assessment1/part1/IntegerArrayUtils.java b/src/main/java/com/zipcodewilmington/assessment1/part1/IntegerArrayUtils.java new file mode 100644 index 0000000..68d82ec --- /dev/null +++ b/src/main/java/com/zipcodewilmington/assessment1/part1/IntegerArrayUtils.java @@ -0,0 +1,30 @@ +package com.zipcodewilmington.assessment1.part1; + +/** + * Created by leon on 2/16/18. + */ +public class IntegerArrayUtils { + /** + * @param intArray an array of integers + * @return the sum of `intArray` + */ + public static Integer getSum(Integer[] intArray) { + return null; + } + + /** + * @param intArray an array of integers + * @return the product of `intArray` + */ + public static Integer getProduct(Integer[] intArray) { + return null; + } + + /** + * @param intArray an array of integers + * @return the sum of `intArray` divided by number of elements in `intArray` + */ + public static Double getAverage(Integer[] intArray) { + return null; + } +} diff --git a/src/main/java/com/zipcodewilmington/assessment1/part1/IntegerUtils.java b/src/main/java/com/zipcodewilmington/assessment1/part1/IntegerUtils.java new file mode 100644 index 0000000..eccbb6c --- /dev/null +++ b/src/main/java/com/zipcodewilmington/assessment1/part1/IntegerUtils.java @@ -0,0 +1,32 @@ +package com.zipcodewilmington.assessment1.part1; + +/** + * Created by leon on 2/16/18. + */ +public class IntegerUtils { + + + /** + * @param n integer value input by client + * @return the sum of all integers between 0 and not including `n` + */ + public static Integer getSumOfN(Integer n) { + return null; + } + + /** + * @param n integer value input by client + * @return the product of all integers between 0 and not including `n` + */ + public static Integer getProductOfN(Integer n) { + return null; + } + + /** + * @param val integer value input by client + * @return integer with identical digits in the reverse order + */ + public static Integer reverseDigits(Integer val) { + return null; + } +} diff --git a/src/main/java/com/zipcodewilmington/assessment1/part1/RockPaperSissorsEvaluator.java b/src/main/java/com/zipcodewilmington/assessment1/part1/RockPaperSissorsEvaluator.java new file mode 100644 index 0000000..9495445 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/assessment1/part1/RockPaperSissorsEvaluator.java @@ -0,0 +1,35 @@ +package com.zipcodewilmington.assessment1.part1; + +/** + * Created by leon on 2/16/18. + */ +public class RockPaperSissorsEvaluator { + protected static final String ROCK = "rock"; + protected static final String PAPER = "paper"; + protected static final String SCISSOR = "scissor"; + + /** + * @param handSign a string representative of a hand sign + * @return the respective winning move + */ + public String getWinningMove(String handSign) { + return null; + } + + /** + * @param handSign a string representative of a hand sign + * @return the respective losing move + */ + public String getLosingMove(String handSign) { + return null; + } + + /** + * @param handSignOfPlayer1 a string representative of a hand sign of a player + * @param handSignOfPlayer2 a string representative of a hand sign of a challenger + * @return a string representative of the winning hand sign between the two players + */ + public String getWinner(String handSignOfPlayer1, String handSignOfPlayer2) { + return null; + } +} diff --git a/src/main/java/com/zipcodewilmington/assessment1/part2/ArrayUtils.java b/src/main/java/com/zipcodewilmington/assessment1/part2/ArrayUtils.java new file mode 100644 index 0000000..bb9995a --- /dev/null +++ b/src/main/java/com/zipcodewilmington/assessment1/part2/ArrayUtils.java @@ -0,0 +1,55 @@ +package com.zipcodewilmington.assessment1.part2; + +/** + * Created by leon on 2/16/18. + */ +public class ArrayUtils { + /** + * @param objectArray an array of any type of Object + * @param objectToCount any non-primitive value + * @return the number of times the specified `value` occurs in the specified `objectArray` + * Given an array of objects, named `objectArray`, and an object `objectToCount`, return the number of times the `objectToCount` appears in the `objectArray` + */ + public static Integer getNumberOfOccurrences(Object[] objectArray, Object objectToCount) { + return null; + } + + /** + * @param objectArray an array of any type of Object + * @param objectToRemove a value to be removed from the `objectArray` + * @return an array with identical content excluding the specified `objectToRemove` + * Given an array of objects, name `objectArray`, and an object `objectToRemove`, return an array of objects with identical contents excluding `objectToRemove` + */ + public static Object[] removeValue(Object[] objectArray, Object objectToRemove) { + return null; + } + + /** + * @param objectArray an array of any type of Object + * @return the most frequently occurring object in the array + * given an array of objects, named `objectArray` return the most frequently occuring object in the array + */ + public static Object getMostCommon(Object[] objectArray) { + return null; + } + + + /** + * @param objectArray an array of any type of Object + * @return the least frequently occurring object in the array + * given an array of objects, named `objectArray` return the least frequently occuring object in the array + */ + public static Object getLeastCommon(Object[] objectArray) { + return null; + } + + /** + * @param objectArray an array of any type of Object + * @param objectArrayToAdd an array of Objects to add to the first argument + * @return an array containing all elements in `objectArray` and `objectArrayToAdd` + * given two arrays `objectArray` and `objectArrayToAdd`, return an array containing all elements in `objectArray` and `objectArrayToAdd` + */ + public static Object[] mergeArrays(Object[] objectArray, Object[] objectArrayToAdd) { + return null; + } +} diff --git a/src/main/java/com/zipcodewilmington/assessment1/part2/MultiplesDeleter.java b/src/main/java/com/zipcodewilmington/assessment1/part2/MultiplesDeleter.java new file mode 100644 index 0000000..a348b0d --- /dev/null +++ b/src/main/java/com/zipcodewilmington/assessment1/part2/MultiplesDeleter.java @@ -0,0 +1,43 @@ +package com.zipcodewilmington.assessment1.part2; + +/** + * Created by leon on 2/16/18. + */ +public class MultiplesDeleter { + /** + * @param ints array of Integer objects + * @return all ints which are not divisible by 2 + * given an array of integers, named `ints` return an identical array with evens removed + */ + public Integer[] deleteEvens(Integer[] ints) { + return null; + } + + /** + * @param ints array of Integer objects + * @return all ints which are divisible by 2 + * given an array of integers, named `ints` return an identical array with odds removed + */ + public Integer[] deleteOdds(Integer[] ints) { + return null; + } + + /** + * @param ints array of Integer objects + * @return all ints which are not divisible by 3 + * given an array of integers, named `ints` return an identical array with numbers indivisible by 3 removed + */ + public Integer[] deleteMultiplesOf3(Integer[] ints) { + return null; + } + + /** + * @param ints array of Integer objects + * @param multiple the multiple to evaluate divisibility against + * @return all ints which are not divisible by the `multiple` specified + * given an array of integers, named `ints` return an identical array with numbers indivisible by `multiple` removed + */ + public Integer[] deleteMultiplesOfN(Integer[] ints, int multiple) { + return null; + } +} diff --git a/src/main/java/com/zipcodewilmington/assessment1/part2/StringUtils.java b/src/main/java/com/zipcodewilmington/assessment1/part2/StringUtils.java new file mode 100644 index 0000000..fc403e5 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/assessment1/part2/StringUtils.java @@ -0,0 +1,56 @@ +package com.zipcodewilmington.assessment1.part2; + +/** + * Created by leon on 2/16/18. + */ +public class StringUtils { + + /** + * @param sentence a string containing words delimited by spaces, representative of a sentence + * @return an array of strings, representative of each word in the sentence + * given a string containing words delimited by spaces, representative of a sentence, return an array of strings, each element representative of a respective word in the sentence + */ + public static String[] getWords(String sentence) { + return null; + } + + + /** + * @param sentence a string containing words delimited by spaces, representative of a sentence + * @return the first word in the specified sentence + * given a string containing words delimited by spaces, representative of a sentence, return the first word of the sentence + */ + public static String getFirstWord(String sentence) { + return null; + } + + /** + * @param sentence a string containing words delimited by spaces, representative of a sentence + * @return the first word in the specified sentence, with identical contents in reverse order + * given a string containing words delimited by spaces, representative of a sentence, return the first word with identical contents in reverse order + */ + public static String reverseFirstWord(String sentence) { + return null; + } + + /** + * @param sentence a string containing words delimited by spaces, representative of a sentence + * @return the first word in the specified sentence, with identical contents in reverse order and the first character capitalized + * given a string containing words delimited by spaces, representative of a sentence, return the first word with identical contents in reverse order with the first character capitalized + */ + public static String reverseFirstWordThenCamelCase(String sentence) { + return null; + } + + + /** + * @param str string input from client + * @param index the index of the character to be removed from `str` + * @return string with identical contents, excluding the character at the specified index + * given a string and index, return an identical string excluding the character at the specified index + */ + public static String removeCharacterAtIndex(String str, int index) { + return null; + } + +} diff --git a/src/main/java/com/zipcodewilmington/assessment1/part3/Animal.java b/src/main/java/com/zipcodewilmington/assessment1/part3/Animal.java new file mode 100644 index 0000000..658bb25 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/assessment1/part3/Animal.java @@ -0,0 +1,8 @@ +package com.zipcodewilmington.assessment1.part3; + +/** + * Created by leon on 2/16/18. + */ +public interface Animal { + String speak(); +} diff --git a/src/main/java/com/zipcodewilmington/assessment1/part3/Cat.java b/src/main/java/com/zipcodewilmington/assessment1/part3/Cat.java new file mode 100644 index 0000000..e731b77 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/assessment1/part3/Cat.java @@ -0,0 +1,43 @@ +package com.zipcodewilmington.assessment1.part3; + +/** + * Created by leon on 2/16/18. + */ +public class Cat extends Pet { + /** + * @param name name of this Cat + * @param age age of this Cat + */ + public Cat(String name, Integer age) { + + } + + /** + * @param age age of this Cat + */ + public Cat(Integer age) { + } + + /** + * @param name name of this Cat + */ + public Cat(String name) { + + } + + /** + * nullary constructor + * by default, a Cat's + * name is CatName + * age is 0 + */ + public Cat() { + } + + /** + * @return meow as a string + */ + public String speak() { + return null; + } +} diff --git a/src/main/java/com/zipcodewilmington/assessment1/part3/Dog.java b/src/main/java/com/zipcodewilmington/assessment1/part3/Dog.java new file mode 100644 index 0000000..0c775fd --- /dev/null +++ b/src/main/java/com/zipcodewilmington/assessment1/part3/Dog.java @@ -0,0 +1,43 @@ +package com.zipcodewilmington.assessment1.part3; + +/** + * Created by leon on 2/16/18. + */ +public class Dog extends Pet { + /** + * @param name name of this Dog + * @param age age of this dog + */ + public Dog(String name, Integer age) { + + } + + /** + * @param age age of this dog + */ + public Dog(Integer age) { + } + + /** + * @param name name of this dog + */ + public Dog(String name) { + + } + + /** + * nullary constructor + * by default, a dog's + * name is DogName + * age is 0 + */ + public Dog() { + } + + /** + * @return bark as a string + */ + public String speak() { + return null; + } +} diff --git a/src/main/java/com/zipcodewilmington/assessment1/part3/Pet.java b/src/main/java/com/zipcodewilmington/assessment1/part3/Pet.java new file mode 100644 index 0000000..3c925da --- /dev/null +++ b/src/main/java/com/zipcodewilmington/assessment1/part3/Pet.java @@ -0,0 +1,61 @@ +package com.zipcodewilmington.assessment1.part3; + +/** + * Created by leon on 2/16/18. + */ +public abstract class Pet implements Animal { + /** + * nullary constructor + * by default, pet has age of 0; name of ""; + */ + public Pet() { + } + + /** + * @param name name of this pet + */ + public Pet(String name) { + } + + + /** + * @param age age of this pet + */ + public Pet(int age) { + } + + /** + * @param name name of this pet + * @param age age of this pet + */ + public Pet(String name, int age) { + } + + /** + * @return name of this pet + */ + public String getName() { + return null; + } + + /** + * @return age of this pet + */ + public Integer getAge() { + return null; + } + + /** + * @param newPetOwner the new owner of this pet + * ensure this instance of `Pet` is added to the owner's composite `pets` list + */ + public void setOwner(PetOwner newPetOwner) { + } + + /** + * @return PetOwner object whose composite `pets` collection contains this Pet instance + */ + public PetOwner getOwner() { + return null; + } +} diff --git a/src/main/java/com/zipcodewilmington/assessment1/part3/PetOwner.java b/src/main/java/com/zipcodewilmington/assessment1/part3/PetOwner.java new file mode 100644 index 0000000..7bbf2ab --- /dev/null +++ b/src/main/java/com/zipcodewilmington/assessment1/part3/PetOwner.java @@ -0,0 +1,80 @@ +package com.zipcodewilmington.assessment1.part3; + +/** + * Created by leon on 2/16/18. + */ +public class PetOwner { + /** + * @param name name of the owner of the Pet + * @param pets array of Pet object + */ + public PetOwner(String name, Pet... pets) { + } + + /** + * @param pet pet to be added to the composite collection of Pets + */ + public void addPet(Pet pet) { + } + + /** + * @param pet pet to be removed from the composite collection Pets + */ + public void removePet(Pet pet) { + + } + + /** + * @param pet pet to evaluate ownership of + * @return true if I own this pet + */ + public Boolean isOwnerOf(Pet pet) { + return null; + } + + /** + * @return the age of the Pet object whose age field is the lowest amongst all Pets in this class + */ + public Integer getYoungetPetAge() { + return null; + } + + + + + /** + * @return the age of the Pet object whose age field is the highest amongst all Pets in this class + */ + public Integer getOldestPetAge() { + return null; + } + + + /** + * @return the sum of ages of Pet objects stored in this class divided by the number of Pet object + */ + public Float getAveragePetAge() { + return null; + } + + /** + * @return the number of Pet objects stored in this class + */ + public Integer getNumberOfPets() { + return null; + } + + /** + * @return the name property of the Pet + */ + public String getName() { + return null; + } + + /** + * @return array representation of animals owned by this PetOwner + */ + public Pet[] getPets() { + return null; + } +} diff --git a/src/main/java/com/zipcodewilmington/assessment1/part4/Jumper.java b/src/main/java/com/zipcodewilmington/assessment1/part4/Jumper.java new file mode 100644 index 0000000..f881e9c --- /dev/null +++ b/src/main/java/com/zipcodewilmington/assessment1/part4/Jumper.java @@ -0,0 +1,11 @@ +package com.zipcodewilmington.assessment1.part4; + +public class Jumper { + + /* + * Complete the function below. + */ + public int jumps(int k, int j) { + return -1; + } +} diff --git a/src/main/java/com/zipcodewilmington/assessment1/part5/Palindrome.java b/src/main/java/com/zipcodewilmington/assessment1/part5/Palindrome.java new file mode 100644 index 0000000..89e2016 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/assessment1/part5/Palindrome.java @@ -0,0 +1,8 @@ +package com.zipcodewilmington.assessment1.part5; + +public class Palindrome { + + public Integer countPalindromes(String input){ + return null; + } +} diff --git a/src/test/java/com/zipcodewilmington/assessment1/UnitTestingUtils.java b/src/test/java/com/zipcodewilmington/assessment1/UnitTestingUtils.java new file mode 100644 index 0000000..2326e7f --- /dev/null +++ b/src/test/java/com/zipcodewilmington/assessment1/UnitTestingUtils.java @@ -0,0 +1,27 @@ +package com.zipcodewilmington.assessment1; + +import org.junit.Assert; + +import java.util.Arrays; + +/** + * Created by leon on 1/28/18. + * + * @ATTENTION_TO_STUDENTS You are forbidden from modifying this class. + */ +public class UnitTestingUtils { + public synchronized static void assertArrayEquality(T[] expected, E[] actual) { + Arrays.sort(expected); + Arrays.sort(actual); + String expectedString = Arrays.toString(expected); + String actualString = Arrays.toString(actual); + boolean equality = expectedString.equals(actualString); + + System.out.println("\n\nExpected:\n\t" + expectedString); + System.out.println("\nActual:\n\t" + actualString); + System.out.println("\nEquivalence:\n\t" + equality); + + Assert.assertEquals(expectedString, actualString); + Assert.assertEquals(expected, actual); + } +} \ No newline at end of file diff --git a/src/test/java/com/zipcodewilmington/assessment1/part1/BasicArrayUtilsTest.java b/src/test/java/com/zipcodewilmington/assessment1/part1/BasicArrayUtilsTest.java new file mode 100644 index 0000000..4ce240f --- /dev/null +++ b/src/test/java/com/zipcodewilmington/assessment1/part1/BasicArrayUtilsTest.java @@ -0,0 +1,61 @@ +package com.zipcodewilmington.assessment1.part1; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by leon on 2/16/18. + */ +public class BasicArrayUtilsTest { + @Test + public void getFirstElementTest() { + // Given + String[] inputArray = {"The", "quick", "brown"}; + String expected = "The"; + + // When + String actual = BasicArrayUtils.getFirstElement(inputArray); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void getSecondTest() { + // Given + String[] inputArray = {"The", "quick", "brown"}; + String expected = "quick"; + + // When + String actual = BasicArrayUtils.getSecondElement(inputArray); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void getLastElementTest() { + // Given + String[] inputArray = {"The", "quick", "brown"}; + String expected = "brown"; + + // When + String actual = BasicArrayUtils.getLastElement(inputArray); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void getSecondToLastElementTest() { + // Given + String[] inputArray = {"The", "quick", "brown", "fox"}; + String expected = "brown"; + + // When + String actual = BasicArrayUtils.getSecondToLastElement(inputArray); + + // Then + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/zipcodewilmington/assessment1/part1/BasicStringUtilsTest.java b/src/test/java/com/zipcodewilmington/assessment1/part1/BasicStringUtilsTest.java new file mode 100644 index 0000000..86574a6 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/assessment1/part1/BasicStringUtilsTest.java @@ -0,0 +1,88 @@ +package com.zipcodewilmington.assessment1.part1; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by leon on 2/16/18. + */ +public class BasicStringUtilsTest { + @Test + public void camelCaseTest() { + // Given + String input = "the quick brown fox"; + String expected = "The quick brown fox"; + + // When + String actual = BasicStringUtils.camelCase(input); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void reverseTest() { + // Given + String input = "the quick brown fox"; + String expected = "xof nworb kciuq eht"; + + // When + String actual = BasicStringUtils.reverse(input); + + // Then + Assert.assertEquals(expected, actual); + } + + + @Test + public void reverseThenCamelCaseTest() { + // Given + String input = "the quick brown fox"; + String expected = "Xof nworb kciuq eht"; + + // When + String actual = BasicStringUtils.reverseThenCamelCase(input); + + // Then + Assert.assertEquals(expected, actual); + } + + + @Test + public void removeFirstAndLastCharacterTest() { + // Given + String input = "The quick brown"; + String expected = "he quick brow"; + + // When + String actual = BasicStringUtils.removeFirstAndLastCharacter(input); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void invertCasingTest1() { + // Given + String input = "tHE quiCK brOwN"; + String expected = "The QUIck BRoWn"; + + // When + String actual = BasicStringUtils.invertCasing(input); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void invertCasingTest2() { + // Given + String expected = "tHE quiCK brOwN"; + + // When + String actual = BasicStringUtils.invertCasing(BasicStringUtils.invertCasing(expected)); + + // Then + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/zipcodewilmington/assessment1/part1/IntegerArrayUtilsTest.java b/src/test/java/com/zipcodewilmington/assessment1/part1/IntegerArrayUtilsTest.java new file mode 100644 index 0000000..70d13f6 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/assessment1/part1/IntegerArrayUtilsTest.java @@ -0,0 +1,48 @@ +package com.zipcodewilmington.assessment1.part1; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by leon on 2/16/18. + */ +public class IntegerArrayUtilsTest { + @Test + public void getSumTest() { + // : Given + Integer[] input = { 1, 2, 3, 4, 5}; + Integer expected = 15; + + // : When + Integer actual = IntegerArrayUtils.getSum(input); + + // : Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testGetProduct() { + // : Given + Integer[] input = { 1, 2, 3, 4, 5}; + Integer expected = 120; + + // : When + Integer actual = IntegerArrayUtils.getProduct(input); + + // : Then + Assert.assertEquals(expected, actual); + } + + @Test + public void getAverageTest() { + // : Given + Integer[] input = { 1, 2, 3, 4, 5}; + Double expected = 3.0; + + // : When + Double actual = IntegerArrayUtils.getAverage(input); + + // : Then + Assert.assertEquals(expected, actual, 0.01); + } +} diff --git a/src/test/java/com/zipcodewilmington/assessment1/part1/IntegerUtilsTest.java b/src/test/java/com/zipcodewilmington/assessment1/part1/IntegerUtilsTest.java new file mode 100644 index 0000000..a5e30af --- /dev/null +++ b/src/test/java/com/zipcodewilmington/assessment1/part1/IntegerUtilsTest.java @@ -0,0 +1,48 @@ +package com.zipcodewilmington.assessment1.part1; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by leon on 2/16/18. + */ +public class IntegerUtilsTest { + @Test + public void getSumTest() { + // : Given + Integer input = 5; + Integer expected = 15; + + // : When + Integer actual = IntegerUtils.getSumOfN(input); + + // : Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testGetProduct() { + // : Given + Integer input = 5; + Integer expected = 120; + + // : When + Integer actual = IntegerUtils.getProductOfN(input); + + // : Then + Assert.assertEquals(expected, actual); + } + + @Test + public void reverseDigitsTest() { + // : Given + Integer input = 12345; + Integer expected = 54321; + + // : When + Integer actual = IntegerUtils.reverseDigits(input); + + // : Then + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/zipcodewilmington/assessment1/part1/RockPaperSissorsEvaluatorTest.java b/src/test/java/com/zipcodewilmington/assessment1/part1/RockPaperSissorsEvaluatorTest.java new file mode 100644 index 0000000..8f24c0b --- /dev/null +++ b/src/test/java/com/zipcodewilmington/assessment1/part1/RockPaperSissorsEvaluatorTest.java @@ -0,0 +1,52 @@ +package com.zipcodewilmington.assessment1.part1; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by leon on 2/16/18. + */ +public class RockPaperSissorsEvaluatorTest { + @Test + public void getWinningMoveTest() { + // Given + String input = "rock"; + String expected = "paper"; + RockPaperSissorsEvaluator rps = new RockPaperSissorsEvaluator(); + + // When + String actual = rps.getWinningMove(input); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void getLosingMoveTest() { + // Given + String input = "rock"; + String expected = "scissor"; + RockPaperSissorsEvaluator rps = new RockPaperSissorsEvaluator(); + + // When + String actual = rps.getLosingMove(input); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void getWinnerTest() { + // Given + String input1 = "rock"; + String input2 = "scissor"; + String expected = "rock"; + RockPaperSissorsEvaluator rps = new RockPaperSissorsEvaluator(); + + // When + String actual = rps.getWinner(input1, input2); + + // Then + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/zipcodewilmington/assessment1/part2/ArrayUtilsTest.java b/src/test/java/com/zipcodewilmington/assessment1/part2/ArrayUtilsTest.java new file mode 100644 index 0000000..6828b17 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/assessment1/part2/ArrayUtilsTest.java @@ -0,0 +1,79 @@ +package com.zipcodewilmington.assessment1.part2; + +import com.zipcodewilmington.assessment1.UnitTestingUtils; +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by leon on 2/16/18. + */ +public class ArrayUtilsTest { + @Test + public void getNumberOfOccurrencesTest1() { + // Given + Integer valueToEvaluate = 7; + Integer expected = 3; + Integer[] inputArray = {1, 2, 7, 8, 4, 5, 7, 0, 9, 8, 7}; + + // When + Integer actual = ArrayUtils.getNumberOfOccurrences(inputArray, valueToEvaluate); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void removeValueTest1() { + // Given + Integer valueToRemove = 7; + Integer[] expected = {1, 2, 8, 4, 5, 0, 9, 8}; + Integer[] inputArray = {1, 2, 7, 8, 4, 5, 7, 0, 9, 8, 7}; + + // When + Integer[] actual = (Integer[]) ArrayUtils.removeValue(inputArray, valueToRemove); + + // Then + UnitTestingUtils.assertArrayEquality(expected, actual); + } + + + @Test + public void getMostCommonTest() { + // Given + Integer expected = 7; + Integer[] inputArray = {1, 2, 7, 8, 4, 5, 7, 0, 9, 8, 7}; + + // When + Integer actual = (Integer) ArrayUtils.getMostCommon(inputArray); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void getLeastCommonTest() { + // Given + Integer expected = 2; + Integer[] inputArray = {1,1,2,3,3,3,4,4,4,4}; + + // When + Integer actual = (Integer) ArrayUtils.getLeastCommon(inputArray); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void mergeArraysTest() { + // Given + Integer[] array1 = {1,1,1,2,2,2}; + Integer[] array2 = {3,3,3,4,4,4}; + Integer[] expected = {1,1,1,2,2,2,3,3,3,4,4,4}; + + // When + Integer[] actual = (Integer[]) ArrayUtils.mergeArrays(array1, array2); + + // Then + UnitTestingUtils.assertArrayEquality(expected, actual); + } +} diff --git a/src/test/java/com/zipcodewilmington/assessment1/part2/MultiplesDeleterTest.java b/src/test/java/com/zipcodewilmington/assessment1/part2/MultiplesDeleterTest.java new file mode 100644 index 0000000..d7f2121 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/assessment1/part2/MultiplesDeleterTest.java @@ -0,0 +1,69 @@ +package com.zipcodewilmington.assessment1.part2; + +import com.zipcodewilmington.assessment1.UnitTestingUtils; +import org.junit.Test; + +/** + * Created by leon on 2/16/18. + */ +public class MultiplesDeleterTest { + MultiplesDeleter deleter = new MultiplesDeleter(); + + + @Test + public void deleteEvensTest() { + // Given + Integer[] inputArray = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + Integer[] expected = { 1, 3, 5, 7, 9 }; + + // When + Integer[] actual = deleter.deleteEvens(inputArray); + + // Then + UnitTestingUtils.assertArrayEquality(expected, actual); + } + + + @Test + public void deleteOddsTest() { + // Given + Integer[] inputArray = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + Integer[] expected = { 2, 4, 6, 8, 10 }; + + // When + Integer[] actual = deleter.deleteOdds(inputArray); + + // Then + UnitTestingUtils.assertArrayEquality(expected, actual); + } + + + @Test + public void deleteMultiplesOf3Test() { + // Given + Integer[] inputArray = { 3, 6, 9, 12, 15, 4, 7, 10, 13, 16}; + Integer[] expected = {4, 7, 10, 13, 16}; + + // When + Integer[] actual = deleter.deleteMultiplesOf3(inputArray); + + // Then + UnitTestingUtils.assertArrayEquality(expected, actual); + } + + + @Test + public void deleteMultiplesOfNTest() { + // Given + Integer multiple = 6; + Integer[] inputArray = { 6, 12, 18, 24, 30, 4, 7, 10, 13, 16}; + Integer[] expected = {4, 7, 10, 13, 16}; + + // When + Integer[] actual = deleter.deleteMultiplesOfN(inputArray, multiple); + + // Then + UnitTestingUtils.assertArrayEquality(expected, actual); + } + +} diff --git a/src/test/java/com/zipcodewilmington/assessment1/part2/StringUtilsTest.java b/src/test/java/com/zipcodewilmington/assessment1/part2/StringUtilsTest.java new file mode 100644 index 0000000..3d874a3 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/assessment1/part2/StringUtilsTest.java @@ -0,0 +1,80 @@ +package com.zipcodewilmington.assessment1.part2; + +import com.zipcodewilmington.assessment1.UnitTestingUtils; +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by leon on 2/16/18. + */ +public class StringUtilsTest { + @Test + public void getWordsTest() { + // Given + String inputString = "The quick brown fox jumps"; + String[] expected = {"The", "quick", "brown", "fox", "jumps"}; + + // When + String[] actual = StringUtils.getWords(inputString); + + // Then + UnitTestingUtils.assertArrayEquality(expected, actual); + } + + + @Test + public void getFirstWordTest() { + // Given + String inputString = "Quick Brown Fox"; + String expected = "Quick"; + + // When + String actual = StringUtils.getFirstWord(inputString); + + // Then + Assert.assertEquals(expected, actual); + } + + + @Test + public void reverseFirstWordTest() { + // Given + String inputString = "Noel Hunter"; + String expected = "leoN"; + + // When + String actual = StringUtils.reverseFirstWord(inputString); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void reverseFirstWordThenCamelCaseTest() { + // Given + String inputString = "noel Hunter"; + String expected = "Leon"; + + // When + String actual = StringUtils.reverseFirstWordThenCamelCase(inputString); + + // Then + Assert.assertEquals(expected, actual); + } + + + @Test + public void removeCharacterAtIndexTest() { + // Given + String inputString = "Jumping"; + Integer characterIndex = 2; + String expected = "Juping"; + + // When + String actual = StringUtils.removeCharacterAtIndex(inputString, characterIndex); + + // Then + Assert.assertEquals(expected, actual); + } + +} diff --git a/src/test/java/com/zipcodewilmington/assessment1/part3/CatTest.java b/src/test/java/com/zipcodewilmington/assessment1/part3/CatTest.java new file mode 100644 index 0000000..fcc223f --- /dev/null +++ b/src/test/java/com/zipcodewilmington/assessment1/part3/CatTest.java @@ -0,0 +1,94 @@ +package com.zipcodewilmington.assessment1.part3; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by leon on 2/16/18. + */ +public class CatTest { + @Test + public void nullaryConstructorTest() { + // Given + PetOwner expectedOwner = null; + String expectedName = "Cat name"; + Integer expectedAge = 0; + Cat cat = new Cat(); + + // When + String actualName = cat.getName(); + Integer actualAge = cat.getAge(); + PetOwner actualOwner = cat.getOwner(); + + + // Then + Assert.assertEquals(expectedAge, actualAge); + Assert.assertEquals(expectedName, actualName); + Assert.assertEquals(expectedOwner, actualOwner); + } + + @Test + public void constructorWithNameTest() { + // Given + String expectedName = "Name of Cat"; + Integer expectedAge = 0; + Cat cat = new Cat(expectedName); + + // When + String actualName = cat.getName(); + Integer actualAge = cat.getAge(); + + + // Then + Assert.assertEquals(expectedAge, actualAge); + Assert.assertEquals(expectedName, actualName); + } + + + @Test + public void constructorWithAgeTest() { + // Given + String expectedName = "Cat name"; + Integer expectedAge = Integer.MAX_VALUE; + Cat cat = new Cat(expectedAge); + + // When + String actualName = cat.getName(); + Integer actualAge = cat.getAge(); + + + // Then + Assert.assertEquals(expectedAge, actualAge); + Assert.assertEquals(expectedName, actualName); + } + + @Test + public void constructorWithNameAndAgeTest() { + // Given + String expectedName = "Name of Cat"; + Integer expectedAge = Integer.MAX_VALUE; + Cat cat = new Cat(expectedName, expectedAge); + + // When + String actualName = cat.getName(); + Integer actualAge = cat.getAge(); + + + // Then + Assert.assertEquals(expectedAge, actualAge); + Assert.assertEquals(expectedName, actualName); + } + + @Test + public void speakTest() { + // Given + Cat cat = new Cat(); + String expected = "Meow"; + + // When + String actual = cat.speak(); + + // Then + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/zipcodewilmington/assessment1/part3/DogTest.java b/src/test/java/com/zipcodewilmington/assessment1/part3/DogTest.java new file mode 100644 index 0000000..09b376b --- /dev/null +++ b/src/test/java/com/zipcodewilmington/assessment1/part3/DogTest.java @@ -0,0 +1,94 @@ +package com.zipcodewilmington.assessment1.part3; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by leon on 2/16/18. + */ +public class DogTest { + @Test + public void nullaryConstructorTest() { + // Given + PetOwner expectedOwner = null; + String expectedName = "Dog name"; + Integer expectedAge = 0; + Dog dog = new Dog(); + + // When + String actualName = dog.getName(); + Integer actualAge = dog.getAge(); + PetOwner actualOwner = dog.getOwner(); + + + // Then + Assert.assertEquals(expectedAge, actualAge); + Assert.assertEquals(expectedName, actualName); + Assert.assertEquals(expectedOwner, actualOwner); + } + + @Test + public void constructorWithNameTest() { + // Given + String expectedName = "Name of Dog"; + Integer expectedAge = 0; + Dog dog = new Dog(expectedName); + + // When + String actualName = dog.getName(); + Integer actualAge = dog.getAge(); + + + // Then + Assert.assertEquals(expectedAge, actualAge); + Assert.assertEquals(expectedName, actualName); + } + + + @Test + public void constructorWithAgeTest() { + // Given + String expectedName = "Dog name"; + Integer expectedAge = Integer.MAX_VALUE; + Dog dog = new Dog(expectedAge); + + // When + String actualName = dog.getName(); + Integer actualAge = dog.getAge(); + + + // Then + Assert.assertEquals(expectedAge, actualAge); + Assert.assertEquals(expectedName, actualName); + } + + @Test + public void constructorWithNameAndAgeTest() { + // Given + String expectedName = "Name of Dog"; + Integer expectedAge = Integer.MAX_VALUE; + Dog dog = new Dog(expectedName, expectedAge); + + // When + String actualName = dog.getName(); + Integer actualAge = dog.getAge(); + + + // Then + Assert.assertEquals(expectedAge, actualAge); + Assert.assertEquals(expectedName, actualName); + } + + @Test + public void speakTest() { + // Given + Dog dog = new Dog(); + String expected = "Bark"; + + // When + String actual = dog.speak(); + + // Then + Assert.assertEquals(expected, actual); + } +} \ No newline at end of file diff --git a/src/test/java/com/zipcodewilmington/assessment1/part3/PetOwnerTest.java b/src/test/java/com/zipcodewilmington/assessment1/part3/PetOwnerTest.java new file mode 100644 index 0000000..7dd24ee --- /dev/null +++ b/src/test/java/com/zipcodewilmington/assessment1/part3/PetOwnerTest.java @@ -0,0 +1,178 @@ +package com.zipcodewilmington.assessment1.part3; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +/** + * Created by leon on 2/16/18. + */ +public class PetOwnerTest { + @Test + public void constructorTest() { + // Given + String expectedName = "George"; + Pet expectedPet = new Dog(); + + // When + PetOwner po = new PetOwner(expectedName, expectedPet); + String actualName = po.getName(); + Pet actualPet = po.getPets()[0]; + + // Then + Assert.assertEquals(expectedName, actualName); + Assert.assertEquals(expectedPet, actualPet); + } + + @Test + public void addPetTest1() { + // Given + Pet expected = new Dog(); + PetOwner po = new PetOwner("", null); + + // When + po.addPet(expected); + Pet actual = po.getPets()[0]; + + // Then + Assert.assertEquals(actual, expected); + } + + @Test + public void addPetTest2() { + // Given + Pet newPet = new Dog(); + PetOwner po = new PetOwner("", null); + + // When + po.addPet(newPet); + + // Then + boolean outcome = po.isOwnerOf(newPet); + Assert.assertTrue(outcome); + } + + @Test + public void removePetTest() { + // Given + Pet newPet = new Dog(); + PetOwner po = new PetOwner("", newPet); + Pet expected = null; + + // When + po.removePet(newPet); + Pet actual = po.getPets()[0]; + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void isOwnerOfTest() { + // Given + Pet newPet = new Dog(); + Pet anotherPet = new Dog(); + PetOwner po = new PetOwner("", newPet); + + // When + boolean outcome = po.isOwnerOf(newPet); + boolean poOwnsAnotherPet = po.isOwnerOf(anotherPet); + + // Then + Assert.assertTrue(outcome); + Assert.assertFalse(poOwnsAnotherPet); + } + + + @Test + public void getYoungestPetAgeTest() { + // Given + int expected = 1; + Pet oneYearOldPuppy = new Dog(expected); + Pet twoYearOldKitten = new Cat(2); + PetOwner po = new PetOwner("", oneYearOldPuppy, twoYearOldKitten); + + // When + int actual = po.getYoungetPetAge(); + + // Then + Assert.assertEquals(expected, actual); + + } + + @Test + public void getOldestPetAgeTest() { + // Given + int expected = 2; + Pet oneYearOldPuppy = new Dog(1); + Pet twoYearOldKitten = new Cat(expected); + PetOwner po = new PetOwner("", oneYearOldPuppy, twoYearOldKitten); + + // When + int actual = po.getOldestPetAge(); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void getAveragePetAgeTest() { + // Given + Float expected = 3F; + Pet oneYearOldPuppy = new Dog(4); + Pet twoYearOldKitten = new Cat(2); + PetOwner po = new PetOwner("", oneYearOldPuppy, twoYearOldKitten); + + // When + Float actual = po.getAveragePetAge(); + + // Then + Assert.assertEquals(expected, actual, 0.05); + } + + @Test + public void getNumberOfPetsTest() { + // Given + Integer expected = 2; + Pet oneYearOldPuppy = new Dog(4); + Pet twoYearOldKitten = new Cat(2); + PetOwner po = new PetOwner("", oneYearOldPuppy, twoYearOldKitten); + + // When + Integer actual = po.getNumberOfPets(); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void getNameTest() { + // Given + String expected = "Pet owner name"; + PetOwner po = new PetOwner(expected); + + // When + String actual = po.getName(); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void getPets() { + // Given + Pet oneYearOldPuppy = new Dog(4); + Pet twoYearOldKitten = new Cat(2); + Pet[] pets = { oneYearOldPuppy, twoYearOldKitten }; + PetOwner po = new PetOwner("", oneYearOldPuppy, twoYearOldKitten); + List petList = Arrays.asList(po.getPets()); + + // When + // Then + for(Pet pet : pets) { + Assert.assertTrue(petList.contains(pet)); + } + } +} diff --git a/src/test/java/com/zipcodewilmington/assessment1/part3/PetTest.java b/src/test/java/com/zipcodewilmington/assessment1/part3/PetTest.java new file mode 100644 index 0000000..038d98b --- /dev/null +++ b/src/test/java/com/zipcodewilmington/assessment1/part3/PetTest.java @@ -0,0 +1,49 @@ +package com.zipcodewilmington.assessment1.part3; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by leon on 2/16/18. + */ +public class PetTest { + @Test + public void testInheritance() { + Pet p = new Dog(); + Assert.assertTrue(p instanceof Pet); + } + + @Test + public void testImplementation() { + Pet p = new Dog(); + Assert.assertTrue(p instanceof Animal); + } + + @Test + public void setOwnerTest() { + // Given + Pet p = new Dog(); + PetOwner expected = new PetOwner(null, null); + + // When + p.setOwner(expected); + PetOwner actual = p.getOwner(); + + // Then + Assert.assertEquals(expected, actual); + } + + + @Test + public void getOwnerTest() { + // Given + Pet p = new Dog(); + PetOwner expected = new PetOwner(null, p); + + // When + PetOwner actual = p.getOwner(); + + // Then + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/zipcodewilmington/assessment1/part4/JumperTest.java b/src/test/java/com/zipcodewilmington/assessment1/part4/JumperTest.java new file mode 100644 index 0000000..e22bb27 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/assessment1/part4/JumperTest.java @@ -0,0 +1,66 @@ +package com.zipcodewilmington.assessment1.part4; + +import org.junit.Assert; +import org.junit.Test; + +public class JumperTest { + + @Test + public void solution0(){ + Jumper jumper = new Jumper(); + Integer expected = jumper.jumps(3,1); + Integer actual = 3; + Assert.assertEquals(expected, actual); + + } + + @Test + public void solution1(){ + // Should assert to true + Jumper jumper = new Jumper(); + Integer expected = jumper.jumps(3,2); + Integer actual = 2; + Assert.assertEquals(expected, actual); + + } + + @Test + public void solution2(){ + // Should assert to true + Jumper jumper = new Jumper(); + Integer expected = jumper.jumps(3,3); + Integer actual = 1; + Assert.assertEquals(expected, actual); + + } + + @Test + public void solution3(){ + // Should assert to true + Jumper jumper = new Jumper(); + Integer expected = jumper.jumps(16808,282475250); + Integer actual = 16808; + Assert.assertEquals(expected, actual); + + } + + @Test + public void solution4(){ + // Should assert to true + Jumper jumper = new Jumper(); + Integer expected = jumper.jumps(458777924,7237710); + Integer actual = 2802257; + Assert.assertEquals(expected, actual); + + } + + @Test + public void solution5(){ + // Should assert to true + Jumper jumper = new Jumper(); + Integer expected = jumper.jumps(823564441,115438166); + Integer actual = 15497286; + Assert.assertEquals(expected, actual); + + } +} diff --git a/src/test/java/com/zipcodewilmington/assessment1/part5/PalindromeTest.java b/src/test/java/com/zipcodewilmington/assessment1/part5/PalindromeTest.java new file mode 100644 index 0000000..f043c9c --- /dev/null +++ b/src/test/java/com/zipcodewilmington/assessment1/part5/PalindromeTest.java @@ -0,0 +1,66 @@ +package com.zipcodewilmington.assessment1.part5; + +import org.junit.Assert; +import org.junit.Test; + +public class PalindromeTest { + + @Test + public void solution0(){ + Palindrome palindrome = new Palindrome(); + Integer expected = palindrome.countPalindromes("aaa"); + Integer actual = 6; + Assert.assertEquals(expected, actual); + + } + + @Test + public void solution1(){ + // Should assert to true + Palindrome palindrome = new Palindrome(); + Integer expected = palindrome.countPalindromes("abccba"); + Integer actual = 9; + Assert.assertEquals(expected, actual); + + } + + @Test + public void solution2(){ + // Should assert to true + Palindrome palindrome = new Palindrome(); + Integer expected = palindrome.countPalindromes("daata"); + Integer actual = 7; + Assert.assertEquals(expected, actual); + + } + + @Test + public void solution3(){ + // Should assert to true + Palindrome palindrome = new Palindrome(); + Integer expected = palindrome.countPalindromes("lrfkqyuqfj"); + Integer actual = 10; + Assert.assertEquals(expected, actual); + + } + + @Test + public void solution4(){ + // Should assert to true + Palindrome palindrome = new Palindrome(); + Integer expected = palindrome.countPalindromes("kxyqvnrtys"); + Integer actual = 10; + Assert.assertEquals(expected, actual); + + } + + @Test + public void solution5(){ + // Should assert to true + Palindrome palindrome = new Palindrome(); + Integer expected = palindrome.countPalindromes("ltvzkqtpvolphckcyufdqmlglimklfzktgygdttnhcvpfdfbrpzlkvshwywshtdgmbqbkkxcvgumonmwvytbytnuqhmfjaqtgngcwkuzyamnerphfmwevhwlezohyeehbrcewjxvceziftiqtntfsrptugtiznorvonzjfeacgamayapwlmbzitzszhzkosvnknberbltlkggdgpljfisyltmmfvhybljvkypcflsaqevcijcyrgmqirzniaxakholawoydvchveigttxwpukzjfhxbrtspfttotafsngqvoijxuvqbztvaalsehzxbshnrvbykjqlrzzfmlvyoshiktodnsjjpqplciklzqrxloqxrudygjtyzleizmeainxslwhhjwslqendjvxjyghrveuvphknqtsdtwxcktmwwwsdthzmlmbhjkmouhpbqurqfxgqlojmwsomowsjvpvhznbsilhhdkbdxqgrgedpzchrgefeukmcowoeznwhpiiduxdnnlbnmyjyssbsococdzcuunkrfduvouaghhcyvmlkzaajpfpyljtyjjpyntsefxiswjutenuycpbcnmhfuqmmidmvknyxmywegmtunodvuzygvguxtrdsdfzfssmeluodjgdgzfmrazvndtaurdkugsbdpawxitivdubbqeonycaegxfjkklrfkraoheucsvpiteqrswgkaaaohxxzhqjtkqaqhkwberbpmglbjipnujywogwczlkyrdejaqufowbigrsnjniegvdvotugocedktcbbufnxorixibbdfrzuqsyrfqghoyqevcuanuujszitaoaowsxyglafbwzddoznrvjqeyqignpitruijvyllsibobjltusrypanvybsfrxtlfmpdidtyozoolzslgdgowijatklvjzscizrkupmsoxftumyxifyunxucubvkfctkqlroqgzjvjwzizppvsomflvioemycnp"); + Integer actual = 1084; + Assert.assertEquals(expected, actual); + + } +}