MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / TestDistance

Function TestDistance

math/pythagoras/pythagoras_test.go:22–37  ·  view source on GitHub ↗

TestDistance tests the Function Distance with 2 vectors

(t *testing.T)

Source from the content-addressed store, hash-verified

20
21// TestDistance tests the Function Distance with 2 vectors
22func 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}

Callers

nothing calls this directly

Calls 1

DistanceFunction · 0.70

Tested by

no test coverage detected