doodle/pkg/collision/collide_test.go
Noah Petherbridge 1a8a5eb94b Polish and bugfixes
- Fix a memory sharing bug in the Giant Screenshot feature.
- Main Menu to eagerload chunks in the background to make scrolling less
  jittery. No time for a loadscreen!
- Extra script debugging: names/IDs of doodads are shown when they send
  messages to one another.
- Level Properties: you can edit the Bounded max width/height values for
  the level.

Doodad changes:

- Buttons: fix a timing bug and keep better track of who is stepping on it,
  only popping up when all colliders have left. The effect: they pop up
  immediately (not after 200ms) and are more reliable.
- Keys: zero-qty keys will no longer put themselves into the inventory of
  characters who already have one except for the player character. So
  the Thief will not steal them if she already has the key.

Added to the JavaScript API:

* time.Hour, time.Minute, time.Second, time.Millisecond, time.Microsecond
2021-10-09 20:45:38 -07:00

59 lines
994 B
Go

package collision_test
import (
"testing"
"git.kirsle.net/apps/doodle/pkg/collision"
"git.kirsle.net/go/render"
)
func TestBetweenBoxes(t *testing.T) {
mkrect := func(x, y, w, h int) render.Rect {
return render.Rect{
X: x,
Y: y,
W: w,
H: h,
}
}
table := []struct {
A render.Rect
B render.Rect
Expect bool
}{
{
A: mkrect(0, 0, 32, 32),
B: mkrect(32, 0, 32, 32),
Expect: true,
},
{
A: mkrect(0, 0, 32, 32),
B: mkrect(100, 100, 40, 40),
Expect: false,
},
{
A: mkrect(100, 100, 50, 50),
B: mkrect(80, 110, 100, 30),
Expect: true,
},
}
var actual bool
for i, test := range table {
actual = false
for range collision.BetweenBoxes([]render.Rect{test.A, test.B}) {
actual = true
break
}
if test.Expect != actual {
t.Errorf(
"Test %d BetweenBoxes: %s cmp %s\n"+
"Expected: %+v\n"+
"Actually: %+v",
i, test.A, test.B, test.Expect, actual,
)
}
}
}