Skip to content

Commit

Permalink
add unit test for min and max length
Browse files Browse the repository at this point in the history
  • Loading branch information
astik committed Sep 28, 2018
1 parent 3e8070c commit 9945af9
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions src/test/java/com/mifmif/common/regex/GenerexTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,28 @@ public class GenerexTest {

private String pattern;
private Generex generex;
private int expectedMatchedStringsSize;
private int expectedMatchedStringsSize;
private int expectedStringsMinLength;
private int expectedStringsMaxLength;

@Parameters(name = "Test get match: {0}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] { { "Sample multicharacter expression", "[A-B]{5,9}", 992 }, { "Sample expression", "[0-3]([a-c]|[e-g]{1,2})", 60 },
{ "Number format", "\\d{3,4}", 11000 },
// {"Any non-number","\\D{3,4}"},
{ "Any word", "\\w{1,2}", 4032 }, { "Empty string", "", 1 },
// {"Any non-word","\\W{1,2}"}
});
return Arrays.asList(new Object[][] { //
{"Sample multicharacter expression", "[A-B]{5,9}", 992, 5, 9}, //
{"Sample expression", "[0-3]([a-c]|[e-g]{1,2})", 60, 2, 3}, //
{"Number format", "\\d{3,4}", 11000, 3, 4}, //
// {"Any non-number","\\D{3,4}", ???, 3, 4}, //
{"Any word", "\\w{1,2}", 4032, 1, 2}, //
{"Empty string", "", 1, 0, 0}, //
// {"Any non-word","\\W{1,2}", ???, 1, 2} //
});
}

public GenerexTest(String description, String patternValue, int numberOfStrings) {
public GenerexTest(String description, String patternValue, int numberOfStrings, int minLength, int maxLength) {
this.pattern = patternValue;
this.expectedMatchedStringsSize = numberOfStrings;
this.expectedMatchedStringsSize = numberOfStrings;
this.expectedStringsMinLength = minLength;
this.expectedStringsMaxLength = maxLength;
}

@Before
Expand All @@ -54,6 +61,22 @@ public void testMatchedStringsSizeShouldReturnExpectedValues() {
expectedMatchedStringsSize == size);
}

@Test
public void testMinLengthMatchedStringsShouldReturnExpectedValues() {
long size = generex.generateMinLength();
Assert.assertTrue(
String.format("The minimum lengh matched strings '%s' doesn't match the value '%s'", size, expectedStringsMinLength),
expectedStringsMinLength == size);
}

@Test
public void testMaxLengthMatchedStringsShouldReturnExpectedValues() {
long size = generex.generateMaxLength();
Assert.assertTrue(
String.format("The maximum lengh matched strings '%s' doesn't match the value '%s'", size, expectedStringsMaxLength),
expectedStringsMaxLength == size);
}

@Test
public void testGetMatchedFirstMatchShouldBeTheSameAsMatchWithZeroIndex() {
String firstMatch = generex.getFirstMatch();
Expand Down

0 comments on commit 9945af9

Please sign in to comment.