Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 60b2baf

Browse files
Address philc's comments.
1 parent 56325ab commit 60b2baf

File tree

1 file changed

+22
-64
lines changed

1 file changed

+22
-64
lines changed

tests/unit_tests/completion_test.coffee

Lines changed: 22 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -229,90 +229,48 @@ context "suggestions",
229229
assert.equal -1, suggestion.generateHtml().indexOf("http://ninjawords.com")
230230

231231
context "RankingUtils.wordRelevancy",
232-
should "get a higher relevancy score in shorter URLs", ->
233-
highScore = RankingUtils.wordRelevancy(["stack"], "http://stackoverflow.com/short", "nothing")
234-
lowScore = RankingUtils.wordRelevancy(["stack"], "http://stackoverflow.com/longer", "nothing")
232+
should "score higher in shorter URLs", ->
233+
highScore = RankingUtils.wordRelevancy(["stack"], "http://stackoverflow.com/short", "a-title")
234+
lowScore = RankingUtils.wordRelevancy(["stack"], "http://stackoverflow.com/longer", "a-title")
235235
assert.isTrue highScore > lowScore
236236

237-
should "get a higher relevancy score in shorter titles", ->
238-
highScore = RankingUtils.wordRelevancy(["ffee"], "http://stackoverflow.com/same", "Coffeescript")
239-
lowScore = RankingUtils.wordRelevancy(["ffee"], "http://stackoverflow.com/same", "Coffeescript rocks")
237+
should "score higher in shorter titles", ->
238+
highScore = RankingUtils.wordRelevancy(["coffee"], "a-url", "Coffeescript")
239+
lowScore = RankingUtils.wordRelevancy(["coffee"], "a-url", "Coffeescript rocks")
240240
assert.isTrue highScore > lowScore
241241

242-
should "get a higher relevancy score for matching the start of a word (in a URL)", ->
243-
lowScore = RankingUtils.wordRelevancy(["stack"], "http://Xstackoverflow.com/same", "nothing")
244-
highScore = RankingUtils.wordRelevancy(["stack"], "http://stackoverflowX.com/same", "nothing")
242+
should "score higher for matching the start of a word (in a URL)", ->
243+
lowScore = RankingUtils.wordRelevancy(["stack"], "http://Xstackoverflow.com/same", "a-title")
244+
highScore = RankingUtils.wordRelevancy(["stack"], "http://stackoverflowX.com/same", "a-title")
245245
assert.isTrue highScore > lowScore
246246

247-
should "get a higher relevancy score for matching the start of a word (in a title)", ->
248-
lowScore = RankingUtils.wordRelevancy(["ted"], "http://stackoverflow.com/same", "Dist racted")
249-
highScore = RankingUtils.wordRelevancy(["ted"], "http://stackoverflow.com/same", "Distrac ted")
247+
should "score higher for matching the start of a word (in a title)", ->
248+
lowScore = RankingUtils.wordRelevancy(["te"], "a-url", "Dist racted")
249+
highScore = RankingUtils.wordRelevancy(["te"], "a-url", "Distrac ted")
250250
assert.isTrue highScore > lowScore
251251

252-
should "get a higher relevancy score for matching a whole word (in a URL)", ->
253-
lowScore = RankingUtils.wordRelevancy(["com"], "http://stackoverflow.comX/same", "nothing")
254-
highScore = RankingUtils.wordRelevancy(["com"], "http://stackoverflowX.com/same", "nothing")
252+
should "score higher for matching a whole word (in a URL)", ->
253+
lowScore = RankingUtils.wordRelevancy(["com"], "http://stackoverflow.comX/same", "a-title")
254+
highScore = RankingUtils.wordRelevancy(["com"], "http://stackoverflowX.com/same", "a-title")
255255
assert.isTrue highScore > lowScore
256256

257-
should "get a higher relevancy score for matching a whole word (in a title)", ->
258-
lowScore = RankingUtils.wordRelevancy(["com"], "http://stackoverflow.com/same", "abc comX")
259-
highScore = RankingUtils.wordRelevancy(["com"], "http://stackoverflow.com/same", "abcX com")
257+
should "score higher for matching a whole word (in a title)", ->
258+
lowScore = RankingUtils.wordRelevancy(["com"], "a-url", "abc comX")
259+
highScore = RankingUtils.wordRelevancy(["com"], "a-url", "abcX com")
260260
assert.isTrue highScore > lowScore
261261

