-
Notifications
You must be signed in to change notification settings - Fork 20k
Create a new Rabin-Karp Algorithm #3201
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cfdb8c5
Create a new Rabin-Karp Algorithm
tackhwa e6769c9
Update and rename RabinKarpSearch to RabinKarpAlgorithm.java
tackhwa 18fbb0d
JUnit test for Rabin Karp Algorithm
tackhwa d57b635
Update RabinKarpAlgorithmTest
tackhwa 303d3bb
Update and rename RabinKarpAlgorithmTest to RabinKarpAlgorithmTest.java
tackhwa 1451d81
Merge branch 'master' into patch-1
tackhwa 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
JUnit test for Rabin Karp Algorithm
Add a j-unit test for Rabin Karp Algorithm
- Loading branch information
commit 18fbb0dc3d1301b94a883bf8d62ea2dafede34ee
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
src/test/java/com/thealgorithms/searches/RabinKarpAlgorithmTest
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,85 @@ | ||
package com.thealgorithms.searches; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
|
||
|
||
|
||
class RabinKarpAlgorithmTest { | ||
|
||
|
||
RabinKarpAlgorithm RKA= new RabinKarpAlgorithm(); | ||
int q= 101; | ||
|
||
|
||
|
||
|
||
@Test | ||
// valid test case | ||
public void RabinKarpAlgorithmTestExample() { | ||
String txt = "This is an example for rabin karp algorithmn"; | ||
String pat = "algorithmn"; | ||
int value = RKA.search(pat, txt, q); | ||
System.out.println(value); | ||
assertEquals(value,34); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
tackhwa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Test | ||
// valid test case | ||
public void RabinKarpAlgorithmTestFront() { | ||
String txt = "AAABBDDG"; | ||
String pat = "AAA"; | ||
int value = RKA.search(pat, txt, q); | ||
System.out.println(value); | ||
assertEquals(value, 0); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
@Test | ||
// valid test case | ||
public void RabinKarpAlgorithmTestMiddle() { | ||
String txt = "AAABBCCBB"; | ||
String pat = "BBCC"; | ||
int value = RKA.search(pat, txt, q); | ||
System.out.println(value); | ||
assertEquals(value, 3); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
@Test | ||
// valid test case | ||
public void RabinKarpAlgorithmTestLast() { | ||
String txt = "AAAABBBBCCC"; | ||
String pat = "CCC"; | ||
int value = RKA.search(pat, txt, q); | ||
System.out.println(value); | ||
assertEquals(value, 8); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
@Test | ||
// valid test case | ||
public void RabinKarpAlgorithmTestNotFound() { | ||
String txt = "ABCBCBCAAB"; | ||
String pat = "AADB"; | ||
int value = RKA.search(pat, txt, q); | ||
System.out.println(value); | ||
assertEquals(value, -1); | ||
|
||
} | ||
|
||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.