add more tests
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package engine
|
||||
|
||||
import "core:testing"
|
||||
import sdl "vendor:sdl3"
|
||||
|
||||
fake_tex :: proc(id: uintptr) -> ^sdl.GPUTexture {
|
||||
return cast(^sdl.GPUTexture)id
|
||||
}
|
||||
|
||||
@(test)
|
||||
texture_run_len_empty_or_oob :: proc(t: ^testing.T) {
|
||||
testing.expect_value(t, texture_run_len(nil, 0), 0)
|
||||
list := []Queued_Sprite{}
|
||||
testing.expect_value(t, texture_run_len(list, 0), 0)
|
||||
list = make([]Queued_Sprite, 1)
|
||||
defer delete(list)
|
||||
list[0] = {texture = fake_tex(1)}
|
||||
testing.expect_value(t, texture_run_len(list, -1), 0)
|
||||
testing.expect_value(t, texture_run_len(list, 1), 0)
|
||||
}
|
||||
|
||||
@(test)
|
||||
texture_run_len_single :: proc(t: ^testing.T) {
|
||||
list := make([]Queued_Sprite, 1)
|
||||
defer delete(list)
|
||||
list[0] = {texture = fake_tex(1)}
|
||||
testing.expect_value(t, texture_run_len(list, 0), 1)
|
||||
}
|
||||
|
||||
@(test)
|
||||
texture_run_len_same_texture :: proc(t: ^testing.T) {
|
||||
tex := fake_tex(1)
|
||||
list := make([]Queued_Sprite, 3)
|
||||
defer delete(list)
|
||||
list[0] = {texture = tex}
|
||||
list[1] = {texture = tex}
|
||||
list[2] = {texture = tex}
|
||||
testing.expect_value(t, texture_run_len(list, 0), 3)
|
||||
}
|
||||
|
||||
@(test)
|
||||
texture_run_len_breaks_on_change :: proc(t: ^testing.T) {
|
||||
a := fake_tex(1)
|
||||
b := fake_tex(2)
|
||||
list := make([]Queued_Sprite, 3)
|
||||
defer delete(list)
|
||||
list[0] = {texture = a}
|
||||
list[1] = {texture = a}
|
||||
list[2] = {texture = b}
|
||||
testing.expect_value(t, texture_run_len(list, 0), 2)
|
||||
testing.expect_value(t, texture_run_len(list, 2), 1)
|
||||
}
|
||||
|
||||
@(test)
|
||||
texture_run_len_all_different :: proc(t: ^testing.T) {
|
||||
list := make([]Queued_Sprite, 3)
|
||||
defer delete(list)
|
||||
list[0] = {texture = fake_tex(1)}
|
||||
list[1] = {texture = fake_tex(2)}
|
||||
list[2] = {texture = fake_tex(3)}
|
||||
testing.expect_value(t, texture_run_len(list, 0), 1)
|
||||
testing.expect_value(t, texture_run_len(list, 1), 1)
|
||||
testing.expect_value(t, texture_run_len(list, 2), 1)
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package engine
|
||||
|
||||
import "core:testing"
|
||||
|
||||
@(test)
|
||||
camera_default_values :: proc(t: ^testing.T) {
|
||||
cam := camera_default()
|
||||
testing.expect_value(t, cam.position, Vec2{0, 0})
|
||||
testing.expect_value(t, cam.anchor, Vec2{0.5, 0.5})
|
||||
}
|
||||
|
||||
@(test)
|
||||
world_to_screen_centered_identity :: proc(t: ^testing.T) {
|
||||
cam := Camera {
|
||||
position = {400, 500},
|
||||
anchor = {0.5, 0.5},
|
||||
}
|
||||
viewport := Vec2{800, 600}
|
||||
screen := world_to_screen(cam, cam.position, viewport)
|
||||
testing.expect_value(t, screen.x, f32(400))
|
||||
testing.expect_value(t, screen.y, f32(300))
|
||||
}
|
||||
|
||||
@(test)
|
||||
world_to_screen_origin_cam :: proc(t: ^testing.T) {
|
||||
cam := Camera {
|
||||
position = {0, 0},
|
||||
anchor = {0.5, 0.5},
|
||||
}
|
||||
screen := world_to_screen(cam, {10, 20}, {200, 100})
|
||||
testing.expect_value(t, screen.x, f32(110))
|
||||
testing.expect_value(t, screen.y, f32(70))
|
||||
}
|
||||
|
||||
@(test)
|
||||
world_to_screen_top_left_anchor :: proc(t: ^testing.T) {
|
||||
cam := Camera {
|
||||
position = {5, 7},
|
||||
anchor = {0, 0},
|
||||
}
|
||||
screen := world_to_screen(cam, {15, 27}, {800, 600})
|
||||
testing.expect_value(t, screen.x, f32(10))
|
||||
testing.expect_value(t, screen.y, f32(20))
|
||||
}
|
||||
@@ -64,6 +64,55 @@ character_frame_rect_hit_and_miss :: proc(t: ^testing.T) {
|
||||
testing.expect(t, !ok)
|
||||
}
|
||||
|
||||
@(test)
|
||||
character_frame_returns_full_def :: proc(t: ^testing.T) {
|
||||
data: Character_Data
|
||||
data.def.clips = make(map[string]Clip_Def)
|
||||
defer delete(data.def.clips)
|
||||
|
||||
frames := make([]Frame_Def, 1)
|
||||
frames[0] = Frame_Def {
|
||||
rect = {10, 20, 30, 40},
|
||||
source_size = {100, 200},
|
||||
trim_offset = {5, 7},
|
||||
}
|
||||
defer delete(frames)
|
||||
|
||||
data.def.clips["idle"] = Clip_Def {
|
||||
loop = true,
|
||||
fps = 10,
|
||||
frames = frames,
|
||||
}
|
||||
|
||||
frame, ok := character_frame(&data, "idle", 0)
|
||||
testing.expect(t, ok)
|
||||
testing.expect_value(t, frame.rect, [4]int{10, 20, 30, 40})
|
||||
testing.expect_value(t, frame.source_size, [2]int{100, 200})
|
||||
testing.expect_value(t, frame.trim_offset, [2]int{5, 7})
|
||||
}
|
||||
|
||||
@(test)
|
||||
character_frame_nil_and_bad_index :: proc(t: ^testing.T) {
|
||||
_, ok := character_frame(nil, "idle", 0)
|
||||
testing.expect(t, !ok)
|
||||
|
||||
data: Character_Data
|
||||
data.def.clips = make(map[string]Clip_Def)
|
||||
defer delete(data.def.clips)
|
||||
|
||||
frames := make([]Frame_Def, 1)
|
||||
frames[0] = {rect = {1, 2, 3, 4}}
|
||||
defer delete(frames)
|
||||
data.def.clips["idle"] = Clip_Def{frames = frames}
|
||||
|
||||
_, ok = character_frame(&data, "idle", -1)
|
||||
testing.expect(t, !ok)
|
||||
_, ok = character_frame(&data, "idle", 1)
|
||||
testing.expect(t, !ok)
|
||||
_, ok = character_frame(&data, "missing", 0)
|
||||
testing.expect(t, !ok)
|
||||
}
|
||||
|
||||
destroy_char_def :: proc(def: ^Char_Def) {
|
||||
if def == nil do return
|
||||
|
||||
|
||||
@@ -33,3 +33,59 @@ sprite_quad_origin_center :: proc(t: ^testing.T) {
|
||||
testing.expect_value(t, o.x, f32(350))
|
||||
testing.expect_value(t, o.y, f32(400))
|
||||
}
|
||||
|
||||
@(test)
|
||||
frame_uvs_unflipped :: proc(t: ^testing.T) {
|
||||
u0, v0, u1, v1 := frame_uvs({10, 20, 30, 40}, 100, 200, false)
|
||||
testing.expect_value(t, u0, f32(0.1))
|
||||
testing.expect_value(t, v0, f32(0.1))
|
||||
testing.expect_value(t, u1, f32(0.4))
|
||||
testing.expect_value(t, v1, f32(0.3))
|
||||
testing.expect(t, u0 < u1)
|
||||
}
|
||||
|
||||
@(test)
|
||||
frame_uvs_flipped :: proc(t: ^testing.T) {
|
||||
a0, _, a1, _ := frame_uvs({10, 20, 30, 40}, 100, 200, false)
|
||||
b0, v0, b1, v1 := frame_uvs({10, 20, 30, 40}, 100, 200, true)
|
||||
testing.expect_value(t, b0, a1)
|
||||
testing.expect_value(t, b1, a0)
|
||||
testing.expect_value(t, v0, f32(0.1))
|
||||
testing.expect_value(t, v1, f32(0.3))
|
||||
}
|
||||
|
||||
@(test)
|
||||
sprite_feet_quad_no_flip :: proc(t: ^testing.T) {
|
||||
// feet (400,500), source 100x200, pivot feet, trim (10,20), packed 80x160
|
||||
x0, y0, x1, y1 := sprite_feet_quad(
|
||||
{400, 500},
|
||||
100,
|
||||
200,
|
||||
{10, 20},
|
||||
{80, 160},
|
||||
{0.5, 1.0},
|
||||
false,
|
||||
)
|
||||
testing.expect_value(t, x0, f32(360)) // 400 - 50 + 10
|
||||
testing.expect_value(t, y0, f32(320)) // 500 - 200 + 20
|
||||
testing.expect_value(t, x1, f32(440))
|
||||
testing.expect_value(t, y1, f32(480))
|
||||
}
|
||||
|
||||
@(test)
|
||||
sprite_feet_quad_flip_x :: proc(t: ^testing.T) {
|
||||
x0, y0, x1, y1 := sprite_feet_quad(
|
||||
{400, 500},
|
||||
100,
|
||||
200,
|
||||
{5, 20},
|
||||
{80, 160},
|
||||
{0.5, 1.0},
|
||||
true,
|
||||
)
|
||||
// canvas_left = 350; trim_x_draw = 100 - 5 - 80 = 15 → x0 = 365
|
||||
testing.expect_value(t, x0, f32(365))
|
||||
testing.expect_value(t, y0, f32(320))
|
||||
testing.expect_value(t, x1, f32(445))
|
||||
testing.expect_value(t, y1, f32(480))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user