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

ljacqu / wordeval / 14552398690

19 Apr 2025 07:59PM UTC coverage: 52.924% (+2.3%) from 50.591%
14552398690

push

github

ljacqu
Write sanitizer tests that don't require the dictionary file

268 of 576 branches covered (46.53%)

1 of 2 new or added lines in 1 file covered. (50.0%)

36 existing lines in 9 files now uncovered.

724 of 1368 relevant lines covered (52.92%)

3.06 hits per line

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

44.44
/src/main/java/ch/jalu/wordeval/evaluators/impl/Emordnilap.java
1
package ch.jalu.wordeval.evaluators.impl;
2

3
import ch.jalu.wordeval.dictionary.Word;
4
import ch.jalu.wordeval.evaluators.AllWordsEvaluator;
5
import ch.jalu.wordeval.evaluators.export.EvaluatorExportUtil;
6
import ch.jalu.wordeval.evaluators.result.WordWithKey;
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.Collection;
13
import java.util.Comparator;
14
import java.util.HashSet;
15
import java.util.List;
16
import java.util.Map;
17
import java.util.Set;
18
import java.util.TreeMap;
19
import java.util.stream.Collectors;
20

21
/**
22
 * Finds emordnilaps, words that produce another word when reversed,
23
 * such as German "Lager" and "Regal".
24
 */
25
public class Emordnilap implements AllWordsEvaluator {
2✔
26

27
  @Getter
6✔
28
  private final List<WordWithKey> results = new ArrayList<>();
29

30
  @Override
31
  public void evaluate(Collection<Word> words) {
32
    TreeMap<String, Word> wordsByLowercase = words.stream()
6✔
33
      .collect(Collectors.toMap(Word::getLowercase, word -> word, (a, b) -> b, TreeMap::new));
6✔
34

35
    for (Map.Entry<String, Word> entry : wordsByLowercase.entrySet()) {
11✔
36
      String lowercase = entry.getKey();
4✔
37
      String reversed = StringUtils.reverse(lowercase);
3✔
38
      Word reversedWord = wordsByLowercase.get(reversed);
5✔
39
      if (lowercase.compareTo(reversed) < 0 && reversedWord != null) {
6✔
40
        // TODO: Add smarter checks to avoid performing work, maybe can even stop once compareTo is < 0 ?
41
        results.add(new WordWithKey(reversedWord, entry.getKey()));
11✔
42
      }
43
    }
1✔
44
  }
1✔
45

46
  @Override
47
  public String getId() {
48
    return "group.emordnilap";
×
49
  }
50

51
  @Override
52
  public ListMultimap<Object, Object> getTopResults(int topScores, int maxLimit) {
53
    List<WordWithKey> sortedResult = results.stream()
×
54
        .sorted(Comparator.<WordWithKey>comparingInt(wordWithKey -> wordWithKey.getKey().length()).reversed())
×
55
        .toList();
×
56

57
    Set<Integer> uniqueValues = new HashSet<>();
×
UNCOV
58
    ListMultimap<Object, Object> filteredResults = EvaluatorExportUtil.newListMultimap();
×
59
    for (WordWithKey wordWithKey : sortedResult) {
×
60
      int score = wordWithKey.getKey().length();
×
61
      if (uniqueValues.add(score) && uniqueValues.size() > topScores) {
×
UNCOV
62
        break;
×
63
      }
UNCOV
64
      filteredResults.put(score, wordWithKey.getWord().getRaw() + " (" + wordWithKey.getKey() + ")");
×
65
      if (filteredResults.size() >= maxLimit) {
×
UNCOV
66
        break;
×
67
      }
UNCOV
68
    }
×
69

UNCOV
70
    return filteredResults;
×
71
  }
72
}
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