This repository has been archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
First skeleton of the additional coding task #8
Open
mgborowiec
wants to merge
3
commits into
master
Choose a base branch
from
codingExtension
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
gCoffee/app/src/main/java/com/mborowiec/gcoffee/OrderMatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.mborowiec.gcoffee; | ||
|
||
public interface OrderMatch { | ||
|
||
public boolean menuContainsItem(String item, String[] menu); | ||
|
||
public String findMatch(String order, String[] menu); | ||
} |
33 changes: 33 additions & 0 deletions
33
gCoffee/app/src/main/java/com/mborowiec/gcoffee/StringUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.mborowiec.gcoffee; | ||
|
||
import org.apache.commons.text.similarity.LevenshteinDistance; | ||
|
||
public class StringUtil { | ||
|
||
/** | ||
* Normalizes the string by removing punctuation, removing whitespaces | ||
* and making the string lowercase. | ||
* @param input input string | ||
* @return a normalized string | ||
*/ | ||
public String normalize(String input) { | ||
String normalized = input.replaceAll("[^a-zA-Z ]" , "") | ||
.replaceAll("\\s+", "") | ||
.toLowerCase(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some strings to test/consider: |
||
|
||
return normalized; | ||
} | ||
|
||
/** | ||
* Calculates the Levenshtein distance between two strings | ||
* @param str1 first input string | ||
* @param str2 second input string | ||
* @return distance between strings | ||
*/ | ||
public Integer calculateLevenshteinDistance(String str1, String str2) { | ||
LevenshteinDistance levenshteinDistance = new LevenshteinDistance(); | ||
int distance = levenshteinDistance.apply(str1, str2); | ||
|
||
return distance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,4 +44,64 @@ public void testCheckMenuNull() { | |
boolean test = testClass.menuContainsItem(null, coffeeList); | ||
assertFalse(test); | ||
} | ||
|
||
@Test | ||
public void testFindMatchExactMatch() { | ||
String testString = testClass.findMatch("latte", coffeeList); | ||
assertEquals("latte", testString); | ||
} | ||
|
||
@Test | ||
public void testFindMatchSimpleTypo() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about giving more descriptive test names?.. e.g. "whitespaceMissing", "middleLetterMissing", "lastLetterMissing" etc. From my experience, it is helpful in case when some tests start failing :) |
||
String testString = testClass.findMatch("flatwhite", coffeeList); | ||
assertEquals("Flat White", testString); | ||
} | ||
|
||
@Test | ||
public void testFindMatchSimpleTypo1() { | ||
String testString = testClass.findMatch("capuccino", coffeeList); | ||
assertEquals("Cappuccino", testString); | ||
} | ||
|
||
@Test | ||
public void testFindMatchSimpleTypo2() { | ||
String testString = testClass.findMatch("american", coffeeList); | ||
assertEquals("Americano", testString); | ||
} | ||
|
||
@Test | ||
public void testFindMatchSimpleTypo3() { | ||
String testString = testClass.findMatch("fatwhite", coffeeList); | ||
assertEquals("Flat White", testString); | ||
} | ||
|
||
@Test | ||
public void testFindMatchSimpleTypo4() { | ||
String testString = testClass.findMatch("mcha", coffeeList); | ||
assertEquals("Mocha", testString); | ||
} | ||
|
||
@Test | ||
public void testFindMatchNull() { | ||
String testString = testClass.findMatch(null, coffeeList); | ||
assertEquals(null, testString); | ||
} | ||
|
||
@Test | ||
public void testFindMatchEmptyString() { | ||
String testString = testClass.findMatch("", coffeeList); | ||
assertEquals(null, testString); | ||
} | ||
|
||
@Test | ||
public void testFindMatchWhitespace() { | ||
String testString = testClass.findMatch(" ", coffeeList); | ||
assertEquals(null, testString); | ||
} | ||
//The case not handled yet - returns latte | ||
@Test | ||
public void testFindMatchNotOnMenu() { | ||
String testString = testClass.findMatch("black tea", coffeeList); | ||
assertEquals(null, testString); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When happens if you pass an empty array as your menu?