Skip to content

Commit

Permalink
Resolve #46: Updated README with min and max lengths of generated phr…
Browse files Browse the repository at this point in the history
…ases
  • Loading branch information
AlexanderYastrebov committed Jun 29, 2016
1 parent 83f05fd commit c5d8357
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ There is also `PhraseGenerator` provided which generates over 10^9 different phr
nostalgic_boyd_helps_agitated_noyce
pensive_allen_tells_fervent_einstein

The generated phrase is 22 to 61 characters long.

### Listeners

For some use cases, e.g. integration with other frameworks and libraries, it might be useful to register a listener that gets notified every time a trace is either started or stopped.
Expand Down
14 changes: 14 additions & 0 deletions tracer-core/src/main/java/org/zalando/tracer/PhraseGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,20 @@ static long maxCombinations() {
.reduce(1, (a, b) -> a * b);
}

@VisibleForTesting
static int minLength() {
return Stream.of(PARTS)
.mapToInt(dict -> Stream.of(dict).mapToInt(String::length).min().getAsInt())
.sum() + (PARTS.length - 1);
}

@VisibleForTesting
static int maxLength() {
return Stream.of(PARTS)
.mapToInt(dict -> Stream.of(dict).mapToInt(String::length).max().getAsInt())
.sum() + (PARTS.length - 1);
}

@VisibleForTesting
static boolean isJacocoHappy() {
final Holder h = new Holder();
Expand Down
10 changes: 10 additions & 0 deletions tracer-core/src/test/java/org/zalando/tracer/GeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,14 @@ public void testPhraseWozniakIsNotBoring() throws Exception {
public void testPhraseOver_1_000_000_000() throws Exception {
assertTrue(PhraseGenerator.maxCombinations() > 1_000_000_000);
}

@Test
public void testPhraseMinLength() throws Exception {
assertThat(PhraseGenerator.minLength(), is(22));
}

@Test
public void testPhraseMaxLength() throws Exception {
assertThat(PhraseGenerator.maxLength(), is(61));
}
}

0 comments on commit c5d8357

Please sign in to comment.