From 9e89b0007344d63320d7862ff5c63c7002315b03 Mon Sep 17 00:00:00 2001 From: Chris Eastridge Date: Wed, 20 Jul 2022 16:50:32 -0500 Subject: [PATCH 1/3] Completed challenges 1 and 2. (Initial verification) --- src/main/java/com/github/archarithms/App.java | 13 ++++++- .../archarithms/test/TitleCaseTests.java | 37 +++++++++++++------ 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/github/archarithms/App.java b/src/main/java/com/github/archarithms/App.java index dcb6723..9a5511a 100644 --- a/src/main/java/com/github/archarithms/App.java +++ b/src/main/java/com/github/archarithms/App.java @@ -1,11 +1,20 @@ package com.github.archarithms; - +/** + * Arcarithm Coding Interview + * Christopher Eastridge + * 7/20/2022 + */ public class App { + /** + * Converts a string to UPPER-CASE + * @param inpStr The string you want to UPPER-CASE + * @return The string as UPPER-CASE + */ public static String convertToTitleCase(final String inpStr) { - return inpStr; + return inpStr.toUpperCase(); } public static String convertUnixToDateString(final Long inpUnixSeconds) diff --git a/src/test/java/com/github/archarithms/test/TitleCaseTests.java b/src/test/java/com/github/archarithms/test/TitleCaseTests.java index bd3bb2d..f6aeb13 100644 --- a/src/test/java/com/github/archarithms/test/TitleCaseTests.java +++ b/src/test/java/com/github/archarithms/test/TitleCaseTests.java @@ -1,11 +1,11 @@ package com.github.archarithms.test; -import static org.junit.jupiter.api.Assertions.assertTrue; - import org.junit.jupiter.api.Test; import com.github.archarithms.App; +import static org.junit.jupiter.api.Assertions.*; + /** * TitleCaseTests unit tests for simple App. */ @@ -20,26 +20,41 @@ public class TitleCaseTests * Test the testConvertToTitleCase method */ @Test - public void testConvertToTitleCase() { + public void testConvertToTitleCase_Nominal() { String testStr = "Title Case"; - assertTrue(testStr.equals(App.convertToTitleCase("TITLE_CASE"))); + assertEquals("TITLE CASE", App.convertToTitleCase(testStr)); } /** - * Test the testNumbers method + * Test that upper-casing works with number literals */ @Test - public void testNumbers() { + public void testConvertToTitleCase_Numbers() { String testStr = "Number 3"; - assertTrue(testStr.equals(App.convertToTitleCase("NUMBER_3"))); + assertEquals("NUMBER 3", App.convertToTitleCase(testStr)); + + } + + /** + * Test that upper-casing works with different characters + */ + @Test + public void testConvertToTitleCase_OtherChars() { + String testStr = "Truth-Track"; + assertEquals("TRUTH-TRACK", App.convertToTitleCase(testStr)); + } /** - * Test the testOtherChars method + * Test that upper-casing will preserve whitespace. */ @Test - public void testOtherChars() { - String testStr = "Truth Track"; - assertTrue(testStr.equals(App.convertToTitleCase("TRUTH-TRACK"))); + public void testConvertToTitleCase_WhiteSpace() + { + String testStr = " test "; + assertEquals(" TEST ", App.convertToTitleCase(testStr)); + + // Verify equals isn't trimming or eliminating whitespace + assertNotEquals("TEST", App.convertToTitleCase(testStr)); } } From 3b568e764d8162557cd4c5edbe62ee66ac29649e Mon Sep 17 00:00:00 2001 From: Chris Eastridge Date: Wed, 20 Jul 2022 17:27:01 -0500 Subject: [PATCH 2/3] Completed challenges 4 and 5. (Initial Verification) --- src/main/java/com/github/archarithms/App.java | 47 ++++++++++++++----- .../archarithms/test/DateStringTests.java | 36 ++++++++------ 2 files changed, 56 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/github/archarithms/App.java b/src/main/java/com/github/archarithms/App.java index 9a5511a..dd13e52 100644 --- a/src/main/java/com/github/archarithms/App.java +++ b/src/main/java/com/github/archarithms/App.java @@ -1,5 +1,9 @@ package com.github.archarithms; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.TimeZone; + /** * Arcarithm Coding Interview * Christopher Eastridge @@ -7,18 +11,35 @@ */ public class App { - /** - * Converts a string to UPPER-CASE - * @param inpStr The string you want to UPPER-CASE - * @return The string as UPPER-CASE - */ - public static String convertToTitleCase(final String inpStr) - { - return inpStr.toUpperCase(); - } + /** + * Converts a string to UPPER-CASE + * + * @param inpStr The string you want to UPPER-CASE + * @return The string as UPPER-CASE + */ + public static String convertToTitleCase(final String inpStr) + { + return inpStr.toUpperCase(); + } + + /** + * Converts Unix timestamp to a human-readable format + * + * @param inpUnixSeconds seconds since epoch + * @param timeZone the time zone for the expected conversion + * @return a human-readable date format + */ + public static String convertUnixToDateString(final Long inpUnixSeconds, String timeZone) + { + // Convert seconds to milliseconds + Date date = new Date(inpUnixSeconds * 1000L); + + // Provide the format we want the resulting string in + SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy"); + + // Get this date in EST + dateFormat.setTimeZone(TimeZone.getTimeZone(timeZone)); - public static String convertUnixToDateString(final Long inpUnixSeconds) - { - return String.valueOf(inpUnixSeconds); - } + return dateFormat.format(date); + } } diff --git a/src/test/java/com/github/archarithms/test/DateStringTests.java b/src/test/java/com/github/archarithms/test/DateStringTests.java index 04e9943..e84afba 100644 --- a/src/test/java/com/github/archarithms/test/DateStringTests.java +++ b/src/test/java/com/github/archarithms/test/DateStringTests.java @@ -1,36 +1,44 @@ package com.github.archarithms.test; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - +import com.github.archarithms.App; import org.junit.jupiter.api.Test; -import com.github.archarithms.App; +import static org.junit.jupiter.api.Assertions.*; /** * DateStringTests unit tests for simple App. */ public class DateStringTests { - - /* - * UNCOMMENT THE UNIT TESTS TO RUN THEM. FEEL FREE TO ADD MORE! - */ - /** * Test the testConvertUnixToDateString method */ @Test - public void testConvertUnixToDateString() { + public void testConvertUnixToDateString_Nominal() + { String testStr = "July 4, 2017"; - assertTrue(testStr.equals(App.convertUnixToDateString(1499144400L))); + assertEquals(testStr, App.convertUnixToDateString(1499144400L, "GMT-5")); + } + + /** + * Test the testConvertUnixToDateString method for mismatched time zone + */ + @Test + public void testConvertUnixToDateString_TimeZoneMismatch() + { + String pstTimeStr = "July 3, 2017"; + String estTimeStr = "July 4, 2017"; + String convertedStr = App.convertUnixToDateString(1499144400L, "GMT-8"); + assertEquals(pstTimeStr, convertedStr); + assertNotEquals(estTimeStr, convertedStr); } /** - * Test the testNullCase method + * Test the testConvertUnixToDateString method throws an exception for null cases */ @Test - public void testNullCase() { - assertThrows(Exception.class, () -> App.convertUnixToDateString(null)); + public void testConvertUnixToDateString_Null_ThrowsException() + { + assertThrows(Exception.class, () -> App.convertUnixToDateString(null, "GMT-5")); } } From f39a7180c9cd13fd6a54afffb39645f7ab43cb91 Mon Sep 17 00:00:00 2001 From: Chris Eastridge Date: Wed, 20 Jul 2022 17:32:34 -0500 Subject: [PATCH 3/3] Added some test cases to TitleCaseTests and ran feature verification. --- .../archarithms/test/TitleCaseTests.java | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/github/archarithms/test/TitleCaseTests.java b/src/test/java/com/github/archarithms/test/TitleCaseTests.java index f6aeb13..2a4d236 100644 --- a/src/test/java/com/github/archarithms/test/TitleCaseTests.java +++ b/src/test/java/com/github/archarithms/test/TitleCaseTests.java @@ -1,8 +1,7 @@ package com.github.archarithms.test; -import org.junit.jupiter.api.Test; - import com.github.archarithms.App; +import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -11,16 +10,12 @@ */ public class TitleCaseTests { - - /* - * UNCOMMENT THE UNIT TESTS TO RUN THEM. FEEL FREE TO ADD MORE! - */ - /** * Test the testConvertToTitleCase method */ @Test - public void testConvertToTitleCase_Nominal() { + public void testConvertToTitleCase_Nominal() + { String testStr = "Title Case"; assertEquals("TITLE CASE", App.convertToTitleCase(testStr)); } @@ -29,7 +24,8 @@ public void testConvertToTitleCase_Nominal() { * Test that upper-casing works with number literals */ @Test - public void testConvertToTitleCase_Numbers() { + public void testConvertToTitleCase_Numbers() + { String testStr = "Number 3"; assertEquals("NUMBER 3", App.convertToTitleCase(testStr)); @@ -39,7 +35,8 @@ public void testConvertToTitleCase_Numbers() { * Test that upper-casing works with different characters */ @Test - public void testConvertToTitleCase_OtherChars() { + public void testConvertToTitleCase_OtherChars() + { String testStr = "Truth-Track"; assertEquals("TRUTH-TRACK", App.convertToTitleCase(testStr)); @@ -57,4 +54,24 @@ public void testConvertToTitleCase_WhiteSpace() // Verify equals isn't trimming or eliminating whitespace assertNotEquals("TEST", App.convertToTitleCase(testStr)); } + + /** + * Test that upper-casing works with empty String. + */ + @Test + public void testConvertToTitleCase_Empty() + { + String testStr = ""; + assertEquals("", App.convertToTitleCase(testStr)); + } + + /** + * Test that an exception is thrown for null values. + */ + @Test + public void testConvertToTitleCase_Null_ThrowsException() + { + String testStr = ""; + assertThrows(Exception.class, () -> App.convertToTitleCase(null)); + } }