2020-07-08 10:03:59 +02:00
|
|
|
package meta
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
2020-11-21 18:08:41 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-07-08 10:03:59 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestData_AspectRatio(t *testing.T) {
|
|
|
|
t.Run("valid", func(t *testing.T) {
|
|
|
|
data := Data{
|
|
|
|
DocumentID: "123",
|
|
|
|
InstanceID: "456",
|
|
|
|
TakenAt: time.Time{},
|
|
|
|
TakenAtLocal: time.Time{},
|
|
|
|
TimeZone: "UTC",
|
|
|
|
Codec: "avc1",
|
|
|
|
Lat: 1.334,
|
|
|
|
Lng: 44.567,
|
|
|
|
Altitude: 5,
|
|
|
|
Width: 500,
|
|
|
|
Height: 600,
|
|
|
|
Error: nil,
|
|
|
|
All: nil,
|
|
|
|
}
|
|
|
|
|
2020-07-20 19:48:31 +02:00
|
|
|
assert.Equal(t, float32(0.83), data.AspectRatio())
|
2020-07-08 10:03:59 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("invalid", func(t *testing.T) {
|
|
|
|
data := Data{
|
|
|
|
DocumentID: "123",
|
|
|
|
InstanceID: "456",
|
|
|
|
TakenAt: time.Time{},
|
|
|
|
TakenAtLocal: time.Time{},
|
|
|
|
TimeZone: "UTC",
|
|
|
|
Codec: "avc1",
|
|
|
|
Lat: 1.334,
|
|
|
|
Lng: 44.567,
|
|
|
|
Altitude: 5,
|
|
|
|
Width: 0,
|
|
|
|
Height: 600,
|
|
|
|
Error: nil,
|
|
|
|
All: nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, float32(0), data.AspectRatio())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestData_Portrait(t *testing.T) {
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
data := Data{
|
|
|
|
Width: 500,
|
|
|
|
Height: 600,
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, true, data.Portrait())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
data := Data{
|
|
|
|
Width: 800,
|
|
|
|
Height: 600,
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, false, data.Portrait())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestData_Megapixels(t *testing.T) {
|
|
|
|
t.Run("30 MP", func(t *testing.T) {
|
|
|
|
data := Data{
|
|
|
|
Width: 5000,
|
|
|
|
Height: 6000,
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, 30, data.Megapixels())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestData_HasDocumentID(t *testing.T) {
|
2020-07-23 15:34:20 +02:00
|
|
|
t.Run("6ba7b810-9dad-11d1-80b4-00c04fd430c8", func(t *testing.T) {
|
2020-07-08 10:03:59 +02:00
|
|
|
data := Data{
|
2020-07-23 15:34:20 +02:00
|
|
|
DocumentID: "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
|
2020-07-08 10:03:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, true, data.HasDocumentID())
|
|
|
|
})
|
|
|
|
|
2020-07-23 15:34:20 +02:00
|
|
|
t.Run("asdfg12345hjyt6", func(t *testing.T) {
|
|
|
|
data := Data{
|
|
|
|
DocumentID: "asdfg12345hjyt6",
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, false, data.HasDocumentID())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("asdfg12345hj", func(t *testing.T) {
|
2020-07-08 10:03:59 +02:00
|
|
|
data := Data{
|
|
|
|
DocumentID: "asdfg12345hj",
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, false, data.HasDocumentID())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestData_HasInstanceID(t *testing.T) {
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
data := Data{
|
2020-07-23 15:34:20 +02:00
|
|
|
InstanceID: "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
|
2020-07-08 10:03:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, true, data.HasInstanceID())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
data := Data{
|
|
|
|
InstanceID: "asdfg12345hj",
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, false, data.HasInstanceID())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestData_HasTimeAndPlace(t *testing.T) {
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
data := Data{
|
|
|
|
Lat: 1.334,
|
|
|
|
Lng: 4.567,
|
|
|
|
TakenAt: time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC),
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, true, data.HasTimeAndPlace())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
data := Data{
|
|
|
|
Lat: 1.334,
|
|
|
|
Lng: 0,
|
|
|
|
TakenAt: time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC),
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, false, data.HasTimeAndPlace())
|
|
|
|
})
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
data := Data{
|
|
|
|
Lat: 0,
|
|
|
|
Lng: 4.567,
|
|
|
|
TakenAt: time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC),
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, false, data.HasTimeAndPlace())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
data := Data{
|
|
|
|
Lat: 1.334,
|
|
|
|
Lng: 4.567,
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, false, data.HasTimeAndPlace())
|
|
|
|
})
|
|
|
|
}
|
2021-02-25 16:03:07 +01:00
|
|
|
|
|
|
|
func TestData_CellID(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
data := Data{
|
|
|
|
Lat: 1.334,
|
|
|
|
Lng: 4.567,
|
|
|
|
TakenAt: time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC),
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "s2:100c9acde614", data.CellID())
|
|
|
|
})
|
|
|
|
}
|