Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork312
Add JUnit test to some Algorithms#23
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
TUGVince wants to merge1 commit intorampatra:masterChoose a base branch fromTUGVince: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
17 changes: 17 additions & 0 deletions.project
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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>Algorithms-and-Data-Structures-in-Java</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
2 changes: 2 additions & 0 deletions.settings/org.eclipse.core.resources.prefs
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,2 @@ | ||
eclipse.preferences.version=1 | ||
encoding/<project>=UTF-8 |
33 changes: 33 additions & 0 deletionssrc/main/java/com/hackerrank/algorithms/arraysandsorting/InsertionSort2Test.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,33 @@ | ||
package InsertionSort; | ||
import static org.junit.Assert.assertArrayEquals; | ||
import org.junit.Test; | ||
public class InsertionSort2Test { | ||
@Test | ||
public void shouldDoNothingWithEmptyArray() { | ||
int[] values = {}; | ||
InsertionSort2.insertionSortPart2(values); | ||
} | ||
@Test | ||
public void shouldDoNothingWithOneElementArray() { | ||
int[] values = {16}; | ||
InsertionSort2.insertionSortPart2(values); | ||
assertArrayEquals(new int[] {16}, values); | ||
} | ||
@Test | ||
public void shouldSortValues() { | ||
int[] values = { 11, -4, 3, 0, 1}; | ||
int[] expectedOrder = { -4, 0, 1, 3, 11}; | ||
InsertionSort2.insertionSortPart2(values); | ||
assertArrayEquals(expectedOrder, values); | ||
} | ||
} |
81 changes: 81 additions & 0 deletionssrc/main/java/com/hackerrank/algorithms/strings/PalindromeIndexTest.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,81 @@ | ||
package palimdromeIndex; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
public class PalindromeIndexTest { | ||
private String input; | ||
@Before | ||
public void setUp() throws Exception { | ||
input = null; | ||
} | ||
@After | ||
public void tearDown() throws Exception { | ||
} | ||
@Test(expected = NullPointerException.class) | ||
public void nullStringTest() throws Exception { | ||
PalindromeIndex.isPalindrome(null); | ||
} | ||
@Test | ||
public void emptyStringTest() throws Exception { | ||
input = ""; | ||
assertTrue(PalindromeIndex.isPalindrome(input)); | ||
} | ||
@Test | ||
public void singleCharTest() throws Exception { | ||
input = "H"; | ||
assertTrue(PalindromeIndex.isPalindrome(input)); | ||
} | ||
@Test | ||
public void alphaNumericPalindromeTest() throws Exception { | ||
input = "1234321"; | ||
assertTrue(PalindromeIndex.isPalindrome(input)); | ||
} | ||
@Test | ||
public void validPalindromeTest() throws Exception { | ||
input = "madam"; | ||
assertTrue(PalindromeIndex.isPalindrome(input)); | ||
} | ||
@Test | ||
public void invalidWordPalindromeTest() throws Exception { | ||
input = "rotators"; | ||
assertFalse(PalindromeIndex.isPalindrome(input)); | ||
} | ||
@Test | ||
public void invalidPalindromeTest() throws Exception { | ||
input = "I am a tester"; | ||
assertFalse(PalindromeIndex.isPalindrome(input)); | ||
} | ||
} |
42 changes: 42 additions & 0 deletionssrc/main/java/com/hackerrank/algorithms/strings/SentencePalindrome.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,42 @@ | ||
package sentencePalindrome; | ||
public class SentencePalindrome { | ||
static boolean isPalindrome(String str) { | ||
int l = 0; | ||
int h = str.length() - 1; | ||
// Lowercase string | ||
str = str.toLowerCase(); | ||
// Compares character until they are equal | ||
while (l <= h) { | ||
char getAtl = str.charAt(l); | ||
char getAth = str.charAt(h); | ||
// If there is another symbol in left | ||
// of sentence | ||
if (!(getAtl >= 'a' && getAtl <= 'z')) | ||
l++; | ||
// If there is another symbol in right | ||
// of sentence | ||
else if (!(getAth >= 'a' && getAth <= 'z')) | ||
h--; | ||
// If characters are equal | ||
else if (getAtl == getAth) { | ||
l++; | ||
h--; | ||
} | ||
else | ||
return false; | ||
} | ||
return true; | ||
} | ||
public static void main(String[] args) { | ||
} | ||
} |
99 changes: 99 additions & 0 deletionssrc/main/java/com/hackerrank/algorithms/strings/SentencePalindromeTest.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,99 @@ | ||
package sentencePalindrome; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
public class SentencePalindromeTest { | ||
private String input; | ||
@Before | ||
public void setUp() throws Exception { | ||
input = null; | ||
} | ||
@After | ||
public void tearDown() throws Exception { | ||
} | ||
@Test(expected = NullPointerException.class) | ||
public void nullStringTest() throws Exception { | ||
SentencePalindrome.isPalindrome(null); | ||
} | ||
@Test | ||
public void emptyStringTest() throws Exception { | ||
input = ""; | ||
assertTrue(SentencePalindrome.isPalindrome(input)); | ||
} | ||
@Test | ||
public void multipleWhiteSpaceTest() throws Exception { | ||
input = "A Santa at Nasa"; | ||
assertTrue(SentencePalindrome.isPalindrome(input)); | ||
} | ||
@Test | ||
public void singleCharTest() throws Exception { | ||
input = "H"; | ||
assertTrue(SentencePalindrome.isPalindrome(input)); | ||
} | ||
@Test | ||
public void punctuationTest() throws Exception { | ||
input = "Eva, can I see bees in a cave?"; | ||
assertTrue(SentencePalindrome.isPalindrome(input)); | ||
} | ||
@Test | ||
public void unicodeTest() throws Exception { | ||
input = "Step on no pet."; | ||
assertFalse(SentencePalindrome.isPalindrome(input)); | ||
} | ||
@Test | ||
public void alphaNumericPalindromeTest() throws Exception { | ||
input = "Air 2 an a2ria"; | ||
assertTrue(SentencePalindrome.isPalindrome(input)); | ||
} | ||
@Test | ||
public void validPalindromeTest() throws Exception { | ||
input = "No lemon no melon"; | ||
assertTrue(SentencePalindrome.isPalindrome(input)); | ||
} | ||
@Test | ||
public void invalidPalindromeTest() throws Exception { | ||
input = "I am a tester"; | ||
assertFalse(SentencePalindrome.isPalindrome(input)); | ||
} | ||
} |
72 changes: 36 additions & 36 deletionssrc/main/java/com/rampatra/sorting/BubbleSort.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
32 changes: 32 additions & 0 deletionssrc/main/java/com/rampatra/sorting/BubbleSortTest.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,32 @@ | ||
package BubbleSort; | ||
import static org.junit.Assert.assertArrayEquals; | ||
import org.junit.Test; | ||
public class BubbleSortTest { | ||
@Test | ||
public void shouldDoNothingWithEmptyArray() { | ||
int[] values = {}; | ||
BubbleSort.bubbleSort(values); | ||
} | ||
@Test | ||
public void shouldDoNothingWithOneElementArray() { | ||
int[] values = {16}; | ||
BubbleSort.bubbleSort(values); | ||
assertArrayEquals(new int[] {16}, values); | ||
} | ||
@Test | ||
public void shouldSortValues() { | ||
int[] values = { 11, -4, 3, 0, 1}; | ||
int[] expectedOrder = { -4, 0, 1, 3, 11}; | ||
BubbleSort.bubbleSort(values); | ||
assertArrayEquals(expectedOrder, values); | ||
} | ||
} |
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.