Skip to content

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 6 commits into from
Aug 5, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
JUnit test for Rabin Karp Algorithm
Add a j-unit test for Rabin Karp Algorithm
  • Loading branch information
tackhwa authored Aug 3, 2022
commit 18fbb0dc3d1301b94a883bf8d62ea2dafede34ee
85 changes: 85 additions & 0 deletions src/test/java/com/thealgorithms/searches/RabinKarpAlgorithmTest
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);

}




@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);

}

}