Skip to content

Commit d6b1a6c

Browse files
committedJul 21, 2018
Add property based tests on rabinKarp
1 parent 16c4b88 commit d6b1a6c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
 

‎src/algorithms/string/rabin-karp/__test__/rabinKarp.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as fc from 'fast-check';
2+
13
import { rabinKarp, hashWord, reHashWord } from '../rabinKarp';
24

35
describe('rabinKarp', () => {
@@ -18,4 +20,20 @@ describe('rabinKarp', () => {
1820
expect(rabinKarp('abcxabcdabxaabcdabcabcdabcdabcy', 'abcdabca')).toBe(12);
1921
expect(rabinKarp('abcxabcdabxaabaabaaaabcdabcdabcy', 'aabaabaaa')).toBe(11);
2022
});
23+
24+
it('should find a valid word position [property]', () => {
25+
fc.assert(fc.property(fc.fullUnicodeString(), fc.fullUnicodeString(), (s1, s2) => {
26+
const position = rabinKarp(s1, s2);
27+
return position === -1 || s1.slice(position, position + s2.length) === s2;
28+
}));
29+
});
30+
31+
it('should find a match [property]', () => {
32+
fc.assert(
33+
fc.property(
34+
fc.fullUnicodeString(), fc.fullUnicodeString(), fc.fullUnicodeString(),
35+
(a, b, c) => rabinKarp(a + b + c, b) !== -1
36+
)
37+
);
38+
});
2139
});

1 commit comments

Comments
 (1)

dubzzz commented on Jul 21, 2018

@dubzzz
OwnerAuthor

Issue opened in the official repository regarding the flakiness of should find a match [property]
See trekhleb#102

Please sign in to comment.