(t *testing.T)
| 13 | } |
| 14 | |
| 15 | func TestFindDistanceBetweenTwoPoints(t *testing.T) { |
| 16 | tests := []struct { |
| 17 | name string |
| 18 | args args |
| 19 | want float64 |
| 20 | wantErr bool |
| 21 | }{ |
| 22 | { |
| 23 | "(0,0) and (2,-2)", |
| 24 | args{ |
| 25 | geometry.EuclideanPoint{0, 0}, |
| 26 | geometry.EuclideanPoint{2, -2}, |
| 27 | }, |
| 28 | 2.8284271247461903, |
| 29 | false, |
| 30 | }, |
| 31 | { |
| 32 | "(-20,23) and (-15,68)", |
| 33 | args{ |
| 34 | geometry.EuclideanPoint{-20, 23}, |
| 35 | geometry.EuclideanPoint{-15, 68}, |
| 36 | }, |
| 37 | 45.27692569068709, |
| 38 | false, |
| 39 | }, |
| 40 | { |
| 41 | "(2,2) and (14,11)", |
| 42 | args{ |
| 43 | geometry.EuclideanPoint{2, 2}, |
| 44 | geometry.EuclideanPoint{14, 11}, |
| 45 | }, |
| 46 | 15, |
| 47 | false, |
| 48 | }, |
| 49 | { |
| 50 | "Return error for mismatched dimensions(2,2) and ()", |
| 51 | args{ |
| 52 | geometry.EuclideanPoint{2, 2}, |
| 53 | geometry.EuclideanPoint{}, |
| 54 | }, |
| 55 | -1, |
| 56 | true, |
| 57 | }, |
| 58 | } |
| 59 | for _, tt := range tests { |
| 60 | t.Run(tt.name, func(t *testing.T) { |
| 61 | got, err := geometry.EuclideanDistance(tt.args.p1, tt.args.p2) |
| 62 | if (err != nil) != tt.wantErr && errors.Is(err, geometry.ErrDimMismatch) { |
| 63 | t.Errorf("EuclideanDistance() error = %v, wantErr %v", err, tt.wantErr) |
| 64 | return |
| 65 | } |
| 66 | if got != tt.want { |
| 67 | t.Errorf("EuclideanDistance() = %v, want %v", got, tt.want) |
| 68 | } |
| 69 | }) |
| 70 | } |
| 71 | } |
| 72 |
nothing calls this directly
no test coverage detected