def testThreeLevelsValuesMingle(self): """Three Leaf levels, and values mingle""" self.assertEqual( compressByRunLengths(huffman([1] * 28 + [10, 13, 15])), [(7, 8), (6, 20), (3, 1), (2, 2)])
def testWith28Ones(self): """28 ones""" self.assertEqual(compressByRunLengths(vanLeeuwen([1]*28)),[(5,24),(4,4)])
def testTwoLevels(self): """Two Leaf levels""" self.assertEqual(compressByRunLengths(vanLeeuwen([1,1,1,1,8,8,8])),[(4,4),(2,3)])
def testSixWeights(self): """Six Weights""" self.assertEqual(compressByRunLengths(vanLeeuwen([1,1,1,1,1,1])),[(3,4),(2,2)])
def test_paperExample(self): elements = [0.22, 0.20, 0.18, 0.15, 0.10, 0.08, 0.05, 0.02] result = compressByRunLengths(huffman(elements, 4)) expected = [(3, 2), (2, 3), (1, 3)] self.assertEqual(result, expected)
def test_fourTernary(self): elements = [4, 3, 6, 8] result = compressByRunLengths(huffman(elements, 3)) expected = [(2, 2), (1, 2)] self.assertEqual(result, expected)
def testIntermediateStepWith8And4(self): """Intermediate step""" self.assertEqual( compressByRunLengths(huffman([8, 8, 8, 4, 10, 13, 15])), [(4, 2), (3, 3), (2, 2)])
def testIntermediateStepWith8And4(self): """Intermediate step""" self.assertEqual(compressByRunLengths(vanLeeuwen([8,8,8,4,10,13,15])),[(4,2),(3,3),(2,2)])
def test_twoElements(self): elements = [4, 2] result = compressByRunLengths(huffman(elements, 2)) expected = [(1, 2)] self.assertEqual(result, expected)
def test_unusualWeights(self): elements = [-4, 0, 18.3, 9] result = compressByRunLengths(huffman(elements, 2)) expected = [(3, 2), (2, 1), (1, 1)] self.assertEqual(result, expected)
def testThreeLevelsValuesDoNotMingle(self): """Three Leaf levels, and values do not mingle""" self.assertEqual( compressByRunLengths(huffman([1] * 32 + [10, 13, 15])), [(6, 32), (3, 2), (2, 1)])
def testWith28Ones(self): """28 ones""" self.assertEqual(compressByRunLengths(huffman([1] * 28)), [(5, 24), (4, 4)])
def testTwoLevels(self): """Two Leaf levels""" self.assertEqual(compressByRunLengths(huffman([1, 1, 1, 1, 8, 8, 8])), [(4, 4), (2, 3)])
def testSixWeights(self): """Six Weights""" self.assertEqual(compressByRunLengths(huffman([1, 1, 1, 1, 1, 1])), [(3, 4), (2, 2)])
def testThreeLevelsValuesDoNotMingle(self): """Three Leaf levels, and values do not mingle""" self.assertEqual(compressByRunLengths(vanLeeuwen([1]*32+[10,13,15])),[(6,32),(3,2),(2,1)])
def test_fourElements(self): elements = [4, 3, 6, 8] result = compressByRunLengths(huffman(elements, 2)) expected = [(3, 2), (2, 1), (1, 1)] self.assertEqual(result, expected)
def testIntermediateStepWith16And12(self): """Intermediate step""" self.assertEqual(compressByRunLengths(vanLeeuwen([16,12,10,13,15])),[(3,2),(2,3)])
def test_sameWeigths(self): for d in range(2, 15): elements = [1] * d result = compressByRunLengths(huffman(elements, d)) expected = [(1, d)] self.assertEqual(result, expected)
def testThreeLevelsValuesMingle(self): """Three Leaf levels, and values mingle""" self.assertEqual(compressByRunLengths(vanLeeuwen([1]*28+[10,13,15])),[(7,8),(6,20),(3,1),(2,2)])
def testIntermediateStepWith16And12(self): """Intermediate step""" self.assertEqual(compressByRunLengths(huffman([16, 12, 10, 13, 15])), [(3, 2), (2, 3)])