-
Notifications
You must be signed in to change notification settings - Fork 17
Added tests and bug fix #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| package edu.mills.cs180a; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.CsvSource; | ||
|
|
||
| class StringUtilitiesTester { | ||
| @Test | ||
|
|
@@ -13,13 +16,86 @@ void isSubstring_False_null() { | |
| } | ||
|
|
||
| @Test | ||
| void isSubstring_False_EmptyString() { | ||
| void isSubstring_True_EmptyString() { | ||
| assertTrue(StringUtilities.isSubstring("", "foo")); | ||
| // TODO: write rest | ||
| } | ||
|
|
||
| @Test | ||
| void isSubstring_True_Length1Substring() { | ||
| assertTrue(StringUtilities.isSubstring("A", "ABC")); | ||
| } | ||
|
|
||
| @Test | ||
| void isSubstring_True_Length2Substring() { | ||
| assertTrue(StringUtilities.isSubstring("C D", "ABC DEF")); | ||
|
Owner
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. This looks like a length-3 substring. |
||
| } | ||
|
|
||
| @Test | ||
| void isSubstring_True_Length3Substring() { | ||
| assertTrue(StringUtilities.isSubstring("GHI", "ABC DEF GHI")); | ||
| } | ||
|
|
||
| @Test | ||
| void isSubstring_False_Length1Substring() { | ||
| assertFalse(StringUtilities.isSubstring("D", "ABC")); | ||
| } | ||
|
|
||
| @Test | ||
| void isSubstring_False_Length2Substring() { | ||
| assertFalse(StringUtilities.isSubstring("C F", "ABC DEF")); | ||
| } | ||
|
|
||
| @Test | ||
| void isSubstring_False_Length3Substring() { | ||
|
Owner
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. This looks like a length-3 substring. |
||
| assertFalse(StringUtilities.isSubstring("XYZ ABC", "ABC DEF GHI")); | ||
| } | ||
|
|
||
| @Test | ||
| void isSubstring_True_SubstringAtStart() { | ||
| assertTrue(StringUtilities.isSubstring("ABC", "ABC DEF GHI")); | ||
| } | ||
|
|
||
| @Test | ||
| void isSubstring_True_SubstringInMiddle() { | ||
| assertTrue(StringUtilities.isSubstring("DEF", "ABC DEF GHI")); | ||
| } | ||
|
|
||
| @Test | ||
| void isSubstring_True_SubstringAtEnd() { | ||
| assertTrue(StringUtilities.isSubstring("GHI", "ABC DEF GHI")); | ||
| } | ||
|
|
||
| @Test | ||
| void isSubstring_False_SubstringAtStart() { | ||
| assertFalse(StringUtilities.isSubstring("ADF", "ABC DEF GHI")); | ||
| } | ||
|
|
||
| @Test | ||
| void isSubstring_False_SubstringInMiddle() { | ||
| assertFalse(StringUtilities.isSubstring("C DEG", "ABC DEF GHI")); | ||
| } | ||
|
|
||
| @Test | ||
| void isSubstring_False_SubstringAtEnd() { | ||
| assertFalse(StringUtilities.isSubstring("Ijk", "GHI")); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @CsvSource({"The cart, tottenham", "Tra lalalalala,apple pie", "Mo Ghile Mear,run away"}) | ||
|
Owner
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. 😃 |
||
| void isSubstring_Fail_FirstLetterOfSubstringLastLetterOfString(String input, String subInput) { | ||
| assertFalse(StringUtilities.isSubstring(subInput, input)); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @CsvSource({"The cat is in the hat,cat is in", "Tra lalalalala,Tra", "Mo Ghile Mear,Ghile"}) | ||
| void isSubstring_True_VariedStringsAndSubstrings(String input, String subInput) { | ||
| assertTrue(StringUtilities.isSubstring(subInput, input)); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @CsvSource({"The cat is in the hat,hotpot", "Tra lalalalala,homeward is", | ||
| "Mo Ghile Mear,run away"}) | ||
| void isSubstring_False_VariedStringsAndSubstrings(String input, String subInput) { | ||
| assertFalse(StringUtilities.isSubstring(subInput, 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.
Good.