Kumo
A hand-rolled game engine.
git clone https://git.sentomk.me/Kumo.git
frame_buffer_test.cpp (1132B) · raw
1 #include "render/frame_buffer.h" 2 3 #include "check.h" 4 5 using kumo::FrameBuffer; 6 7 // A buffer whose width and height differ, so that a row stride taken from the 8 // wrong one lands on the wrong pixel. 9 TEST(at_uses_the_width_as_row_stride) { 10 FrameBuffer frame(5, 3); 11 frame.at(4, 0) = 1; 12 frame.at(0, 1) = 2; 13 frame.at(4, 2) = 3; 14 CHECK_EQ(frame.pixels[4], 1u); // row 0, last column 15 CHECK_EQ(frame.pixels[5], 2u); // row 1, first column 16 CHECK_EQ(frame.pixels[14], 3u); // the last pixel 17 } 18 19 TEST(contains_checks_both_sides) { 20 const FrameBuffer frame(5, 3); 21 CHECK(frame.contains(0, 0)); 22 CHECK(frame.contains(4, 2)); 23 CHECK(!frame.contains(5, 0)); 24 CHECK(!frame.contains(0, 3)); 25 CHECK(!frame.contains(-1, 0)); 26 CHECK(!frame.contains(0, -1)); 27 } 28 29 TEST(hash_depends_on_pixels_and_on_shape) { 30 FrameBuffer a(4, 2); 31 FrameBuffer b(4, 2); 32 CHECK(kumo::hash_pixels(a) == kumo::hash_pixels(b)); 33 34 b.at(3, 1) = 1; 35 CHECK(kumo::hash_pixels(a) != kumo::hash_pixels(b)); 36 37 // The same eight zero pixels, arranged differently. 38 const FrameBuffer tall(2, 4); 39 CHECK(kumo::hash_pixels(a) != kumo::hash_pixels(tall)); 40 }
