frechet_test.go 694 B

123456789101112131415161718192021222324252627282930313233
  1. package frechet
  2. import (
  3. "testing"
  4. )
  5. func TestFrechet(t *testing.T) {
  6. curve1 := []Point{Point{X: 0, Y: 0}, Point{X: 1, Y: 1}, Point{X: 2, Y: 2}}
  7. curve2 := []Point{Point{X: 0, Y: 1}, Point{X: 1, Y: 2}, Point{X: 2, Y: 3}}
  8. dist := Frechet(curve1, curve2)
  9. if dist != 1.0 {
  10. t.Fatalf("%v != 1.0", dist)
  11. }
  12. }
  13. func BenchmarkFrechet(b *testing.B) {
  14. curve1 := []Point{}
  15. curve2 := []Point{}
  16. for i := 0; i < 1000; i++ {
  17. curve1 = append(curve1, Point{X: float64(i), Y: float64(i)})
  18. curve2 = append(curve2, Point{X: float64(i), Y: float64(i + 1)})
  19. }
  20. b.ResetTimer()
  21. for i := 0; i < b.N; i++ {
  22. dist := Frechet(curve1, curve2)
  23. if dist != 1.0 {
  24. b.Fatalf("%v != 1.0", dist)
  25. }
  26. }
  27. }