You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main_test.go 1.1KB

12345678910111213141516171819202122232425262728293031323334
  1. package main
  2. import (
  3. "math"
  4. "testing"
  5. )
  6. func Test_angleBetween(t *testing.T) {
  7. type args struct {
  8. asteroid1 *asteroid
  9. asteroid2 *asteroid
  10. }
  11. tests := []struct {
  12. name string
  13. args args
  14. want float64
  15. }{
  16. {"above", args{&asteroid{x: 5, y: 5}, &asteroid{x: 5, y: 0}}, 0},
  17. {"below", args{&asteroid{x: 5, y: 5}, &asteroid{x: 5, y: 10}}, math.Pi},
  18. {"right", args{&asteroid{x: 5, y: 5}, &asteroid{x: 10, y: 5}}, math.Pi / 2},
  19. {"left", args{&asteroid{x: 5, y: 5}, &asteroid{x: 0, y: 5}}, 3 * math.Pi / 2},
  20. {"quadrant1", args{&asteroid{x: 5, y: 5}, &asteroid{x: 10, y: 0}}, math.Pi / 4},
  21. {"quadrant2", args{&asteroid{x: 5, y: 5}, &asteroid{x: 10, y: 10}}, 3 * math.Pi / 4},
  22. {"quadrant3", args{&asteroid{x: 5, y: 5}, &asteroid{x: 0, y: 10}}, 5 * math.Pi / 4},
  23. {"quadrant4", args{&asteroid{x: 5, y: 5}, &asteroid{x: 0, y: 0}}, 7 * math.Pi / 4},
  24. }
  25. for _, tt := range tests {
  26. t.Run(tt.name, func(t *testing.T) {
  27. if got := angleBetween(tt.args.asteroid1, tt.args.asteroid2); got != tt.want {
  28. t.Errorf("angleBetween() = %v, want %v", got, tt.want)
  29. }
  30. })
  31. }
  32. }