#include "render/frame_buffer.h" #include "check.h" using kumo::FrameBuffer; // A buffer whose width and height differ, so that a row stride taken from the // wrong one lands on the wrong pixel. TEST(at_uses_the_width_as_row_stride) { FrameBuffer frame(5, 3); frame.at(4, 0) = 1; frame.at(0, 1) = 2; frame.at(4, 2) = 3; CHECK_EQ(frame.pixels[4], 1u); // row 0, last column CHECK_EQ(frame.pixels[5], 2u); // row 1, first column CHECK_EQ(frame.pixels[14], 3u); // the last pixel } TEST(contains_checks_both_sides) { const FrameBuffer frame(5, 3); CHECK(frame.contains(0, 0)); CHECK(frame.contains(4, 2)); CHECK(!frame.contains(5, 0)); CHECK(!frame.contains(0, 3)); CHECK(!frame.contains(-1, 0)); CHECK(!frame.contains(0, -1)); } TEST(hash_depends_on_pixels_and_on_shape) { FrameBuffer a(4, 2); FrameBuffer b(4, 2); CHECK(kumo::hash_pixels(a) == kumo::hash_pixels(b)); b.at(3, 1) = 1; CHECK(kumo::hash_pixels(a) != kumo::hash_pixels(b)); // The same eight zero pixels, arranged differently. const FrameBuffer tall(2, 4); CHECK(kumo::hash_pixels(a) != kumo::hash_pixels(tall)); }