Add tests for label.go

This commit is contained in:
Theresa Gresch 2019-07-08 14:09:21 +02:00
parent 61b5bb028c
commit 3dc9abea67

View File

@ -0,0 +1,55 @@
package photoprism
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestLabel_NewLocationLabel(t *testing.T) {
LocLabel := NewLocationLabel("locationtest", 23, 1)
t.Log(LocLabel)
assert.Equal(t, "location", LocLabel.Source)
assert.Equal(t, 23, LocLabel.Uncertainty)
assert.Equal(t, "locationtest", LocLabel.Name)
t.Run("locationtest/slash/897", func(t *testing.T) {
LocLabel := NewLocationLabel("locationtest/slash/897", 24, -2)
t.Log(LocLabel)
assert.Equal(t, "location", LocLabel.Source)
assert.Equal(t, 24, LocLabel.Uncertainty)
assert.Equal(t, "locationtest/slash/897", LocLabel.Name)
})
t.Run("locationtest-minus/slash", func(t *testing.T) {
LocLabel := NewLocationLabel("locationtest-minus/slash", 80, -2)
t.Log(LocLabel)
assert.Equal(t, "location", LocLabel.Source)
assert.Equal(t, 80, LocLabel.Uncertainty)
assert.Equal(t, "locationtest-minus/slash", LocLabel.Name)
})
}
func TestLabel_AppendLabel(t *testing.T) {
cat := Label{Name: "cat", Source: "location", Uncertainty: 80, Priority: 5}
dog := Label{Name: "dog", Source: "location", Uncertainty: 80, Priority: 5}
labels := Labels{cat, dog}
t.Run("labelWithName", func(t *testing.T) {
assert.Equal(t, 2, labels.Len())
cow := Label{Name: "cow", Source: "location", Uncertainty: 80, Priority: 5}
labelsNew := labels.AppendLabel(cow)
assert.Equal(t, 3, labelsNew.Len())
assert.Equal(t, "dog", labelsNew[1].Name)
assert.Equal(t, "cat", labelsNew[0].Name)
assert.Equal(t, "cow", labelsNew[2].Name)
})
t.Run("labelWithoutName", func(t *testing.T) {
assert.Equal(t, 2, labels.Len())
cow := Label{Name: "", Source: "location", Uncertainty: 80, Priority: 5}
labelsNew := labels.AppendLabel(cow)
assert.Equal(t, 2, labelsNew.Len())
assert.Equal(t, "dog", labelsNew[1].Name)
})
}