From 9c767dbf39b7a94875ab61eb0f5c00a878d8814d Mon Sep 17 00:00:00 2001 From: Theresa Gresch Date: Sun, 12 Jan 2020 15:40:01 +0100 Subject: [PATCH] Add test for classify/labels --- internal/classify/labels_test.go | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/internal/classify/labels_test.go b/internal/classify/labels_test.go index 6eaa4dbb8..8c4d8e614 100644 --- a/internal/classify/labels_test.go +++ b/internal/classify/labels_test.go @@ -55,4 +55,39 @@ func TestLabels_Title(t *testing.T) { assert.Equal(t, "fallback", labels.Title("fallback")) }) + + t.Run("empty labels", func(t *testing.T) { + labels := Labels{} + + assert.Equal(t, "", labels.Title("")) + }) + + t.Run("label priority < 0", func(t *testing.T) { + cat := Label{Name: "cat", Source: "location", Uncertainty: 59, Priority: -1} + dog := Label{Name: "dog", Source: "location", Uncertainty: 10, Priority: -1} + labels := Labels{cat, dog} + + assert.Equal(t, "fallback", labels.Title("fallback")) + }) + + t.Run("label priority = 0", func(t *testing.T) { + cat := Label{Name: "cat", Source: "location", Uncertainty: 59, Priority: 0} + dog := Label{Name: "dog", Source: "location", Uncertainty: 62, Priority: 0} + labels := Labels{cat, dog} + + assert.Equal(t, "fallback", labels.Title("fallback")) + }) +} + +func TestLabels_Keywords(t *testing.T) { + cat := Label{Name: "cat", Source: "location", Uncertainty: 80, Priority: 5, Categories: []string{"animal"}} + dog := Label{Name: "dog", Source: "location", Uncertainty: 80, Priority: 5} + labels := Labels{cat, dog} + + t.Run("labelWithName", func(t *testing.T) { + result := labels.Keywords() + assert.Equal(t, "cat", result[0]) + assert.Equal(t, "animal", result[1]) + assert.Equal(t, "dog", result[2]) + }) }