Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork312
Added jUnit test and fixed 2 bugs#47
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
gugugiyu wants to merge1 commit intorampatra:masterChoose a base branch fromgugugiyu:master
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.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
16 changes: 12 additions & 4 deletionssrc/main/java/com/rampatra/strings/IntegerToString.java
This file contains hidden or 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
13 changes: 11 additions & 2 deletionssrc/main/java/com/rampatra/strings/StringToInteger.java
This file contains hidden or 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
4 changes: 4 additions & 0 deletionssrc/main/java/com/rampatra/strings/SubStringCheck.java
This file contains hidden or 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
60 changes: 60 additions & 0 deletionssrc/main/java/com/rampatra/strings/TestIntegerToString.java
This file contains hidden or 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,60 @@ | ||
package com.rampatra.strings; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import org.junit.jupiter.api.Test; | ||
public class TestIntegerToString { | ||
@Test | ||
static void integerCases(){ | ||
//Positive, small number, expected: true | ||
int a1 = 123; | ||
String a2 = "123"; | ||
//Negative, small number, expected: true | ||
int b1 = -123; | ||
String b2 = "-123"; | ||
//0, expected: true | ||
int c1 = 0; | ||
String c2 = "0"; | ||
boolean resultA = a2.equals(IntegerToString.getStringFromInteger(a1)); | ||
boolean resultB = b2.equals(IntegerToString.getStringFromInteger(b1)); | ||
boolean resultC = c2.equals(IntegerToString.getStringFromInteger(c1)); | ||
assertTrue(resultA); | ||
assertTrue(resultB); | ||
assertTrue(resultB); | ||
} | ||
@Test | ||
static void boundaryCases() { | ||
//INT_MAX | ||
int a1 = Integer.MAX_VALUE; | ||
String a2 = "2147483647"; | ||
//INT_MIN | ||
int b1 = Integer.MIN_VALUE; | ||
String b2 = "-2147483648"; | ||
//Trailing zero | ||
int c1 = 000000000000; | ||
String c2 = "0"; | ||
boolean resultA = a2.equals(IntegerToString.getStringFromInteger(a1)); | ||
boolean resultB = b2.equals(IntegerToString.getStringFromInteger(b1)); | ||
boolean resultC = c2.equals(IntegerToString.getStringFromInteger(c1)); | ||
assertTrue(resultA); | ||
assertTrue(resultB); | ||
assertTrue(resultC); | ||
} | ||
public static void main(String args[]){ | ||
integerCases(); | ||
boundaryCases(); | ||
} | ||
} |
104 changes: 104 additions & 0 deletionssrc/main/java/com/rampatra/strings/TestStringToInteger.java
This file contains hidden or 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,104 @@ | ||
package com.rampatra.strings; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import org.junit.jupiter.api.Test; | ||
public class TestStringToInteger { | ||
//It assumes the {@code string} contains ASCII characters only. | ||
@Test | ||
public static void AllTestCases() { | ||
//Empty cases | ||
String test1 = ""; | ||
int retVal = -1; | ||
//In this case, we're expected to be thrown the numberFormatException | ||
try { | ||
retVal = StringToInteger.getIntegerFromString(test1); | ||
}catch (NumberFormatException e) { | ||
System.out.println("Exception case for \" Empty cases \" executed successfully."); | ||
}finally { | ||
System.out.println("End exception case. Return value: " + retVal); | ||
} | ||
//Positive number | ||
String test2 = "2147483647"; | ||
retVal = Integer.MAX_VALUE; | ||
assertEquals(StringToInteger.getIntegerFromString(test2), retVal); | ||
//Negative number | ||
String test3 = "-2147483648"; | ||
retVal = Integer.MIN_VALUE; | ||
assertEquals(retVal, StringToInteger.getIntegerFromString(test3)); | ||
//Zero leading | ||
String test4 = "00000000000000000000000123123123"; | ||
retVal = 123123123; | ||
assertEquals(StringToInteger.getIntegerFromString(test4), retVal); | ||
//Zero leading and minus sign | ||
String test5 = "00000-213"; | ||
retVal = 0; | ||
//In this case, we're expected to be thrown the numberFormatException | ||
try { | ||
retVal = StringToInteger.getIntegerFromString(test5); | ||
}catch (NumberFormatException e) { | ||
System.out.println("Exception case for \" Zero leading and minus sign \" executed successfully."); | ||
}finally { | ||
System.out.println("End exception case. Return value: " + retVal); | ||
} | ||
//Ascii string | ||
String test6 = "QWERTYUIOPASDFGHJKLZXCVBNM 1234567890 qwertyuiopasdfghjklzxcvbnm -=+!@#$%^&*() >:{ }|\\\\]"; | ||
//In this case, we're expected to be thrown the numberFormatException | ||
try { | ||
retVal = StringToInteger.getIntegerFromString(test6); | ||
}catch (NumberFormatException e) { | ||
System.out.println("Exception case for \" Ascii string \" executed successfully."); | ||
}finally { | ||
System.out.println("End exception case. Return value: " + retVal); | ||
} | ||
//Trailing ASCII character, positive value | ||
String test7 = "123AAABBB"; | ||
retVal = 123; | ||
//In this case, we're expected to be thrown the numberFormatException | ||
try { | ||
retVal = StringToInteger.getIntegerFromString(test7); | ||
}catch (NumberFormatException e) { | ||
System.out.println("Exception case for \" Trailing ASCII character, positive value \" executed successfully."); | ||
}finally { | ||
System.out.println("End exception case. Return value: " + retVal); | ||
} | ||
//Trailing ASCII character, negative value | ||
String test8 = "-123AAABBB"; | ||
retVal = 123; | ||
//In this case, we're expected to be thrown the numberFormatException | ||
try { | ||
retVal = StringToInteger.getIntegerFromString(test8); | ||
}catch (NumberFormatException e) { | ||
System.out.println("Exception case for \" Trailing ASCII character, negative value \" executed successfully."); | ||
}finally { | ||
System.out.println("End exception case. Return value: " + retVal); | ||
} | ||
} | ||
public static void main(String[] args) { | ||
AllTestCases(); | ||
} | ||
} |
126 changes: 126 additions & 0 deletionssrc/main/java/com/rampatra/strings/TestSubStringCheck.java
This file contains hidden or 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,126 @@ | ||
package com.rampatra.strings; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import org.junit.jupiter.api.Test; | ||
public class TestSubStringCheck { | ||
static String assumedFilledString = "QWERTYUIOPASDFGHJKLZXCVBNM 1234567890 qwertyuiopasdfghjklzxcvbnm -=+!@#$%^&*() >:{ }|\\]"; | ||
static String assumedFilledSubString = "QWERTYUIOPASDFGHJKLZXCVBNM"; | ||
static String emptyString = ""; | ||
static String nullString = null; | ||
static String nonASCIIString = "Ă Â Ô Ơ Ư Ê ⏩ ☕ ☝ ♈ ぁ あ ぃ い ぅ う ぇ え ぉ お ç ù"; | ||
static String nonASCIISubString = "ぁ あ ぃ い ぅ う ぇ え ぉ お ç ù"; | ||
static String spaceString = " "; | ||
@Test | ||
static void happyCases() { | ||
//First slot is main string | ||
boolean resultA = SubStringCheck.isSubString(assumedFilledString, assumedFilledSubString); | ||
//Second slot is main string | ||
boolean resultB = SubStringCheck.isSubString(assumedFilledSubString, assumedFilledString); | ||
//Both slot is the same | ||
boolean resultC = SubStringCheck.isSubString(assumedFilledSubString, assumedFilledSubString); | ||
//Assertion | ||
assertTrue(resultA); | ||
assertFalse(resultB); | ||
assertTrue(resultC); | ||
} | ||
@Test | ||
static void emptyCases() { | ||
//First slot is empty | ||
boolean resultA = SubStringCheck.isSubString(emptyString, assumedFilledString); | ||
//Second slot is empty | ||
boolean resultB = SubStringCheck.isSubString(assumedFilledString, emptyString); | ||
//Both slot is empty | ||
boolean resultC = SubStringCheck.isSubString(emptyString, emptyString); | ||
//Assertion | ||
assertFalse(resultA); | ||
assertTrue(resultB); | ||
assertTrue(resultC); | ||
} | ||
@Test | ||
static void nullCases() { | ||
//First slot is null | ||
boolean resultA = SubStringCheck.isSubString(nullString, assumedFilledString); | ||
//Second slot is null | ||
boolean resultB = SubStringCheck.isSubString(assumedFilledString, nullString); | ||
//Both slot is null | ||
boolean resultC = SubStringCheck.isSubString(nullString, nullString); | ||
//First slot is null and second slot is empty | ||
boolean resultD = SubStringCheck.isSubString(nullString, emptyString); | ||
//First slot is empty and second slot is null | ||
boolean resultE = SubStringCheck.isSubString(emptyString, nullString); | ||
//Assertion | ||
assertFalse(resultA); | ||
assertFalse(resultB); | ||
assertFalse(resultC); | ||
assertFalse(resultD); | ||
assertFalse(resultE); | ||
} | ||
@Test | ||
static void spaceCases() { | ||
//First slot is full of spaces | ||
boolean resultA = SubStringCheck.isSubString(spaceString, assumedFilledString); | ||
//Second slot is full of spaces | ||
boolean resultB = SubStringCheck.isSubString(assumedFilledString, spaceString); | ||
//Both slot is full of spaces | ||
boolean resultC = SubStringCheck.isSubString(spaceString, spaceString); | ||
//Assertion | ||
assertFalse(resultA); | ||
assertFalse(resultB); | ||
assertTrue(resultC); | ||
} | ||
@Test | ||
static void nonASCIICases() { | ||
//Good case | ||
boolean resultA = SubStringCheck.isSubString(nonASCIIString, nonASCIISubString); | ||
//Second slot is empty | ||
boolean resultB = SubStringCheck.isSubString(nonASCIIString, emptyString); | ||
//Second slot is null | ||
boolean resultC = SubStringCheck.isSubString(nonASCIIString, nullString); | ||
//Assertion | ||
assertTrue(resultA); | ||
assertTrue(resultB); | ||
assertFalse(resultC); | ||
} | ||
public static void main(String[] args) { | ||
happyCases(); | ||
emptyCases(); | ||
nullCases(); | ||
spaceCases(); | ||
nonASCIICases(); | ||
} | ||
} |
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.