Exemplo n.º 1
0
 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)])
Exemplo n.º 2
0
 def testWith28Ones(self):
     """28 ones"""
     self.assertEqual(compressByRunLengths(vanLeeuwen([1]*28)),[(5,24),(4,4)])
Exemplo n.º 3
0
 def testTwoLevels(self):
     """Two Leaf levels"""
     self.assertEqual(compressByRunLengths(vanLeeuwen([1,1,1,1,8,8,8])),[(4,4),(2,3)])
Exemplo n.º 4
0
 def testSixWeights(self):
     """Six Weights"""
     self.assertEqual(compressByRunLengths(vanLeeuwen([1,1,1,1,1,1])),[(3,4),(2,2)])
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 def test_fourTernary(self):
     elements = [4, 3, 6, 8]
     result = compressByRunLengths(huffman(elements, 3))
     expected = [(2, 2), (1, 2)]
     self.assertEqual(result, expected)
Exemplo n.º 7
0
 def testIntermediateStepWith8And4(self):
     """Intermediate step"""
     self.assertEqual(
         compressByRunLengths(huffman([8, 8, 8, 4, 10, 13, 15])), [(4, 2),
                                                                   (3, 3),
                                                                   (2, 2)])
Exemplo n.º 8
0
 def testIntermediateStepWith8And4(self):
     """Intermediate step"""
     self.assertEqual(compressByRunLengths(vanLeeuwen([8,8,8,4,10,13,15])),[(4,2),(3,3),(2,2)])
Exemplo n.º 9
0
 def test_twoElements(self):
     elements = [4, 2]
     result = compressByRunLengths(huffman(elements, 2))
     expected = [(1, 2)]
     self.assertEqual(result, expected)
Exemplo n.º 10
0
 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)
Exemplo n.º 11
0
 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)])
Exemplo n.º 12
0
 def testWith28Ones(self):
     """28 ones"""
     self.assertEqual(compressByRunLengths(huffman([1] * 28)), [(5, 24),
                                                                (4, 4)])
Exemplo n.º 13
0
 def testTwoLevels(self):
     """Two Leaf levels"""
     self.assertEqual(compressByRunLengths(huffman([1, 1, 1, 1, 8, 8, 8])),
                      [(4, 4), (2, 3)])
Exemplo n.º 14
0
 def testSixWeights(self):
     """Six Weights"""
     self.assertEqual(compressByRunLengths(huffman([1, 1, 1, 1, 1, 1])),
                      [(3, 4), (2, 2)])
Exemplo n.º 15
0
 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)])
Exemplo n.º 16
0
 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)
Exemplo n.º 17
0
 def testIntermediateStepWith16And12(self):
     """Intermediate step"""
     self.assertEqual(compressByRunLengths(vanLeeuwen([16,12,10,13,15])),[(3,2),(2,3)])
Exemplo n.º 18
0
 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)
Exemplo n.º 19
0
 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)])
Exemplo n.º 20
0
 def testIntermediateStepWith16And12(self):
     """Intermediate step"""
     self.assertEqual(compressByRunLengths(huffman([16, 12, 10, 13, 15])),
                      [(3, 2), (2, 3)])