summaryrefslogtreecommitdiff
path: root/test/fzytest.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john.hawthorn@gmail.com>2016-06-13 23:36:51 -0700
committerJohn Hawthorn <john.hawthorn@gmail.com>2016-06-22 18:32:15 -0700
commit6d352b39cb8edca87705065a5b87e6208cafba6b (patch)
treeac45c53b8c2e05f4b8c90da9d8bc4a93f424f876 /test/fzytest.c
parentd9924b1eb8a80bc642340227aa92f276c3ac1d5d (diff)
Add tests for exact scores
Preparing for some changes to the match method
Diffstat (limited to 'test/fzytest.c')
-rw-r--r--test/fzytest.c45
1 files changed, 43 insertions, 2 deletions
diff --git a/test/fzytest.c b/test/fzytest.c
index 16a575c..0e0bad0 100644
--- a/test/fzytest.c
+++ b/test/fzytest.c
@@ -2,6 +2,7 @@
#include <string.h>
#include <signal.h>
+#include "../config.h"
#include "match.h"
#include "choices.h"
@@ -39,7 +40,7 @@ void test_match() {
assert(has_match("", "a"));
}
-void test_scoring() {
+void test_relative_scores() {
/* App/Models/Order is better than App/MOdels/zRder */
assert(match("amor", "app/models/order") > match("amor", "app/models/zrder"));
@@ -66,6 +67,45 @@ void test_scoring() {
assert(match("abc", " a b c ") > match("abc", " a b c "));
}
+void test_exact_scores() {
+ /* Exact match is SCORE_MAX */
+ assert(match("abc", "abc") == SCORE_MAX);
+ assert(match("aBc", "abC") == SCORE_MAX);
+
+ /* Empty query always results in SCORE_MIN */
+ assert(match("", "") == SCORE_MIN);
+ assert(match("", "a") == SCORE_MIN);
+ assert(match("", "bb") == SCORE_MIN);
+
+ /* Gaps */
+ assert(match("a", "*a") == SCORE_GAP_LEADING);
+ assert(match("a", "*ba") == SCORE_GAP_LEADING*2);
+ assert(match("a", "**a*") == SCORE_GAP_LEADING*2 + SCORE_GAP_TRAILING);
+ assert(match("a", "**a**") == SCORE_GAP_LEADING*2 + SCORE_GAP_TRAILING*2);
+ assert(match("aa", "**aa**") == SCORE_GAP_LEADING*2 + SCORE_MATCH_CONSECUTIVE + SCORE_GAP_TRAILING*2);
+ assert(match("aa", "**a*a**") == SCORE_GAP_LEADING + SCORE_GAP_LEADING + SCORE_GAP_INNER + SCORE_GAP_TRAILING + SCORE_GAP_TRAILING);
+
+ /* Consecutive */
+ assert(match("aa", "*aa") == SCORE_GAP_LEADING + SCORE_MATCH_CONSECUTIVE);
+ assert(match("aaa", "*aaa") == SCORE_GAP_LEADING + SCORE_MATCH_CONSECUTIVE*2);
+ assert(match("aaa", "*a*aa") == SCORE_GAP_LEADING + SCORE_GAP_INNER + SCORE_MATCH_CONSECUTIVE);
+
+ /* Slash */
+ assert(match("a", "/a") == SCORE_GAP_LEADING + SCORE_MATCH_SLASH);
+ assert(match("a", "*/a") == SCORE_GAP_LEADING*2 + SCORE_MATCH_SLASH);
+ assert(match("aa", "a/aa") == SCORE_GAP_LEADING*2 + SCORE_MATCH_SLASH + SCORE_MATCH_CONSECUTIVE);
+
+ /* Capital */
+ assert(match("a", "bA") == SCORE_GAP_LEADING + SCORE_MATCH_CAPITAL);
+ assert(match("a", "baA") == SCORE_GAP_LEADING*2 + SCORE_MATCH_CAPITAL);
+ assert(match("aa", "baAa") == SCORE_GAP_LEADING*2 + SCORE_MATCH_CAPITAL + SCORE_MATCH_CONSECUTIVE);
+
+ /* Dot */
+ assert(match("a", ".a") == SCORE_GAP_LEADING + SCORE_MATCH_DOT);
+ assert(match("a", "*a.a") == SCORE_GAP_LEADING*3 + SCORE_MATCH_DOT);
+ assert(match("a", "*a.a") == SCORE_GAP_LEADING + SCORE_GAP_INNER + SCORE_MATCH_DOT);
+}
+
void test_positions_1() {
size_t positions[3];
match_positions("amo", "app/models/foo", positions);
@@ -245,7 +285,8 @@ int main(int argc, char *argv[]) {
signal(SIGTRAP, ignore_signal);
runtest(test_match);
- runtest(test_scoring);
+ runtest(test_relative_scores);
+ runtest(test_exact_scores);
runtest(test_positions_1);
runtest(test_positions_2);
runtest(test_positions_3);