private void selectCorrespondingText(final String text) { double score = 0; WebElement optionToSelect = null; for (WebElement option : options) { String source = option.getText(); if (service.score(source, text) > score) { score = service.score(source, text); optionToSelect = option; } } if (optionToSelect != null) { setSelected(optionToSelect); } else { throw new NoSuchElementException("Cannot locate option with corresponding text " + text); } }
for (ComparableFilenameWord misspelledWord : words) { StringBuilder sb = new StringBuilder(); List<SimilarityScore> scores = service.scoreAll(dict.getWords(), misspelledWord.toString()); Collections.sort(scores, comp); sb.append(misspelledWord).append(": ");
@Test public void testFindTop() { SimilarityStrategy strategy = mock(SimilarityStrategy.class); String target = "McDonalds"; String c1 = "MacMahons"; String c2 = "McPherson"; String c3 = "McDonalds"; SimilarityScore expected = new SimilarityScore(c3, 1.000); when(strategy.score(c1, target)).thenReturn(0.90); when(strategy.score(c2, target)).thenReturn(0.74); when(strategy.score(c3, target)).thenReturn(1.000); StringSimilarityService service = new StringSimilarityServiceImpl(strategy); List<String> features = new ArrayList<String>(); features.add(c1); features.add(c2); features.add(c3); SimilarityScore top= service.findTop(features,target); verify(strategy).score(c1, target); verify(strategy).score(c2, target); verify(strategy).score(c3, target); assertEquals(expected, top); }
@Test public void testScoreAll() { SimilarityStrategy strategy = mock(SimilarityStrategy.class); String target = "McDonalds"; String c1 = "MacMahons"; String c2 = "McPherson"; String c3 = "McDonalds"; when(strategy.score(target, c1)).thenReturn(0.90); when(strategy.score(target, c2)).thenReturn(0.74); when(strategy.score(target, c3)).thenReturn(1.000); StringSimilarityService service = new StringSimilarityServiceImpl(strategy); List<String> features = new ArrayList<String>(); features.add(c1); features.add(c2); features.add(c3); List<SimilarityScore> scores = service.scoreAll(features, target); verify(strategy).score(c1, target); verify(strategy).score(c2, target); verify(strategy).score(c3, target); assertEquals(3, scores.size()); }
@Test public void testFindTop_Ascending() { SimilarityStrategy strategy = mock(SimilarityStrategy.class); String target = "McDonalds"; String c1 = "MacMahons"; String c2 = "McPherson"; String c3 = "McDonalds"; SimilarityScore expected = new SimilarityScore(c2, 0.74); when(strategy.score(c1, target)).thenReturn(0.90); when(strategy.score(c2, target)).thenReturn(0.74); when(strategy.score(c3, target)).thenReturn(1.000); StringSimilarityService service = new StringSimilarityServiceImpl(strategy); List<String> features = new ArrayList<String>(); features.add(c1); features.add(c2); features.add(c3); AscendingSimilarityScoreComparator comparator = new AscendingSimilarityScoreComparator(); SimilarityScore top= service.findTop(features,target, comparator); verify(strategy).score(c1, target); verify(strategy).score(c2, target); verify(strategy).score(c3, target); assertEquals(expected, top); }
crowdinCommands.add(COMMAND_PULL); for (String cmd : crowdinCommands) { s = service.score(cmd, command); if (s > score) { score = s;
@Test public void testFindTop_Descending() { SimilarityStrategy strategy = mock(SimilarityStrategy.class); String target = "McDonalds"; String c1 = "MacMahons"; String c2 = "McPherson"; String c3 = "McDonalds"; SimilarityScore expected = new SimilarityScore(c3, 1.000); when(strategy.score(c1, target)).thenReturn(0.90); when(strategy.score(c2, target)).thenReturn(0.74); when(strategy.score(c3, target)).thenReturn(1.000); StringSimilarityService service = new StringSimilarityServiceImpl(strategy); List<String> features = new ArrayList<String>(); features.add(c1); features.add(c2); features.add(c3); DescendingSimilarityScoreComparator comparator = new DescendingSimilarityScoreComparator(); SimilarityScore top= service.findTop(features,target, comparator); verify(strategy).score(c1, target); verify(strategy).score(c2, target); verify(strategy).score(c3, target); assertEquals(expected, top); } }
@ReplayOnError public void deselectByCorrespondingText(final String text) { if (!isMultiple()) { throw new UnsupportedOperationException("You may only deselect all options of a multi-select"); } try { findElement(); double score = 0; WebElement optionToSelect = null; for (WebElement option : options) { String source = option.getText(); if (service.score(source, text) > score) { score = service.score(source, text); optionToSelect = option; } } if (optionToSelect != null) { setDeselected(optionToSelect); } else { throw new NoSuchElementException("Cannot locate option with corresponding text " + text); } } finally { finalizeAction(); } }
@Test public void testScore() { SimilarityStrategy strategy = mock(SimilarityStrategy.class); String target = "McDonalds"; String c1 = "MacMahons"; String c2 = "McPherson"; String c3 = "McDonalds"; when(strategy.score(c1, target)).thenReturn(0.90); when(strategy.score(c2, target)).thenReturn(0.74); when(strategy.score(c3, target)).thenReturn(1.000); StringSimilarityService service = new StringSimilarityServiceImpl(strategy); double score = service.score(c1, target); verify(strategy).score(c1, target); assertEquals(0.90, score, 0.000); }