예제 #1
0
 def test_TREE5(self):
     """Alpha Equal One. Sixteen Equal Weights."""
     W = PartiallySortedArray([10]*16)
     T = dvlCodeTree(W)
     self.assertEqual(T.weight(),W.rangeSum(0,len(W)))        
     L = T.depths()
     self.assertEqual(L,[4]*16)
예제 #2
0
 def test_TREE4(self):
     """Alpha Equal One. Four Equal Weights."""
     W = PartiallySortedArray([10]*4)
     T = dvlCodeTree(W)
     self.assertEqual(str(T),'(40,(20,[select(0)],[select(1)]),(rangeSum(2,4),[select(2)],[select(3)]))')
     L = T.depths()
     self.assertEqual(L,[2]*4)
예제 #3
0
 def test_TREE12(self):
     """Exponential Sequence."""
     W = PartiallySortedArray([1,2,4,8,16,32,64,128,256])
     T = dvlCodeTree(W)
     self.assertEqual(T.toStringWithAllWeightsCalculated(),'(511,(255,(127,(63,(31,(15,(7,(3,[1],[2]),[4]),[8]),[16]),[32]),[64]),[128]),[256])')
     L = T.depths()
     self.assertEqual(sorted(L),[1,2,3,4,5,6,7,8,8])
예제 #4
0
 def test_TREE7(self):
     """Alpha Equal One. Three Equal Weights."""
     W = PartiallySortedArray([10] * 3)
     T = dvlCodeTree(W)
     self.assertEqual(str(T), "(30,[10],(20,[select(0)],[select(1)]))")
     L = T.depths()
     self.assertEqual(L, [1, 2, 2])
예제 #5
0
 def test_TREE5(self):
     """Alpha Equal One. Sixteen Equal Weights."""
     W = PartiallySortedArray([10] * 16)
     T = dvlCodeTree(W)
     self.assertEqual(T.weight(), W.rangeSum(0, len(W)))
     L = T.depths()
     self.assertEqual(L, [4] * 16)
예제 #6
0
 def test_TREE3(self):
     """Alpha Equal One. Two Weights."""
     W = PartiallySortedArray([10, 10])
     T = dvlCodeTree(W)
     self.assertEqual(str(T), "(20,[select(0)],[select(1)])")
     L = T.depths()
     self.assertEqual(L, [1] * 2)
예제 #7
0
 def test_TREE3(self):
     """Alpha Equal One. Two Weights."""
     W = PartiallySortedArray([10,10])
     T = dvlCodeTree(W)
     self.assertEqual(str(T),"(20,[select(0)],[select(1)])")
     L = T.depths()
     self.assertEqual(L,[1]*2)
예제 #8
0
 def test_TREE8(self):
     """Alpha Equal One. Three Similar Weights."""
     W = PartiallySortedArray([12, 11, 10])
     T = dvlCodeTree(W)
     self.assertEqual(str(T), "(33,[12],(21,[select(0)],[select(1)]))")
     L = T.depths()
     self.assertEqual(L, [1, 2, 2])
예제 #9
0
 def test_TREE10(self):
     """Exponential Sequence."""
     W = PartiallySortedArray([1, 2, 4])
     T = dvlCodeTree(W)
     self.assertEqual(str(T), '(7,(3,[select(0)],[select(1)]),[4])')
     L = T.depths()
     self.assertEqual(sorted(L), [1, 2, 2])
예제 #10
0
 def test_TREE10(self):
     """Exponential Sequence."""
     W = PartiallySortedArray([1,2,4])
     T = dvlCodeTree(W)
     self.assertEqual(str(T),'(7,(3,[select(0)],[select(1)]),[4])')
     L = T.depths()
     self.assertEqual(sorted(L),[1,2,2])
예제 #11
0
 def test_TREE8(self):
     """Alpha Equal One. Three Similar Weights."""
     W = PartiallySortedArray([12,11,10])
     T = dvlCodeTree(W)
     self.assertEqual(str(T),"(33,[12],(21,[select(0)],[select(1)]))")
     L = T.depths()
     self.assertEqual(L,[1,2,2])
예제 #12
0
 def test_TREE7(self):
     """Alpha Equal One. Three Equal Weights."""
     W = PartiallySortedArray([10]*3)
     T = dvlCodeTree(W)
     self.assertEqual(str(T),"(30,[10],(20,[select(0)],[select(1)]))")
     L = T.depths()
     self.assertEqual(L,[1,2,2])
예제 #13
0
 def test_TREE12(self):
     """Exponential Sequence."""
     W = PartiallySortedArray([1, 2, 4, 8, 16, 32, 64, 128, 256])
     T = dvlCodeTree(W)
     self.assertEqual(
         T.toStringWithAllWeightsCalculated(),
         '(511,(255,(127,(63,(31,(15,(7,(3,[1],[2]),[4]),[8]),[16]),[32]),[64]),[128]),[256])'
     )
     L = T.depths()
     self.assertEqual(sorted(L), [1, 2, 3, 4, 5, 6, 7, 8, 8])
예제 #14
0
 def test_TREE4(self):
     """Alpha Equal One. Four Equal Weights."""
     W = PartiallySortedArray([10] * 4)
     T = dvlCodeTree(W)
     self.assertEqual(
         str(T),
         '(40,(20,[select(0)],[select(1)]),(rangeSum(2,4),[select(2)],[select(3)]))'
     )
     L = T.depths()
     self.assertEqual(L, [2] * 4)
예제 #15
0
 def test_TREE6(self):
     """Alpha Equal One. Eight Similar Weights."""
     W = PartiallySortedArray([10, 11, 12, 13, 14, 15, 16, 17])
     T = dvlCodeTree(W)
     L = T.depths()
     self.assertEqual(L, [3] * 8)
예제 #16
0
 def test_TREE2(self):
     """Alpha Equal One. Singleton input."""
     frequencies = PartiallySortedArray([10])
     self.assertEqual(dvlCodeTree(frequencies),
                      ExternalNode(frequencies, 0))
예제 #17
0
 def test_TREE9(self):
     """Alpha Equal Two. Single very small weight."""
     W = PartiallySortedArray([1]+[8]*3)
     T = dvlCodeTree(W)
     L = T.depths()
     self.assertEqual(L,[2]*4)
예제 #18
0
 def test_TREE6(self):
     """Alpha Equal One. Eight Similar Weights."""
     W = PartiallySortedArray([10,11,12,13,14,15,16,17])
     T = dvlCodeTree(W)
     L = T.depths()
     self.assertEqual(L,[3]*8)
예제 #19
0
 def test_TREE9(self):
     """Alpha Equal Two. Single very small weight."""
     W = PartiallySortedArray([1] + [8] * 3)
     T = dvlCodeTree(W)
     L = T.depths()
     self.assertEqual(L, [2] * 4)
예제 #20
0
 def test_TREE1(self):
     """Empty input."""
     frequencies = PartiallySortedArray([])
     self.assertEqual(dvlCodeTree(frequencies),None)
예제 #21
0
 def test_TREE1(self):
     """Empty input."""
     frequencies = PartiallySortedArray([])
     self.assertEqual(dvlCodeTree(frequencies), None)
예제 #22
0
 def test_TREE2(self):
     """Alpha Equal One. Singleton input."""
     frequencies = PartiallySortedArray([10])
     self.assertEqual(dvlCodeTree(frequencies),ExternalNode(frequencies,0))