alertmanager/ui/app/tests/Match.elm
stuart nelson 4f8ef26b28 Update matching algorithm (#910)
* Test for consecutive chars throughout string

Previously, we were only testing for consecutive
characters at the beginning of the string. Now,
the entire string being compared is searched
through for a matching character, and then the
consecutive search starts.

We were seeing weird situations where the text
entered matched the last half of certain terms,
but because it wasn't, but because we only
searched from the start, results that probably
shouldn't have been the top suggestion were being
suggested too high on the list.

* Weight consecutive matches more highly

Bit of a guess, this seemed to give better results
for my small test case.

* bindata
2017-07-19 11:50:33 +02:00

54 lines
1.8 KiB
Elm

module Match exposing (..)
import Test exposing (..)
import Expect
import Utils.Match exposing (jaroWinkler, consecutiveChars)
testJaroWinkler : Test
testJaroWinkler =
describe "jaroWinkler"
[ test "should find the right values 1" <|
\() ->
Expect.greaterThan (jaroWinkler "zi" "zone")
(jaroWinkler "zo" "zone")
, test "should find the right values 2" <|
\() ->
Expect.greaterThan (jaroWinkler "hook" "alertname")
(jaroWinkler "de" "dev")
, test "should find the right values 3" <|
\() ->
Expect.equal 0.0
(jaroWinkler "l" "zone")
, test "should find the right values 4" <|
\() ->
Expect.equal 1.0
(jaroWinkler "zone" "zone")
, test "should find the right values 5" <|
\() ->
Expect.greaterThan 0.688
(jaroWinkler "atleio3tefdoisahdf" "attributefdoiashfoihfeowfh9w8f9afaw9fahw")
]
testConsecutiveChars : Test
testConsecutiveChars =
describe "consecutiveChars"
[ test "should find the consecutiveChars 1" <|
\() ->
Expect.equal "zo"
(consecutiveChars "zo" "bozo")
, test "should find the consecutiveChars 2" <|
\() ->
Expect.equal "zo"
(consecutiveChars "zol" "zone")
, test "should find the consecutiveChars 3" <|
\() ->
Expect.equal "oon"
(consecutiveChars "oon" "baboone")
, test "should find the consecutiveChars 4" <|
\() ->
Expect.equal "dom"
(consecutiveChars "dom" "random")
]