aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPhil Crosby2014-05-17 23:37:40 -0700
committerPhil Crosby2014-05-17 23:37:40 -0700
commit699babc172715bd014b02bcd659b8186f9848a00 (patch)
tree68df9899912a1bd1ea31774ec17b474e3765757e /tests
parenta7ac21b392708445374ce9767be2b65eaf89d103 (diff)
parent37bdd510bd2d3fbe2674174d245f94664498f88b (diff)
downloadvimium-699babc172715bd014b02bcd659b8186f9848a00.tar.bz2
Merge pull request #1060 from smblott-github/relevancy
Relevancy - incorporate the position at which matches occur.
Diffstat (limited to 'tests')
-rw-r--r--tests/unit_tests/completion_test.coffee44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/unit_tests/completion_test.coffee b/tests/unit_tests/completion_test.coffee
index fb267f63..bba0a0f8 100644
--- a/tests/unit_tests/completion_test.coffee
+++ b/tests/unit_tests/completion_test.coffee
@@ -228,6 +228,50 @@ context "suggestions",
suggestion = new Suggestion(["queryterm"], "tab", "http://ninjawords.com", "ninjawords", returns(1))
assert.equal -1, suggestion.generateHtml().indexOf("http://ninjawords.com")
+context "RankingUtils.wordRelevancy",
+ should "score higher in shorter URLs", ->
+ highScore = RankingUtils.wordRelevancy(["stack"], "http://stackoverflow.com/short", "a-title")
+ lowScore = RankingUtils.wordRelevancy(["stack"], "http://stackoverflow.com/longer", "a-title")
+ assert.isTrue highScore > lowScore
+
+ should "score higher in shorter titles", ->
+ highScore = RankingUtils.wordRelevancy(["coffee"], "a-url", "Coffeescript")
+ lowScore = RankingUtils.wordRelevancy(["coffee"], "a-url", "Coffeescript rocks")
+ assert.isTrue highScore > lowScore
+
+ should "score higher for matching the start of a word (in a URL)", ->
+ lowScore = RankingUtils.wordRelevancy(["stack"], "http://Xstackoverflow.com/same", "a-title")
+ highScore = RankingUtils.wordRelevancy(["stack"], "http://stackoverflowX.com/same", "a-title")
+ assert.isTrue highScore > lowScore
+
+ should "score higher for matching the start of a word (in a title)", ->
+ lowScore = RankingUtils.wordRelevancy(["te"], "a-url", "Dist racted")
+ highScore = RankingUtils.wordRelevancy(["te"], "a-url", "Distrac ted")
+ assert.isTrue highScore > lowScore
+
+ should "score higher for matching a whole word (in a URL)", ->
+ lowScore = RankingUtils.wordRelevancy(["com"], "http://stackoverflow.comX/same", "a-title")
+ highScore = RankingUtils.wordRelevancy(["com"], "http://stackoverflowX.com/same", "a-title")
+ assert.isTrue highScore > lowScore
+
+ should "score higher for matching a whole word (in a title)", ->
+ lowScore = RankingUtils.wordRelevancy(["com"], "a-url", "abc comX")
+ highScore = RankingUtils.wordRelevancy(["com"], "a-url", "abcX com")
+ assert.isTrue highScore > lowScore
+
+ # # TODO: (smblott)
+ # # Word relevancy should take into account the number of matches (it doesn't currently).
+ # should "score higher for multiple matches (in a URL)", ->
+ # lowScore = RankingUtils.wordRelevancy(["stack"], "http://stackoverflow.com/Xxxxxx", "a-title")
+ # highScore = RankingUtils.wordRelevancy(["stack"], "http://stackoverflow.com/Xstack", "a-title")
+ # assert.isTrue highScore > lowScore
+
+ # should "score higher for multiple matches (in a title)", ->
+ # lowScore = RankingUtils.wordRelevancy(["bbc"], "http://stackoverflow.com/same", "BBC Radio 4 (XBCr4)")
+ # highScore = RankingUtils.wordRelevancy(["bbc"], "http://stackoverflow.com/same", "BBC Radio 4 (BBCr4)")
+ # assert.isTrue highScore > lowScore
+
+context "Suggestion.pushMatchingRanges",
should "extract ranges matching term (simple case, two matches)", ->
ranges = []
[ one, two, three ] = [ "one", "two", "three" ]