262262
# # TODO: (smblott)
263263
# # Word relevancy should take into account the number of matches (it doesn't currently).
264-
# should "get a higher relevancy score for multiple matches (in a URL)", ->
265-
# lowScore = RankingUtils.wordRelevancy(["stack"], "http://stackoverflow.com/Xxxxxx", "nothing")
266-
# highScore = RankingUtils.wordRelevancy(["stack"], "http://stackoverflow.com/Xstack", "nothing")
264+
# should "score higher for multiple matches (in a URL)", ->
265+
# lowScore = RankingUtils.wordRelevancy(["stack"], "http://stackoverflow.com/Xxxxxx", "a-title")
266+
# highScore = RankingUtils.wordRelevancy(["stack"], "http://stackoverflow.com/Xstack", "a-title")
267267
# assert.isTrue highScore > lowScore
268268

269-
# should "get a higher relevancy score for multiple matches (in a title)", ->
269+
# should "score higher for multiple matches (in a title)", ->
270270
# lowScore = RankingUtils.wordRelevancy(["bbc"], "http://stackoverflow.com/same", "BBC Radio 4 (XBCr4)")
271271
# highScore = RankingUtils.wordRelevancy(["bbc"], "http://stackoverflow.com/same", "BBC Radio 4 (BBCr4)")
272272
# assert.isTrue highScore > lowScore
273273

274-
# WARNING: The following tests are hardware dependent. They depend upon
275-
# different but algebraically-equivalent sequences of floating point
276-
# operations yielding the same results. That they ever work at all is quite
277-
# remarkable.
278-
# TODO: (smblott)
279-
# Remove these tests when `oldWordRelevancy` is removed.
280-
context "RankingUtils.wordRelevancy (temporary hardware-dependent tests)",
281-
should "exactly equal oldWordRelevancy for whole word matches (in a URL)", ->
282-
newScore = RankingUtils.wordRelevancy(["com"], "http://stackoverflow.com/same", "irrelevant")
283-
oldScore = RankingUtils.oldWordRelevancy(["com"], "http://stackoverflow.com/same", "irrelevant")
284-
assert.equal newScore, oldScore # remarkable! Exactly equal floats.
285-
286-
should "yield 2/3 * oldWordRelevancy for matches at the start of a word (in a URL)", ->
287-
newScore = RankingUtils.wordRelevancy(["sta"], "http://stackoverflow.com/same", "irrelevant")
288-
oldScore = (2.0/3.0) * RankingUtils.oldWordRelevancy(["sta"], "http://stackoverflow.com/same", "irrelevant")
289-
assert.equal newScore, oldScore # remarkable! Exactly equal floats.
290-
291-
should "yield 1/3 * oldWordRelevancy for matches within a word (in a URL)", ->
292-
newScore = RankingUtils.wordRelevancy(["over"], "http://stackoverflow.com/same", "irrelevant")
293-
oldScore = (1.0/3.0) * RankingUtils.oldWordRelevancy(["over"], "http://stackoverflow.com/same", "irrelevant")
294-
assert.equal newScore, oldScore # remarkable! Exactly equal floats.
295-
296-
should "exactly equal oldWordRelevancy for whole word matches (in a title)", ->
297-
newScore = RankingUtils.wordRelevancy(["relevant"], "http://stackoverflow.com/same", "XX relevant YY")
298-
# Multiply by 2 to account for new wordRelevancy favoring title.
299-
oldScore = 2 * RankingUtils.oldWordRelevancy(["relevant"], "http://stackoverflow.com/same", "XX relevant YY")
300-
assert.equal newScore, oldScore # remarkable! Exactly equal floats.
301-
302-
should "2/3 * oldWordRelevancy for matches at the start of a word (in a title)", ->
303-
newScore = RankingUtils.wordRelevancy(["relev"], "http://stackoverflow.com/same", "XX relevant YY")
304-
# Multiply by 2 to account for new wordRelevancy favoring title.
305-
oldScore = (2.0/3.0) * 2 * RankingUtils.oldWordRelevancy(["relev"], "http://stackoverflow.com/same", "XX relevant YY")
306-
assert.equal newScore, oldScore # remarkable! Exactly equal floats.
307-
308-
should "1/3 * oldWordRelevancy for matches within a word (in a title)", ->
309-
newScore = RankingUtils.wordRelevancy(["elev"], "http://stackoverflow.com/same", "XX relevant YY")
310-
# Multiply by 2 to account for new wordRelevancy favoring title.
311-
oldScore = (1.0/3.0) * 2 * RankingUtils.oldWordRelevancy(["elev"], "http://stackoverflow.com/same", "XX relevant YY")
312-
assert.equal newScore, oldScore # remarkable! Exactly equal floats.
313-
#
314-
# End of hardware-dependent tests.
315-
316274
context "Suggestion.pushMatchingRanges",
317275
should "extract ranges matching term (simple case, two matches)", ->
318276
ranges = []

0 commit comments

Comments
 (0)