Skip to content

Commit

Permalink
More unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
suzaku committed Dec 4, 2020
1 parent bb6de01 commit 0342a80
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,26 @@ func TestUpdateEntryScore(t *testing.T) {
t.Errorf("Entity score is wrong: %f", e.score)
}
}

func TestLoadEntries(t *testing.T) {
t.Run("Should make sure the entries are sorted by score", func(t *testing.T) {
f, err := ioutil.TempFile("", "entries")
if err != nil {
t.Fatal(err)
}
content := []byte("20\t/a\n22\t/a/b\n12.5\t/c\n")
err = ioutil.WriteFile(f.Name(), content, 0666)
if err != nil {
t.Fatal(err)
}
entries := loadEntries(f.Name())
if len(entries) != 3 {
t.Errorf("Expect 3 entries, got: %v ", entries)
}
paths := make([]string, len(entries))
for i, e := range entries {
paths[i] = e.val
}
assertItemsEqual(t, paths, []string{"/a/b", "/a", "/c"})
})
}

0 comments on commit 0342a80

Please sign in to comment.