Browse code

Cleanup test

John Hawthorn authored on 13/07/2014 01:48:50
Showing 1 changed files

  • test.rb index 6b92faf..e1e9f0b 100644
... ...
@@ -7,12 +7,20 @@ describe "score" do
7 7
     `./testscore '#{query}' '#{candidate}'`.to_f
8 8
   end
9 9
 
10
+  def assert_unmatched(candidate, query)
11
+    assert_equal 0, score(candidate, query)
12
+  end
13
+
14
+  def assert_matched(candidate, query)
15
+    assert_operator 0, :<, score(candidate, query)
16
+  end
17
+
10 18
   it "scores 1 when the query is empty" do
11 19
     assert_equal 1, score("a", "")
12 20
   end
13 21
 
14 22
   it "scores 0 when the choice is empty" do
15
-    assert_equal 0, score("", "a")
23
+    assert_unmatched "", "a"
16 24
   end
17 25
 
18 26
   it "scores 1 when exact match" do
... ...
@@ -20,22 +28,22 @@ describe "score" do
20 28
   end
21 29
 
22 30
   it "scores 0 when the query is longer than the choice" do
23
-    assert_equal 0, score("short", "longer")
31
+    assert_unmatched "short", "longer"
24 32
   end
25 33
 
26 34
   it "scores 0 when the query doesn't match at all" do
27
-    assert_equal 0, score("a", "b")
35
+    assert_unmatched "a", "b"
28 36
   end
29 37
 
30 38
   it "scores 0 when only a prefix of the query matches" do
31
-    assert_equal 0, score("ab", "ac")
39
+    assert_unmatched "ab", "ac"
32 40
   end
33 41
 
34 42
   it "scores greater than 0 when it matches" do
35
-    assert_operator 0, :<, score("a", "a")
36
-    assert_operator 0, :<, score("ab", "a")
37
-    assert_operator 0, :<, score("ba", "a")
38
-    assert_operator 0, :<, score("bab", "a")
39
-    assert_operator 0, :<, score("babababab", "aaaa")
43
+    assert_matched "a", "a"
44
+    assert_matched "ab", "a"
45
+    assert_matched "ba", "a"
46
+    assert_matched "bab", "a"
47
+    assert_matched "bababababab", "aaaaa"
40 48
   end
41 49
 end