test dw distances

This commit is contained in:
Ilia Denisov
2025-09-23 23:33:47 +03:00
parent 7d93176031
commit ab822a1abf
7 changed files with 75 additions and 35 deletions
+27
View File
@@ -0,0 +1,27 @@
package generator
import (
"fmt"
"testing"
"github.com/iliadenisov/galaxy/pkg/number"
"github.com/stretchr/testify/assert"
)
func TestShortDistance(t *testing.T) {
for i, tc := range []struct {
w, h uint32
x1, y1, x2, y2, d float64
}{
{10, 10, 0, 0, 5, 5, 7.071},
{10, 10, 0, 0, 5.01, 5.01, 7.057},
{10, 10, 2, 2, 8, 2, 4.},
{10, 10, 8, 7, 1, 7, 3.},
} {
t.Run(fmt.Sprint(i), func(t *testing.T) {
m := Map{Width: tc.w, Height: tc.h}
d := m.ShortDistance(Coordinate{tc.x1, tc.y1}, Coordinate{tc.x2, tc.y2})
assert.Equal(t, tc.d, number.Fixed3(d))
})
}
}