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

ljacqu / wordeval / 14562498097

20 Apr 2025 07:08PM UTC coverage: 54.64% (-0.6%) from 55.233%
14562498097

push

github

ljacqu
Create tests for appData, prevent AppData from being initialized directly

270 of 570 branches covered (47.37%)

8 of 9 new or added lines in 3 files covered. (88.89%)

26 existing lines in 5 files now uncovered.

736 of 1347 relevant lines covered (54.64%)

3.24 hits per line

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

40.74
/src/main/java/ch/jalu/wordeval/evaluators/impl/VowelCount.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.export.EvaluatorExportUtil;
6
import ch.jalu.wordeval.evaluators.result.WordWithKey;
7
import ch.jalu.wordeval.language.Language;
8
import ch.jalu.wordeval.language.LetterType;
9
import com.google.common.collect.ListMultimap;
10
import lombok.Getter;
11
import lombok.ToString;
12

13
import java.util.ArrayList;
14
import java.util.Comparator;
15
import java.util.HashSet;
16
import java.util.List;
17
import java.util.Set;
18
import java.util.stream.Collectors;
19

20
/**
21
 * Evaluator which collects all words by count of
22
 * separate vowels or consonants for further processing.
23
 */
24
@ToString(of = "letterType")
25
public class VowelCount implements WordEvaluator {
26

27
  private final List<String> letters;
28
  @Getter
29
  private final LetterType letterType;
30
  @Getter
5✔
31
  private final List<WordWithKey> results = new ArrayList<>();
32

33
  public VowelCount(Language language, LetterType letterType) {
2✔
34
    this.letters = letterType.getLetters(language);
5✔
35
    this.letterType = letterType;
3✔
36
  }
1✔
37

38
  @Override
39
  public void evaluate(Word word) {
40
    // TODO #64: Iterate over the letters of the word instead
41
    String wordWithoutAccents = word.getWithoutAccents();
3✔
42
    String letterProfile = letters.stream()
5✔
43
      .filter(wordWithoutAccents::contains)
4✔
44
      .collect(Collectors.joining());
4✔
45
    results.add(new WordWithKey(word, letterProfile));
9✔
46
  }
1✔
47

48
  @Override
49
  public ListMultimap<Object, Object> getTopResults(int topScores, int maxLimit) {
50
    // TODO: Should probably skip this as PostEvaluators cover the interesting stuff
51
    List<WordWithKey> sortedResult = results.stream()
×
UNCOV
52
        .sorted(Comparator.comparing((WordWithKey wwk) -> wwk.key().length()).reversed())
×
53
        .toList();
×
54

55
    Set<String> uniqueValues = new HashSet<>();
×
56
    ListMultimap<Object, Object> filteredResults = EvaluatorExportUtil.newListMultimap();
×
57
    for (WordWithKey WordWithKey : sortedResult) {
×
UNCOV
58
      if (uniqueValues.add(WordWithKey.key()) && uniqueValues.size() > topScores) {
×
59
        break;
×
60
      }
61
      filteredResults.put(WordWithKey.key(), WordWithKey.word().getRaw());
×
UNCOV
62
      if (filteredResults.size() >= maxLimit) {
×
63
        break;
×
64
      }
65
    }
×
66

UNCOV
67
    return filteredResults;
×
68
  }
69

70
  @Override
71
  public String getId() {
72
    return switch (letterType) {
×
UNCOV
73
      case VOWELS -> "vowels.count";
×
UNCOV
74
      case CONSONANTS -> "consonants.count";
×
75
    };
76
  }
77
}
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