From 091e1e639bb09568375c5b77a60b333d2f506c38 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Sat, 9 Aug 2025 04:45:40 +0200 Subject: Cleaned up testing files --- tests/graphics.lua | 132 ----------------------------------------------- tests/json.lua | 10 ---- tests/test.lua | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+), 142 deletions(-) delete mode 100644 tests/graphics.lua delete mode 100644 tests/json.lua create mode 100644 tests/test.lua (limited to 'tests') diff --git a/tests/graphics.lua b/tests/graphics.lua deleted file mode 100644 index 1322101..0000000 --- a/tests/graphics.lua +++ /dev/null @@ -1,132 +0,0 @@ -math.randomseed(os.time()) - -test_button_square = { x = 400, y = 400 } -test_button_color = color.RED -test_button_speed = 200 - -test_camera_position = { x = 0, y = 0 } -test_camera_speed = 200 - -test_images_asset1 = load_image("tests/icons/icon_1.png") - -open_window(800, 800, "Sample Window") -set_fps(60) - -function test_api() - draw_rect(100, 100, 300, 200, color.YELLOW) - draw_text("Label text", 10, 10, 20, color.VIOLET) - draw_line(400, 10, 500, 100, color.RED) - draw_circle(500, 500, 100, color.BLUE) - draw_ellipse(200, 500, 100, 50, color.BLUE) - draw_triangle(20, 20, 100, 20, 50, 100, color.BLUE) - draw_text(string.format("fps: %d", get_fps()), 10, 30, 20, color.VIOLET) - draw_text(string.format("dt: %.3f", get_dt()), 10, 50, 20, color.VIOLET) -end - -function get_random_color() - local keys = {} - for k in pairs(color) do - table.insert(keys, k) -- Collect all keys - end - local randomKey = keys[math.random(1, #keys)] -- Select a random key - return color[randomKey] -- Return the corresponding color -end - -function test_buttons() - -- Testing button presses. - if button_down(button.PAD_UP) then - draw_text("Pad Up", 10, 10, 20, color.VIOLET) - end - - if button_down(button.PAD_DOWN) then - draw_text("Pad Down", 10, 40, 20, color.VIOLET) - end - - if button_down(button.PAD_LEFT) then - draw_text("Pad Left", 10, 70, 20, color.VIOLET) - end - - if button_down(button.PAD_RIGHT) then - draw_text("Pad Right", 10, 100, 20, color.VIOLET) - end - - if button_down(button.A) then - draw_text("A", 150, 10, 20, color.VIOLET) - end - - if button_down(button.B) then - draw_text("B", 150, 40, 20, color.VIOLET) - end - - if button_down(button.X) then - draw_text("X", 150, 70, 20, color.VIOLET) - end - - if button_down(button.Y) then - draw_text("Y", 150, 100, 20, color.VIOLET) - end - - -- Moving square around. - if button_down(button.PAD_UP) then - test_button_square.y = test_button_square.y - (test_button_speed * get_dt()) - end - - if button_down(button.PAD_DOWN) then - test_button_square.y = test_button_square.y + (test_button_speed * get_dt()) - end - - if button_down(button.PAD_LEFT) then - test_button_square.x = test_button_square.x - (test_button_speed * get_dt()) - end - - if button_down(button.PAD_RIGHT) then - test_button_square.x = test_button_square.x + (test_button_speed * get_dt()) - end - - if button_pressed(button.A) then - test_button_color = get_random_color() - end - - draw_rect(test_button_square.x, test_button_square.y, 50, 50, test_button_color) -end - -function test_camera() - if button_down(button.PAD_UP) then - test_camera_position.y = test_camera_position.y - (test_camera_speed * get_dt()) - end - - if button_down(button.PAD_DOWN) then - test_camera_position.y = test_camera_position.y + (test_camera_speed * get_dt()) - end - - if button_down(button.PAD_LEFT) then - test_camera_position.x = test_camera_position.x - (test_camera_speed * get_dt()) - end - - if button_down(button.PAD_RIGHT) then - test_camera_position.x = test_camera_position.x + (test_camera_speed * get_dt()) - end - - -- Using camera - move_camera(test_camera_position.x, test_camera_position.y) - - start_camera() - draw_rect(0, 0, 300, 200, color.YELLOW) - stop_camera() - - draw_text("This text doesn't move!", 10, 10, 20, color.VIOLET) -end - -while window_running() do - start_drawing() - clear_window(color.BLACK) - - -- test_api() - -- test_buttons() - -- test_camera() - - draw_info() - stop_drawing() -end - -close_window() diff --git a/tests/json.lua b/tests/json.lua deleted file mode 100644 index a659889..0000000 --- a/tests/json.lua +++ /dev/null @@ -1,10 +0,0 @@ -local file = io.open("tests/test.json", "r") -local content = file:read("*a") -file:close() - -local data = json.decode(content) - -print("name: " .. data.name) -for _, n in pairs(data.numbers) do - print(" - number: " .. n) -end diff --git a/tests/test.lua b/tests/test.lua new file mode 100644 index 0000000..74bf797 --- /dev/null +++ b/tests/test.lua @@ -0,0 +1,148 @@ +math.randomseed(os.time()) + +test_button_square = { x = 400, y = 400 } +test_button_color = color.RED +test_button_speed = 200 + +test_camera_position = { x = 0, y = 0 } +test_camera_speed = 200 + +test_images_asset1 = load_image("tests/icons/icon_1.png") + +open_window(800, 800, "Sample Window") +set_fps(60) + +function test_api() + draw_rect(100, 100, 300, 200, color.YELLOW) + draw_text("Label text", 10, 10, 20, color.VIOLET) + draw_line(400, 10, 500, 100, color.RED) + draw_circle(500, 500, 100, color.BLUE) + draw_ellipse(200, 500, 100, 50, color.BLUE) + draw_triangle(20, 20, 100, 20, 50, 100, color.BLUE) + draw_text(string.format("fps: %d", get_fps()), 10, 30, 20, color.VIOLET) + draw_text(string.format("dt: %.3f", get_dt()), 10, 50, 20, color.VIOLET) +end + +function get_random_color() + local keys = {} + for k in pairs(color) do + table.insert(keys, k) -- Collect all keys + end + local randomKey = keys[math.random(1, #keys)] -- Select a random key + return color[randomKey] -- Return the corresponding color +end + +function test_json() + local file = io.open("tests/test.json", "r") + local content = file:read("*a") + file:close() + + local data = json.decode(content) + + print("name: " .. data.name) + for _, n in pairs(data.numbers) do + print(" - number: " .. n) + end +end + +function test_buttons() + -- Testing button presses. + if button_down(button.PAD_UP) then + draw_text("Pad Up", 10, 10, 20, color.VIOLET) + end + + if button_down(button.PAD_DOWN) then + draw_text("Pad Down", 10, 40, 20, color.VIOLET) + end + + if button_down(button.PAD_LEFT) then + draw_text("Pad Left", 10, 70, 20, color.VIOLET) + end + + if button_down(button.PAD_RIGHT) then + draw_text("Pad Right", 10, 100, 20, color.VIOLET) + end + + if button_down(button.A) then + draw_text("A", 150, 10, 20, color.VIOLET) + end + + if button_down(button.B) then + draw_text("B", 150, 40, 20, color.VIOLET) + end + + if button_down(button.X) then + draw_text("X", 150, 70, 20, color.VIOLET) + end + + if button_down(button.Y) then + draw_text("Y", 150, 100, 20, color.VIOLET) + end + + -- Moving square around. + if button_down(button.PAD_UP) then + test_button_square.y = test_button_square.y - (test_button_speed * get_dt()) + end + + if button_down(button.PAD_DOWN) then + test_button_square.y = test_button_square.y + (test_button_speed * get_dt()) + end + + if button_down(button.PAD_LEFT) then + test_button_square.x = test_button_square.x - (test_button_speed * get_dt()) + end + + if button_down(button.PAD_RIGHT) then + test_button_square.x = test_button_square.x + (test_button_speed * get_dt()) + end + + if button_pressed(button.A) then + test_button_color = get_random_color() + end + + draw_rect(test_button_square.x, test_button_square.y, 50, 50, test_button_color) +end + +function test_camera() + if button_down(button.PAD_UP) then + test_camera_position.y = test_camera_position.y - (test_camera_speed * get_dt()) + end + + if button_down(button.PAD_DOWN) then + test_camera_position.y = test_camera_position.y + (test_camera_speed * get_dt()) + end + + if button_down(button.PAD_LEFT) then + test_camera_position.x = test_camera_position.x - (test_camera_speed * get_dt()) + end + + if button_down(button.PAD_RIGHT) then + test_camera_position.x = test_camera_position.x + (test_camera_speed * get_dt()) + end + + -- Using camera + move_camera(test_camera_position.x, test_camera_position.y) + + draw_rect(100, 100, 300, 200, color.BLUE) + + start_camera() + draw_rect(0, 0, 300, 200, color.YELLOW) + stop_camera() + + draw_text("This text doesn't move!", 10, 10, 20, color.VIOLET) +end + +while window_running() do + start_drawing() + clear_window(color.BLACK) + + -- test_json() + -- test_api() + -- test_buttons() + -- test_camera() + + draw_info() + stop_drawing() +end + +close_window() -- cgit v1.2.3