code: def test_optimize_correctness():
      # 256 color Palette image, posterize to > 128 and < 128 levels
      # Size bigger and smaller than 512x512
      # Check the palette for number of colors allocated.
      # Check for correctness after conversion back to RGB
      def check(colors, size, expected_palette_length):
          # make an image with empty colors in the start of the palette range
          im = Image.frombytes(
              "P",
              (colors, colors),
              bytes(range(256 - colors, 256)) * colors,
          )
          im = im.resize((size, size))
          outfile = BytesIO()
          im.save(outfile, "GIF")
          outfile.seek(0)
          with Image.open(outfile) as reloaded:
              # check palette length
              palette_length = max(
                  i + 1 for i, v in enumerate(reloaded.histogram()) if v
              )
              assert expected_palette_length == palette_length
  
              assert_image_equal(
                  im.convert("RGB"), reloaded.convert("RGB")
              )
  
      # These do optimize the palette
      check(128, 511, 128)
      check(64, 511, 64)
      check(4, 511, 4)
  
      # These don't optimize the palette
      check(128, 513, 256)
      check(64, 513, 256)
      check(4, 513, 256)
  
      # Other limits that don't optimize the palette
      check(129, 511, 256)
      check(255, 511, 256)
      check(256, 511, 256)
  
imports: from io import BytesIO
  import pytest
  from PIL import GifImagePlugin, Image, ImageDraw, ImagePalette, features
  from .helper import assert_image_equal, assert_image_equal_tofile, assert_image_similar, hopper, is_pypy, netpbm_available
label_desc: Use image node_id 7 for calling a global function with example usage: test_optimize_correctness() without return types