2019-12-11 16:55:18 +01:00
|
|
|
package entity
|
2019-07-16 13:10:31 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2019-12-11 14:10:20 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-07-16 13:10:31 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewPhotoLabel(t *testing.T) {
|
|
|
|
t.Run("name Christmas 2018", func(t *testing.T) {
|
|
|
|
photoLabel := NewPhotoLabel(1, 3, 80, "source")
|
|
|
|
assert.Equal(t, uint(0x1), photoLabel.PhotoID)
|
|
|
|
assert.Equal(t, uint(0x3), photoLabel.LabelID)
|
2020-04-19 01:13:55 +02:00
|
|
|
assert.Equal(t, 80, photoLabel.Uncertainty)
|
|
|
|
assert.Equal(t, "source", photoLabel.LabelSrc)
|
2019-07-16 13:10:31 +02:00
|
|
|
})
|
|
|
|
}
|
2019-12-17 18:28:07 +01:00
|
|
|
func TestPhotoLabel_TableName(t *testing.T) {
|
|
|
|
photoLabel := &PhotoLabel{}
|
|
|
|
tableName := photoLabel.TableName()
|
|
|
|
|
|
|
|
assert.Equal(t, "photos_labels", tableName)
|
|
|
|
}
|
2020-05-08 14:18:11 +02:00
|
|
|
|
|
|
|
func TestPhotoLabel_FirstOrCreate(t *testing.T) {
|
2020-05-10 19:43:49 +02:00
|
|
|
pl := LabelFixtures.PhotoLabel(1000000, "flower", 38, "image")
|
|
|
|
r := pl.FirstOrCreate()
|
|
|
|
assert.Equal(t, uint(1000000), r.PhotoID)
|
2020-05-08 14:18:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhotoLabel_ClassifyLabel(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
2020-05-10 19:43:49 +02:00
|
|
|
pl := LabelFixtures.PhotoLabel(1000000, "flower", 38, "image")
|
|
|
|
r := pl.ClassifyLabel()
|
2020-05-08 14:18:11 +02:00
|
|
|
assert.Equal(t, "Flower", r.Name)
|
|
|
|
assert.Equal(t, 38, r.Uncertainty)
|
|
|
|
assert.Equal(t, "image", r.Source)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("label = nil", func(t *testing.T) {
|
|
|
|
photoLabel := NewPhotoLabel(1, 3, 80, "source")
|
|
|
|
assert.Panics(t, func() {
|
|
|
|
|
|
|
|
photoLabel.ClassifyLabel()
|
|
|
|
|
|
|
|
}, "photo label: label is nil")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhotoLabel_Save(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
photoLabel := NewPhotoLabel(13, 1000, 99, "image")
|
|
|
|
err := photoLabel.Save()
|
|
|
|
if err != nil {
|
2020-05-08 19:34:29 +02:00
|
|
|
t.Fatal(err)
|
2020-05-08 14:18:11 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|