improved tests

This commit is contained in:
Andrew Cassidy 2021-03-21 23:36:34 -07:00
parent f7821c3a70
commit 3ed1e7dfa4

View File

@ -1,31 +1,19 @@
import rgbcx
import unittest
import nose
from parameterized import parameterized_class
from s3tc import BC1Block
from images import Blocks
import quicktex.s3tc.bc1 as bc1
import quicktex.s3tc.interpolator as interpolator
ColorMode = bc1.BC1Encoder.ColorMode
def get_class_name(cls, num, params_dict):
# By default the generated class named includes either the "name"
# parameter (if present), or the first string value. This example shows
# multiple parameters being included in the generated class name:
return "%s%s" % (
cls.__name__,
params_dict['suffix'],
)
@parameterized_class([
{"use_3color": False, "use_3color_black": False, "suffix": "4Color"},
{"use_3color": True, "use_3color_black": False, "suffix": "3Color"},
{"use_3color": True, "use_3color_black": True, "suffix": "3ColorBlack"},
], class_name_func=get_class_name)
class TestBC1EncoderBlocks(unittest.TestCase):
"""Test BC1 encoder with a variety of inputs with 3 color blocks disabled."""
class TestBC1Encoder(unittest.TestCase):
"""Test BC1 Encoder"""
def setUp(self):
self.bc1_encoder = rgbcx.BC1Encoder(rgbcx.InterpolatorType.Ideal, 5, self.use_3color, self.use_3color_black)
self.bc1_encoder = bc1.BC1Encoder(5)
def test_block_size(self):
"""Ensure encoded block size is 8 bytes."""
@ -36,6 +24,22 @@ class TestBC1EncoderBlocks(unittest.TestCase):
self.assertEqual(self.bc1_encoder.block_size, 8, 'incorrect reported block size')
self.assertEqual(len(out), 8, 'incorrect returned block size')
def get_class_name_blocks(cls, num, params_dict):
return "%s%s" % (cls.__name__, params_dict['color_mode'].name,)
@parameterized_class([
{"color_mode": ColorMode.FourColor},
{"color_mode": ColorMode.ThreeColor},
{"color_mode": ColorMode.ThreeColorBlack},
], class_name_func=get_class_name_blocks)
class TestBC1EncoderBlocks(unittest.TestCase):
"""Test BC1 encoder with a variety of inputs with 3 color blocks disabled."""
def setUp(self):
self.bc1_encoder = bc1.BC1Encoder(5, self.color_mode)
def test_block_4color(self):
"""Test encoder output with 4 color greyscale testblock."""
out = BC1Block.frombytes(self.bc1_encoder.encode_image(Blocks.greyscale, 4, 4))
@ -49,18 +53,22 @@ class TestBC1EncoderBlocks(unittest.TestCase):
out = BC1Block.frombytes(self.bc1_encoder.encode_image(Blocks.three_color, 4, 4))
selectors = [[1, 2, 2, 0]] * 4
self.assertEqual(out.is_3color(), self.use_3color, "returned incorrect block color mode for 3 color test block")
if self.use_3color: # we only care about the selectors if we are in 3 color mode
if self.color_mode != ColorMode.FourColor: # we only care about the selectors if we are in 3 color mode
self.assertTrue(out.is_3color(), "returned 4-color block for 3 color test block")
self.assertEqual(selectors, out.selectors, "block has incorrect selectors for 3 color test block")
else:
self.assertFalse(out.is_3color(), "return 3-color block in 4-color mode")
def test_block_3color_black(self):
"""Test encoder output with 3 color test block with black pixels."""
out = BC1Block.frombytes(self.bc1_encoder.encode_image(Blocks.three_color_black, 4, 4))
selectors = [[3, 1, 2, 0]] * 4
self.assertEqual(out.is_3color_black(), self.use_3color_black, "returned incorrect block color mode for 3 color with black test block")
if self.use_3color_black: # we only care about the selectors if we are in 3 color black mode
if self.color_mode == ColorMode.ThreeColorBlack: # we only care about the selectors if we are in 3 color black mode
self.assertTrue(out.is_3color_black(), "returned 4-color block for 3 color test block with black")
self.assertEqual(selectors, out.selectors, "block has incorrect selectors for 3 color with black test block")
else:
self.assertFalse(out.is_3color_black(), "returned incorrect block color mode for 3 color with black test block")
if __name__ == '__main__':