diff options
author | Martin Czygan <martin.czygan@gmail.com> | 2021-07-01 01:22:42 +0200 |
---|---|---|
committer | Martin Czygan <martin.czygan@gmail.com> | 2021-07-01 01:22:42 +0200 |
commit | f9515d2ece7d930481f11ba94ce08b9bc63e9a90 (patch) | |
tree | 52c14e13ce16ae26737a67108024598ea0034c4f | |
parent | 73bad649ab9b572da60d4f0c07ef43195162c07f (diff) | |
download | refcat-f9515d2ece7d930481f11ba94ce08b9bc63e9a90.tar.gz refcat-f9515d2ece7d930481f11ba94ce08b9bc63e9a90.zip |
zippy: add tests
-rw-r--r-- | skate/zippy.go | 14 | ||||
-rw-r--r-- | skate/zippy_test.go | 61 |
2 files changed, 72 insertions, 3 deletions
diff --git a/skate/zippy.go b/skate/zippy.go index febd4c5..59951e2 100644 --- a/skate/zippy.go +++ b/skate/zippy.go @@ -375,13 +375,16 @@ func ZippyBrefAugment(bref, raw io.Reader, w io.Writer) error { // removeSelfLinks removes self-referential links. TODO: Those should be caught // at the root cause. func removeSelfLinks(brefs []*BiblioRef) (result []*BiblioRef) { + var i int for _, bref := range brefs { if bref.SourceReleaseIdent == bref.TargetReleaseIdent { continue } - result = append(result, bref) + brefs[i] = bref + i++ } - return result + brefs = brefs[:i] + return brefs } // deduplicateBrefs deduplicates by the document id (for elasticsearch), which @@ -392,6 +395,12 @@ func deduplicateBrefs(brefs []*BiblioRef) []*BiblioRef { switch { case brefs[i].MatchStatus == StatusExact.Short(): return true + case brefs[i].MatchStatus == StatusStrong.Short(): + return true + case brefs[i].MatchStatus == StatusWeak.Short(): + return false + case brefs[i].MatchStatus == StatusAmbiguous.Short(): + return false case brefs[i].MatchStatus != StatusUnmatched.Short(): return true default: @@ -401,6 +410,7 @@ func deduplicateBrefs(brefs []*BiblioRef) []*BiblioRef { var ( unique []*BiblioRef seen = set.New() + // i int ) for _, v := range brefs { if seen.Contains(v.Key) { diff --git a/skate/zippy_test.go b/skate/zippy_test.go index 3c1911c..4c9ed32 100644 --- a/skate/zippy_test.go +++ b/skate/zippy_test.go @@ -277,7 +277,7 @@ func TestRemoveSelfLinks(t *testing.T) { }, { brefs: []*BiblioRef{}, - result: nil, + result: []*BiblioRef{}, }, { brefs: []*BiblioRef{ @@ -308,3 +308,62 @@ func TestRemoveSelfLinks(t *testing.T) { } } } + +func TestDeduplicateBrefs(t *testing.T) { + var cases = []struct { + brefs []*BiblioRef + result []*BiblioRef + }{ + { + brefs: nil, + result: nil, + }, + { + brefs: []*BiblioRef{}, + result: nil, + }, + { + brefs: []*BiblioRef{ + &BiblioRef{Key: "123", MatchStatus: StatusStrong.Short()}, + &BiblioRef{Key: "123", MatchStatus: StatusExact.Short()}, + }, + result: []*BiblioRef{ + &BiblioRef{Key: "123", MatchStatus: StatusExact.Short()}, + }, + }, + { + brefs: []*BiblioRef{ + &BiblioRef{Key: "123", MatchStatus: StatusStrong.Short()}, + &BiblioRef{Key: "123", MatchStatus: StatusUnmatched.Short()}, + }, + result: []*BiblioRef{ + &BiblioRef{Key: "123", MatchStatus: StatusStrong.Short()}, + }, + }, + { + brefs: []*BiblioRef{ + &BiblioRef{Key: "123", MatchStatus: StatusStrong.Short()}, + &BiblioRef{Key: "123", MatchStatus: StatusWeak.Short()}, + }, + result: []*BiblioRef{ + &BiblioRef{Key: "123", MatchStatus: StatusStrong.Short()}, + }, + }, + { + brefs: []*BiblioRef{ + &BiblioRef{Key: "123", MatchStatus: StatusStrong.Short()}, + &BiblioRef{Key: "123", MatchStatus: StatusAmbiguous.Short()}, + }, + result: []*BiblioRef{ + &BiblioRef{Key: "123", MatchStatus: StatusStrong.Short()}, + }, + }, + } + for i, c := range cases { + result := deduplicateBrefs(c.brefs) + if !reflect.DeepEqual(result, c.result) { + t.Fatalf("[%d]: got %v, want %v (%v)", + i, result, c.result, pretty.Diff(result, c.result)) + } + } +} |