From fd2e738b97908d27956aec649d73d7913d58d7c6 Mon Sep 17 00:00:00 2001 From: Ian Date: Fri, 23 Apr 2021 09:36:15 -0500 Subject: [PATCH] Committing for merge --- bin/.gitignore | 9 ++ bin/README.md | 33 +++++++ bin/codingChallenge.md | 26 +++++ bin/pom.xml | 56 +++++++++++ .../java/com/github/archarithms/App.class | Bin 0 -> 1407 bytes .../archarithms/test/DateStringTests.class | Bin 0 -> 2415 bytes .../archarithms/test/TitleCaseTests.class | Bin 0 -> 1870 bytes pom.xml | 5 + src/main/java/com/github/archarithms/App.java | 19 +++- .../com/github/archarithms/DateObject.java | 93 ++++++++++++++++++ .../archarithms/test/DateStringTests.java | 12 ++- 11 files changed, 248 insertions(+), 5 deletions(-) create mode 100644 bin/.gitignore create mode 100644 bin/README.md create mode 100644 bin/codingChallenge.md create mode 100644 bin/pom.xml create mode 100644 bin/src/main/java/com/github/archarithms/App.class create mode 100644 bin/src/test/java/com/github/archarithms/test/DateStringTests.class create mode 100644 bin/src/test/java/com/github/archarithms/test/TitleCaseTests.class create mode 100644 src/main/java/com/github/archarithms/DateObject.java diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..773c56d --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1,9 @@ +.classpath +.project +.settings/ +target/ +nbproject/* +.settings +runtime/* +*~ +.DS_Store diff --git a/bin/README.md b/bin/README.md new file mode 100644 index 0000000..42412fc --- /dev/null +++ b/bin/README.md @@ -0,0 +1,33 @@ +# Archarithm's Coding Challenge - Overview + +## Software Requirements +Java - https://www.java.com/en/ + +Maven - http://maven.apache.org + +Junit 5 - https://junit.org/junit5/ + +## Getting started +Clone the project, clean, and compile (no unit tests) with: `mvn clean install -DskipTests`. + +Run unit tests with: `mvn test` or `mvn install`. + +Refer to the coding challenge instructions found in `codingChallenge.md` + +Complete both of the challenges listed in `codingChallenge.md` and follow the instructions below to submit +your solution. Good luck! + +## Instructions +1. Create a feature branch + +2. Create all challenge 1 unit tests (and write additional unit tests if needed) in `com.github.archarithms.test.TitleCaseTests`. + +3. Write corresponding method in `com.github.archarithms.App` for challenge 1. + +4. Create all challenge 2 unit tests (and write additional unit tests if needed) in `com.github.archarithms.test.DateStringTests`. + +5. Write corresponding method in `com.github.archarithms.App` for challenge 2. + +6. Ensure all unit tests run successfully with: `mvn test`. + +7. Push your feature branch and submit a pull request. \ No newline at end of file diff --git a/bin/codingChallenge.md b/bin/codingChallenge.md new file mode 100644 index 0000000..bdebf15 --- /dev/null +++ b/bin/codingChallenge.md @@ -0,0 +1,26 @@ +# Archarithm's Coding Challenge - 1 & 2 + +## Challenge 1 +Create a function that takes in a constant-formatted (all caps, +words separated by underscores) string and returns the string +in "title case" (see examples below). The function should remove all non alphanumeric +characters and replace them with spaces. But no spaces at the end +of the result. A `null` input should throw an error. + +If you so choose feel free to leverage third party libraries to complete your solution. + +For example: +`"THIS_INPUT"` should return `"This Input"` +`"CASE-THREE_extra[chars]///"` should return `"Case Three Extra Chars"` + + +## Challenge 2 +Create a function that takes in a unix epoch time in seconds (long data type) and returns a String +that is the input timestamp converted and formatted as month day, year (see below). If no timestamp is given the function +should return today’s date. If the input is null or has an incorrect type, an error should be +thrown. + +If you so choose feel free to leverage third party libraries to complete your solution. + +For example, passing a unix epoch time `1499144400` in seconds (long data type) +would return `"July 4, 2017"` in this date format (string data type). diff --git a/bin/pom.xml b/bin/pom.xml new file mode 100644 index 0000000..8f6b076 --- /dev/null +++ b/bin/pom.xml @@ -0,0 +1,56 @@ + + 4.0.0 + + com.github.archarithms + java-interview + 0.0.1 + jar + + java-interview + http://archarithms.com + + + UTF-8 + 1.8 + 3.8.1 + 2.22.1 + ${maven.compiler.source} + 5.4.2 + 2.9.7 + + + + + org.junit.jupiter + junit-jupiter-api + ${junit.jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + test + + + joda-time + joda-time + ${joda.time.version} + + + + + + + maven-compiler-plugin + ${maven.compiler.version} + + + maven-surefire-plugin + ${maven.surefire.version} + + + + diff --git a/bin/src/main/java/com/github/archarithms/App.class b/bin/src/main/java/com/github/archarithms/App.class new file mode 100644 index 0000000000000000000000000000000000000000..ff3e69bb28d015bf439ab68df4d9c966e8001c9a GIT binary patch literal 1407 zcmb_c&2H2%5FUrJKk34jLMgwk=_&0Yxp1Ng2^EkkrEuuB5=XD&-E~RqU^`X&06Y^C zNO0$&5aXoFF47`Z&_gVbXXcx4CNuNn=a+8)5W`j*0s@gWJSmt|$q74U3D-q3mTpoF z6K42?8N3%Zd0CciSR$}e8|6%mlXt@t!5x9tbE%|zLEu`neN13!PiLYHT>|}??Q3JS z>A*4xHjb1LR_CW8qZq4{Idf7gS{gmfMPZ-OusfIt>ds3+JwWV(#Z55EnNr%(p`cTc znC?3&EtM*h2KnUYs2T|)6vqf7qYIQjR;bHp%yVWf9m!nSCQ2so$*W4nKd`Z&TgWMH z@{i~8-=diomipKQb9_P_QWR$;2Ap@sQpUcNaZUU$P+@n!D09iBqqZuA!7?c8OvRlx zw8=Bt_9;~=6CVFRwhR}f{)c72ESQ%v`5RSbn0Fl-tEtEuKJKgMSD^2Otln@CGw zC%tTg?;;Qu?o=2z&;#jmvB#`OkJ4%M>7@gA3FMb(1CB!( zrM~F9+cSC(2z4Y}WzK zzlA4&YXz4T;7PD6T6nfmdRof>;aBLqUkyJ)?>oK*(8tr;0DdcY_Ud~Gw_p{eF5HGY r7YI9lAgnDwXw?Wo?Y9p17W&;^;J5tSFMx;W9l#^Z!}AK@F>L+<4@sP2 literal 0 HcmV?d00001 diff --git a/bin/src/test/java/com/github/archarithms/test/DateStringTests.class b/bin/src/test/java/com/github/archarithms/test/DateStringTests.class new file mode 100644 index 0000000000000000000000000000000000000000..4e3428097509b661fad915bbe604015c0b314746 GIT binary patch literal 2415 zcmdT`O>Yx15FM97lBG~6-}EwYN~N+95=cN15-K273gwW1#L?Mx5|>?jvAv-c;&&l| z1b2@774C?!7nD%86jextLo9zxX2$Q$oAsx!?>+!P49g9eV{qG=q~n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V?d00001 diff --git a/pom.xml b/pom.xml index 8f6b076..25acd3b 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,11 @@ joda-time ${joda.time.version} + + org.apache.commons + commons-lang3 + 3.11 + diff --git a/src/main/java/com/github/archarithms/App.java b/src/main/java/com/github/archarithms/App.java index dcb6723..9726d7d 100644 --- a/src/main/java/com/github/archarithms/App.java +++ b/src/main/java/com/github/archarithms/App.java @@ -1,15 +1,28 @@ package com.github.archarithms; +import java.io.IOException; +import java.util.Date; + +import org.apache.commons.lang3.text.WordUtils; public class App { public static String convertToTitleCase(final String inpStr) { - return inpStr; + String cleanString = inpStr.replaceAll("[^a-zA-Z0-9]", " "); + return WordUtils.capitalizeFully(cleanString); } - public static String convertUnixToDateString(final Long inpUnixSeconds) + public static String convertUnixToDateString(final Long inpUnixSeconds) throws IOException { - return String.valueOf(inpUnixSeconds); + if(inpUnixSeconds == null) + throw new IOException("null input"); + Date finalDate = new Date(inpUnixSeconds*1000); + DateObject returnDate = new DateObject(finalDate); + return String.valueOf(formatDate(returnDate)); + } + + private static String formatDate(DateObject dateObject) { + return String.valueOf(dateObject.getMonth() + " " + dateObject.getDay() + ", " + dateObject.getYear()); } } diff --git a/src/main/java/com/github/archarithms/DateObject.java b/src/main/java/com/github/archarithms/DateObject.java new file mode 100644 index 0000000..fb9ed95 --- /dev/null +++ b/src/main/java/com/github/archarithms/DateObject.java @@ -0,0 +1,93 @@ +package com.github.archarithms; + +import java.time.Month; +import java.time.format.TextStyle; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; + +public class DateObject { + + private int year; + private String month; + private int day; + + /*The md says to throw an exception if null or wrong type and provide today's date if "no timestamp is given" + * Since the function takes in a long, it can't take a "wrong type" and if it's null it throws an exception + * So I'm not really sure how this would be called, but I added a default constructor that returns today's date if no parameter is passed in + */ + public DateObject() { + this.year = Calendar.getInstance().get(Calendar.YEAR); + this.month = Month.of(Calendar.getInstance().get(Calendar.MONTH)).getDisplayName(TextStyle.FULL_STANDALONE, null); + this.day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); + } + + public DateObject(int year, String month, int day) { + super(); + this.year = year; + this.month = month; + this.day = day; + } + + public DateObject(Date date) { + this.year = date.getYear() + 1900; + this.month = Month.of(date.getMonth()+1).getDisplayName(TextStyle.FULL_STANDALONE, Locale.ENGLISH); + this.day = date.getDate(); + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public String getMonth() { + return month; + } + + public void setMonth(String month) { + this.month = month; + } + + public int getDay() { + return day; + } + + public void setDay(int day) { + this.day = day; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + day; + result = prime * result + ((month == null) ? 0 : month.hashCode()); + result = prime * result + year; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + DateObject other = (DateObject) obj; + if (day != other.day) + return false; + if (month == null) { + if (other.month != null) + return false; + } else if (!month.equals(other.month)) + return false; + if (year != other.year) + return false; + return true; + } + +} diff --git a/src/test/java/com/github/archarithms/test/DateStringTests.java b/src/test/java/com/github/archarithms/test/DateStringTests.java index 04e9943..c5e8aa1 100644 --- a/src/test/java/com/github/archarithms/test/DateStringTests.java +++ b/src/test/java/com/github/archarithms/test/DateStringTests.java @@ -2,6 +2,9 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +import java.io.IOException; import org.junit.jupiter.api.Test; @@ -22,8 +25,13 @@ public class DateStringTests */ @Test public void testConvertUnixToDateString() { - String testStr = "July 4, 2017"; - assertTrue(testStr.equals(App.convertUnixToDateString(1499144400L))); + try { + String testStr = "July 4, 2017"; + String result = App.convertUnixToDateString(1499144400L); + assertTrue(testStr.equals(result)); + } catch(IOException e) { + fail("Exception thrown"); + } } /**