• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ljacqu / wordeval / 14540577447

18 Apr 2025 07:23PM UTC coverage: 51.439% (-6.2%) from 57.611%
14540577447

push

github

ljacqu
Remove EvaluationResult type param from all Evaluator interfaces

239 of 546 branches covered (43.77%)

16 of 17 new or added lines in 16 files covered. (94.12%)

193 existing lines in 17 files now uncovered.

679 of 1320 relevant lines covered (51.44%)

3.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

48.15
/src/main/java/ch/jalu/wordeval/evaluators/impl/SameLetterConsecutive.java
1
package ch.jalu.wordeval.evaluators.impl;
2

3
import ch.jalu.wordeval.dictionary.Word;
4
import ch.jalu.wordeval.evaluators.WordEvaluator;
5
import ch.jalu.wordeval.evaluators.result.WordWithKey;
6
import com.google.common.collect.ArrayListMultimap;
7
import com.google.common.collect.ListMultimap;
8
import lombok.Getter;
9
import org.apache.commons.lang3.StringUtils;
10

11
import java.util.ArrayList;
12
import java.util.Comparator;
13
import java.util.HashSet;
14
import java.util.List;
15
import java.util.Set;
16

17
/**
18
 * Finds words wherein the same letter appears multiple times consecutively,
19
 * e.g. "lll" in German "Rollladen."
20
 */
21
public class SameLetterConsecutive implements WordEvaluator {
2✔
22

23
  @Getter
6✔
24
  private final List<WordWithKey> results = new ArrayList<>();
25

26
  @Override
27
  public void evaluate(Word wordObject) {
28
    String word = wordObject.getWithoutAccents();
3✔
29
    int counter = 0;
2✔
30
    char lastChar = '\0';
2✔
31
    for (int i = 0; i <= word.length(); ++i) {
8✔
32
      if (i < word.length() && word.charAt(i) == lastChar) {
9✔
33
        ++counter;
2✔
34
      } else {
35
        if (counter > 1) {
3✔
36
          results.add(new WordWithKey(wordObject, StringUtils.repeat(lastChar, counter)));
11✔
37
        }
38
        lastChar = i < word.length() ? word.charAt(i) : '\0';
10✔
39
        counter = 1;
2✔
40
      }
41
    }
42
  }
1✔
43

44
  @Override
45
  public ListMultimap<Object, Object> getTopResults(int topScores, int maxLimit) {
UNCOV
46
    List<WordWithKey> sortedResult = results.stream()
×
UNCOV
47
        .sorted(Comparator.<WordWithKey>comparingInt(wordWithKey -> wordWithKey.getKey().length()).reversed())
×
UNCOV
48
        .toList();
×
49

UNCOV
50
    Set<Integer> uniqueValues = new HashSet<>();
×
UNCOV
51
    ListMultimap<Object, Object> filteredResults = ArrayListMultimap.create();
×
UNCOV
52
    for (WordWithKey wordWithKey : sortedResult) {
×
UNCOV
53
      int score = wordWithKey.getKey().length();
×
UNCOV
54
      if (uniqueValues.add(score) && uniqueValues.size() > topScores) {
×
UNCOV
55
        break;
×
56
      }
UNCOV
57
      filteredResults.put(score, wordWithKey.getWord().getRaw() + " (" + wordWithKey.getKey() + ")");
×
UNCOV
58
      if (filteredResults.size() >= maxLimit) {
×
UNCOV
59
        break;
×
60
      }
UNCOV
61
    }
×
62

UNCOV
63
    return filteredResults;
×
64
  }
65
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc