Backend: Add tests to pkg/internal/classify
This commit is contained in:
parent
8b79206de1
commit
6a171d88d0
3 changed files with 65 additions and 1 deletions
|
@ -29,3 +29,15 @@ func TestLabel_NewLocationLabel(t *testing.T) {
|
|||
assert.Equal(t, "locationtest", LocLabel.Name)
|
||||
})
|
||||
}
|
||||
|
||||
func TestLabel_Title(t *testing.T) {
|
||||
t.Run("locationtest123", func(t *testing.T) {
|
||||
LocLabel := LocationLabel("locationtest123", 23, 1)
|
||||
assert.Equal(t, "Locationtest123", LocLabel.Title())
|
||||
})
|
||||
|
||||
t.Run("Berlin/Neukölln", func(t *testing.T) {
|
||||
LocLabel := LocationLabel("berlin/neukölln_hasenheide", 23, 1)
|
||||
assert.Equal(t, "Berlin/Neukölln_hasenheide", LocLabel.Title())
|
||||
})
|
||||
}
|
||||
|
|
|
@ -82,13 +82,16 @@ func TestLabels_Title(t *testing.T) {
|
|||
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}
|
||||
bird := Label{Name: "bird", Source: "image", Uncertainty: 100, Priority: 2}
|
||||
labels := Labels{cat, dog, bird}
|
||||
|
||||
t.Run("labelWithName", func(t *testing.T) {
|
||||
result := labels.Keywords()
|
||||
t.Log(result)
|
||||
assert.Equal(t, "cat", result[0])
|
||||
assert.Equal(t, "animal", result[1])
|
||||
assert.Equal(t, "dog", result[2])
|
||||
assert.Equal(t, 3, len(result))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,21 @@ var resourcesPath = "../../assets/resources"
|
|||
var modelPath = resourcesPath + "/nasnet"
|
||||
var examplesPath = resourcesPath + "/examples"
|
||||
|
||||
func TestTensorFlow_Init(t *testing.T) {
|
||||
t.Run("disabled true", func(t *testing.T) {
|
||||
tensorFlow := New(resourcesPath, true)
|
||||
|
||||
result := tensorFlow.Init()
|
||||
assert.Nil(t, result)
|
||||
})
|
||||
t.Run("disabled false", func(t *testing.T) {
|
||||
tensorFlow := New(resourcesPath, false)
|
||||
|
||||
result := tensorFlow.Init()
|
||||
assert.Nil(t, result)
|
||||
})
|
||||
}
|
||||
|
||||
func TestTensorFlow_LabelsFromFile(t *testing.T) {
|
||||
t.Run("chameleon_lime.jpg", func(t *testing.T) {
|
||||
tensorFlow := New(resourcesPath, false)
|
||||
|
@ -43,6 +58,23 @@ func TestTensorFlow_LabelsFromFile(t *testing.T) {
|
|||
assert.Contains(t, err.Error(), "no such file or directory")
|
||||
assert.Empty(t, result)
|
||||
})
|
||||
t.Run("disabled true", func(t *testing.T) {
|
||||
tensorFlow := New(resourcesPath, true)
|
||||
|
||||
result, err := tensorFlow.File(examplesPath + "/chameleon_lime.jpg")
|
||||
assert.Nil(t, err)
|
||||
|
||||
if err != nil {
|
||||
t.Log(err.Error())
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
assert.Nil(t, result)
|
||||
assert.IsType(t, Labels{}, result)
|
||||
assert.Equal(t, 0, len(result))
|
||||
|
||||
t.Log(result)
|
||||
})
|
||||
}
|
||||
|
||||
func TestTensorFlow_Labels(t *testing.T) {
|
||||
|
@ -114,6 +146,23 @@ func TestTensorFlow_Labels(t *testing.T) {
|
|||
assert.Nil(t, err)
|
||||
}
|
||||
})
|
||||
t.Run("disabled true", func(t *testing.T) {
|
||||
tensorFlow := New(resourcesPath, true)
|
||||
|
||||
if imageBuffer, err := ioutil.ReadFile(examplesPath + "/dog_orange.jpg"); err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
result, err := tensorFlow.Labels(imageBuffer)
|
||||
|
||||
t.Log(result)
|
||||
|
||||
assert.Nil(t, result)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.IsType(t, Labels{}, result)
|
||||
assert.Equal(t, 0, len(result))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestTensorFlow_LoadModel(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue