-
Notifications
You must be signed in to change notification settings - Fork 0
First skeleton of the additional coding task #8
base: master
Are you sure you want to change the base?
Conversation
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.
Thanks a lot.
Two remarks (which can be addressed in a follow up pull request as well):
- Did you consider to move this logic into a separate class/file?
- What about adding some "still failing" tests early?
* @param input input string | ||
* @return a normalized string | ||
*/ | ||
public String normalize(String input) { |
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.
Comparing the code with the comment, it seems like there are some cornercases which would be handled unexpected, e.g., what about unicode characters?
* @param str2 second input string | ||
* @return distance between strings | ||
*/ | ||
public Integer distance(String str1, String str2) { |
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.
The comment is more precise than the method name. Consider keeping both in sync, e.g.,
calcLevenshteinDistance
} | ||
|
||
/** | ||
* Looks for the closest match (with closest distance) in the menu for an order with typos. |
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.
The comment let's me assume that it only works for orders with typos, but I assume that those without typos should work as well?
|
||
/** | ||
* Looks for the closest match (with closest distance) in the menu for an order with typos. | ||
* @param order an order with potential typos |
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.
nit: typo?
* @return the closest order match | ||
*/ | ||
public String findMatch(String order) { | ||
//TODO: asses which item on menu is closest |
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.
nit: typo
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.
Consider pulling out the string related functions into a utility class and add tests.
} | ||
|
||
@Test | ||
public void testFindMatchSimpleTypo() { |
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.
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 :)
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Some strings to test/consider:
"Latte "
"latté"
} | ||
// Return the menu item with smallest distance | ||
return menu[indexMin]; |
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?
No description provided.