• 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

66.67
/src/main/java/ch/jalu/wordeval/wordgraph/GraphBuilder.java
1
package ch.jalu.wordeval.wordgraph;
2

3
import ch.jalu.wordeval.dictionary.Dictionary;
4
import ch.jalu.wordeval.dictionary.DictionaryProcessor;
5
import ch.jalu.wordeval.dictionary.Word;
6
import lombok.Getter;
7
import lombok.extern.slf4j.Slf4j;
8
import org.jgrapht.graph.DefaultWeightedEdge;
9
import org.jgrapht.graph.SimpleGraph;
10
import org.jgrapht.graph.SimpleWeightedGraph;
11

12
import java.util.List;
13
import java.util.stream.Collectors;
14

15
/**
16
 * Finds which words have a Damerau-Levenshtein distance of 1 and saves these
17
 * connections, forming a graph over the dictionary words.
18
 */
19
@Slf4j
4✔
20
public class GraphBuilder {
21
  
22
  /** 
23
   * The interval in which to display the words that have been processed.
24
   * This must be a number corresponding to 2^k-1, where k >= 1 (e.g. 255, 1023).
25
   */
26
  private static final int STAT_INTERVAL = 255;
27
  
28
  @Getter
29
  private SimpleGraph<String, DefaultWeightedEdge> graph;
30

31
  /**
32
   * Builds a new ConnectionsBuilder object and computes the
33
   * connections for the given dictionary.
34
   *
35
   * @param dictionary the dictionary
36
   */
37
  public GraphBuilder(Dictionary dictionary) {
38
    this(getDictionaryWords(dictionary));
×
UNCOV
39
  }
×
40
  
41
  /**
42
   * Builds a new ConnectionsBuilder object and computes the
43
   * connections based on the given list of words.
44
   *
45
   * @param words the list of words to process
46
   */
47
  public GraphBuilder(List<String> words) {
2✔
48
    constructGraph(words);
3✔
49
  }
1✔
50
  
51
  private static List<String> getDictionaryWords(Dictionary dictionary) {
52
    return DictionaryProcessor.readAllWords(dictionary).stream()
×
53
      .map(Word::getRaw)
×
54
      .distinct()
×
55
      .sorted()
×
UNCOV
56
      .collect(Collectors.toList());
×
57
  }
58

59
  private void constructGraph(List<String> words) {
60
    graph = new SimpleWeightedGraph<>(DefaultWeightedEdge.class);
6✔
61
    for (int i = 0; i < words.size(); ++i) {
8✔
62
      final String leftWord = words.get(i);
5✔
63
      graph.addVertex(leftWord);
5✔
64
      for (int j = i + 1; j < words.size(); ++j) {
10✔
65
        final String rightWord = words.get(j);
5✔
66
        if (DamerauLevenshtein.isEditDistance1(rightWord, leftWord)) {
4✔
67
          // vertices must always be added before edges. addVertex() checks against a Set,
68
          // so the check is efficient enough for us to just always call the functions
69
          graph.addVertex(rightWord);
5✔
70
          graph.addEdge(leftWord, rightWord);
6✔
71
        }
72
      }
73
      if ((i & STAT_INTERVAL) == STAT_INTERVAL) {
5!
UNCOV
74
        log.info("Processed {} words", i);
×
75
      }
76
    }
77
    log.info("Processed total {} words", words.size());
6✔
78
  }
1✔
79

80
}
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