test for math2d and wave
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package game
|
||||
|
||||
import "core:math"
|
||||
import "core:testing"
|
||||
|
||||
@(test)
|
||||
test_distance :: proc(t: ^testing.T) {
|
||||
a := Vec2 {
|
||||
x = 3,
|
||||
y = 2,
|
||||
}
|
||||
b := Vec2 {
|
||||
x = 1,
|
||||
y = 2,
|
||||
}
|
||||
|
||||
d := distance(a, b)
|
||||
|
||||
testing.expect(t, math.abs(d - 2.0) < 0.0001)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_move_toward_already_close :: proc(t: ^testing.T) {
|
||||
pos := Vec2{0.5, 0}
|
||||
target := Vec2{0, 0}
|
||||
|
||||
move_toward(&pos, target, 10, 1.0)
|
||||
|
||||
testing.expect(t, math.abs(pos.x - 0.5) < 0.0001)
|
||||
testing.expect(t, math.abs(pos.y - 0.0) < 0.0001)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_move_toward_reaches_target :: proc(t: ^testing.T) {
|
||||
pos := Vec2{0, 0}
|
||||
target := Vec2{3, 4}
|
||||
|
||||
move_toward(&pos, target, 100, 1.0)
|
||||
|
||||
testing.expect(t, math.abs(pos.x - 3) < 0.0001)
|
||||
testing.expect(t, math.abs(pos.y - 4) < 0.0001)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_move_toward_partial :: proc(t: ^testing.T) {
|
||||
pos := Vec2{0, 0}
|
||||
target := Vec2{10, 0}
|
||||
|
||||
move_toward(&pos, target, 2, 1.0)
|
||||
|
||||
testing.expect(t, math.abs(pos.x - 2) < 0.0001)
|
||||
testing.expect(t, math.abs(pos.y) < 0.0001)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_move_toward_diagonal :: proc(t: ^testing.T) {
|
||||
pos := Vec2{0, 0}
|
||||
target := Vec2{3, 4}
|
||||
|
||||
move_toward(&pos, target, 5, 0.5)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user