diff --git a/internal/classify/label_test.go b/internal/classify/label_test.go index baafa0641..cc040c6b8 100644 --- a/internal/classify/label_test.go +++ b/internal/classify/label_test.go @@ -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()) + }) +} diff --git a/internal/classify/labels_test.go b/internal/classify/labels_test.go index 6abdebdea..26fef7d3f 100644 --- a/internal/classify/labels_test.go +++ b/internal/classify/labels_test.go @@ -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)) }) } diff --git a/internal/classify/tensorflow_test.go b/internal/classify/tensorflow_test.go index 2f019f303..3c671523c 100644 --- a/internal/classify/tensorflow_test.go +++ b/internal/classify/tensorflow_test.go @@ -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) {