start writing some tests for drawings
[?]
Jun 14, 2022, 5:28 PM
K2X6G75Z6XBC4DVIRWC5HC7XA3A2SKOM3MWSQTCFEYWIJL7LME2QCDependencies
- [2]
LUNH47XXmake text and drawings the same width - [3]
HYEAFRZ2split mouse_pressed events between Text and Drawing - [4]
DLQMM265scroll past first page - [*]
R5QXEHUIsomebody stop me - [*]
BLWAYPKVextract a module - [*]
VHQCNMARseveral more modules
Change contents
- file addition: drawing_tests.lua[6.2]
-- major tests for drawings-- We minimize assumptions about specific pixels, and try to test at the level-- of specific shapes. In particular, no tests of freehand drawings.function test_draw_line()io.write('\ntest_draw_line')-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)App.screen.init{width=Margin_left+300, height=300}Lines = load_array{'```lines', '```', ''}Line_width = 256 -- drawing coordinates 1:1 with pixelsCurrent_drawing_mode = 'line'App.draw()check_eq(#Lines, 2, 'F - test_draw_line/baseline/#lines')check_eq(Lines[1].mode, 'drawing', 'F - test_draw_line/baseline/mode')check_eq(Lines[1].y, Margin_top+Drawing_padding_top, 'F - test_draw_line/baseline/y')check_eq(Lines[1].h, 128, 'F - test_draw_line/baseline/y')check_eq(#Lines[1].shapes, 0, 'F - test_draw_line/baseline/#shapes')-- draw a lineApp.run_after_mouse_press(Margin_left+5, Margin_top+Drawing_padding_top+6, 1)App.run_after_mouse_release(Margin_left+35, Margin_top+Drawing_padding_top+36, 1)check_eq(#Lines[1].shapes, 1, 'F - test_draw_line/#shapes')check_eq(#Lines[1].points, 2, 'F - test_draw_line/#points')local drawing = Lines[1]local p1 = drawing.points[drawing.shapes[1].p1]local p2 = drawing.points[drawing.shapes[1].p2]check_eq(p1.x, 5, 'F - test_draw_line/p1:x')check_eq(p1.y, 6, 'F - test_draw_line/p1:y')check_eq(p2.x, 35, 'F - test_draw_line/p2:x')check_eq(p2.y, 36, 'F - test_draw_line/p2:y')end - edit in drawing.lua at line 4[8.18268][7.147]
require 'drawing_tests' - replacement in drawing.lua at line 207
return y >= drawing.y and y < drawing.y + Drawing.pixels(drawing.h) and x >= 16 and x < 16+Line_widthreturn y >= drawing.y and y < drawing.y + Drawing.pixels(drawing.h) and x >= Margin_left and x < Margin_left+Line_width