#!/usr/bin/env python
# Name: test.py
# Purpose: Test the tinypack library.
# Author(s): Matthew Tan Creti
# 
# Copyright 2011 Matthew Tan Creti
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest
import tinypack

class TestTinypack(unittest.TestCase):
	def setUp(self):
		self.plain = [
			[255,254,253,252,255,254,253,252,255,253],
			[254,253,252,255,254,253,252,255,255,255]]

	def test_lzrwEgaChain(self):
		compressor = tinypack.Lzrw(len(self.plain[0]), tinypack.EgaCodebook())

		compressed = [
			compressor.chainCompress(self.plain[0]),
			compressor.chainCompress(self.plain[1])]

		compressor.init()
		expanded = [
			compressor.chainExpand(compressed[0]),
			compressor.chainExpand(compressed[1])]

		self.assertEqual(expanded, self.plain)

if __name__ == '__main__':
	unittest.main()
