2016-08-26 11:37:18 -07:00
|
|
|
package rect
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDistance(t *testing.T) {
|
|
|
|
var distanceTest = []struct {
|
|
|
|
p []Point
|
|
|
|
expected float64
|
|
|
|
}{
|
|
|
|
{[]Point{Point{1, 1}, Point{4, 5}}, 5},
|
|
|
|
{[]Point{Point{-1, -1}, Point{2, 3}}, 5},
|
|
|
|
{[]Point{Point{1, 1}, Point{2, 2}}, math.Sqrt(2)},
|
|
|
|
{[]Point{Point{1, 1}, Point{40, 20}}, math.Sqrt(1882)},
|
|
|
|
}
|
|
|
|
for _, rt := range distanceTest {
|
|
|
|
actual := distance(rt.p[0], rt.p[1])
|
|
|
|
if actual != rt.expected {
|
|
|
|
t.Errorf(
|
2016-08-27 19:08:51 -07:00
|
|
|
"failed distance:\n\texpected: %f\n\t actual: %f",
|
2016-08-26 11:37:18 -07:00
|
|
|
rt.expected,
|
|
|
|
actual,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|