Skip to content
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

test: todo Boyer-Moore algorithm matches KMP results #389

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,25 @@ private String generateRandomString(int upperLimitAscii, int length) {
.toString();
}

// TODO(william): Add a test that compares this implementation of Boyermoore
// with that of KMP.
@Test
public void shouldReturnSameResultAsKMP(){
int runLength = random.nextInt(MAX_ITERATION) + 1;
KMP kmp = new KMP();
for(int run = 0; run < runLength; run++){
int upperCharText = random.nextInt(3);
int upperCharPattern = random.nextInt(3);
int maxLengthText = random.nextInt(1000) + 100;

// ensure maxLengthPattern is at least 1
int maxLengthPattern = random.nextInt(10) + 1;

String text = generateRandomString(upperCharText, maxLengthText);
String pattern = generateRandomString(upperCharPattern, maxLengthPattern);

List<Integer> boyerMooreResult = underTest.findOccurrences(text, pattern);
List<Integer> kmpResult = KMP.kmp(text, pattern);

assertThat(boyerMooreResult).containsExactlyElementsIn(kmpResult);
}
}
}