Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.classpath
.project
.settings/
target/
nbproject/*
.settings
runtime/*
*~
.DS_Store
33 changes: 33 additions & 0 deletions bin/README.md
Original file line number Diff line number Diff line change
@@ -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.
26 changes: 26 additions & 0 deletions bin/codingChallenge.md
Original file line number Diff line number Diff line change
@@ -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).
56 changes: 56 additions & 0 deletions bin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.archarithms</groupId>
<artifactId>java-interview</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>

<name>java-interview</name>
<url>http://archarithms.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.version>3.8.1</maven.compiler.version>
<maven.surefire.version>2.22.1</maven.surefire.version>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
<junit.jupiter.version>5.4.2</junit.jupiter.version>
<joda.time.version>2.9.7</joda.time.version>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda.time.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
</plugin>
</plugins>
</build>
</project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
<artifactId>joda-time</artifactId>
<version>${joda.time.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>
</dependencies>

<build>
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/com/github/archarithms/App.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
93 changes: 93 additions & 0 deletions src/main/java/com/github/archarithms/DateObject.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
12 changes: 10 additions & 2 deletions src/test/java/com/github/archarithms/test/DateStringTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");
}
}

/**
Expand Down