"""test of core functions """ import floatimg def test_create(): width = 640 height = 480 img = floatimg.create(width, height, floatimg.RGB) assert img.width == width assert img.height == height assert img.type_id == floatimg.RGB img = floatimg.create_rgb(width, height) assert img.type_id == floatimg.RGB # TODO inspect RVB def test_clone(): width = 5 height = 5 img = floatimg.create(width, height, floatimg.RGB) img.fill((127.0, 127.0, 127.0)) # clone without copying pixel values img2 = img.clone(False) assert img.width == img2.width assert img.height == img2.height assert img.type_id == img2.type_id # TODO inspect RVB and do pixel per pixel comparison for y in range(height): for x in range(width): assert img.get(x, y) != img2.get(x, y) img2 = img.clone(True) assert img.width == img2.width assert img.height == img2.height assert img.type_id == img2.type_id # TODO inspect RVB and do pixel per pixel comparison for y in range(height): for x in range(width): assert img.get(x, y) == img2.get(x, y) def test_rgb_constant(): width = 5 height = 5 color = [127.0, 127.0, 127.0] img = floatimg.create_rgb(width, height) img.fill(color) for y in range(height): for x in range(width): assert img.get(x, y) == color def test_copy_data(): width = 5 height = 5 color = [127.0, 127.0, 127.0] img = floatimg.create_rgb(width, height) img.fill(color) img2 = floatimg.create_rgb(width, height) img2.fill((64.0, 64.0, 64.0)) img.copy_data(img2) for y in range(height): for x in range(width): assert img.get(x, y) == img2.get(x, y) def test_clear(): width, height = 5, 5 color = [127.0, 127.0, 127.0] img = floatimg.create_rgb(width, height) img.fill(color) img.clear() for y in range(height): for x in range(width): assert img.get(x, y) == [0.0, 0.0, 0.0] def test_str_type(): width, height = 5, 5 img = floatimg.create_rgb(width, height) assert img.str_type == "rgb" def test__str__(): width, height = 5, 5 img = floatimg.create_rgb(width, height) img_str = str(img) assert " width=5 " in img_str assert " height=5 " in img_str assert " type=rgb>" in img_str def test_put_rgb(): width, height = 5, 5 img = floatimg.create_rgb(width, height) assert img.get(0, 0) == [0.0, 0.0, 0.0] img.put(0, 0, (127.0, 127.0, 127.0)) assert img.get(0, 0) == [127.0, 127.0, 127.0]