TestDistance tests the Function Distance with 2 vectors
(t *testing.T)
| 20 | |
| 21 | // TestDistance tests the Function Distance with 2 vectors |
| 22 | func TestDistance(t *testing.T) { |
| 23 | t.Parallel() // marks TestDistance as capable of running in parallel with other tests |
| 24 | for _, tt := range distanceTest { |
| 25 | tt := tt // NOTE: https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables |
| 26 | t.Run(tt.name, func(t *testing.T) { |
| 27 | t.Parallel() |
| 28 | res := Distance(tt.v1, tt.v2) // Calculate result for |
| 29 | roundRes := (math.Floor(res*100) / 100) // Round to 2 decimal places because we can't compare an infinite number of places |
| 30 | // Check result |
| 31 | if roundRes != tt.res { |
| 32 | t.Errorf("Distance(%v, %v) = %f, expected %f", |
| 33 | tt.v1, tt.v2, roundRes, tt.res) |
| 34 | } |
| 35 | }) |
| 36 | } |
| 37 | } |
nothing calls this directly
no test coverage detected