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)
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)
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])
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])
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)
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)
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)
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])
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])
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])
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])
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])
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])
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)
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)
def test_TREE2(self): """Alpha Equal One. Singleton input.""" frequencies = PartiallySortedArray([10]) self.assertEqual(dvlCodeTree(frequencies), ExternalNode(frequencies, 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)
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)
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)
def test_TREE1(self): """Empty input.""" frequencies = PartiallySortedArray([]) self.assertEqual(dvlCodeTree(frequencies),None)
def test_TREE1(self): """Empty input.""" frequencies = PartiallySortedArray([]) self.assertEqual(dvlCodeTree(frequencies), None)
def test_TREE2(self): """Alpha Equal One. Singleton input.""" frequencies = PartiallySortedArray([10]) self.assertEqual(dvlCodeTree(frequencies),ExternalNode(frequencies,0))