Add tests for label.go
This commit is contained in:
parent
61b5bb028c
commit
3dc9abea67
55
internal/photoprism/label_test.go
Normal file
55
internal/photoprism/label_test.go
Normal 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)
|
||||
})
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user