/
object_detection_test.go
53 lines (47 loc) · 1.01 KB
/
object_detection_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package hfapigo_test
import (
"testing"
"time"
"github.com/Kardbord/hfapigo/v2"
)
func TestObjectDetectionRequest(t *testing.T) {
const retries = 10
resps := []*hfapigo.ObjectDetectionResponse{}
var err error
for i := 0; i < retries; i++ {
resps, err = hfapigo.SendObjectDetectionRequest(hfapigo.RecommendedObjectDetectionModel, TestFilesDir+"/test-image.png")
if err == nil {
break
} else {
time.Sleep(time.Second * 5)
}
}
if err != nil {
t.Fatal(err)
}
if len(resps) == 0 {
t.Fatal("Expected non-empty response")
}
for _, resp := range resps {
if resp == nil {
t.Fatal("nil response received")
}
if resp.Score == 0.0 {
t.Fatal("Expected non-zero score")
}
if resp.Label == "" {
t.Fatal("Expected non-empty label")
}
if equal(resp.Box.XMin, resp.Box.XMax, resp.Box.YMin, resp.Box.YMax) {
t.Fatal("expected non-equal coordinates")
}
}
}
func equal(nums ...int) bool {
for i := 1; i < len(nums); i++ {
if nums[i] != nums[0] {
return false
}
}
return true
}