def test_TREE8(self): """Alpha Equal One. Three Similar Weights.""" W = PartiallySortedArray([12, 11, 10]) T = gdmCodeTree(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 = gdmCodeTree(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 = gdmCodeTree(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 = gdmCodeTree(W) self.assertEqual(str(T), "(20,[select(0)],[select(1)])") L = T.depths() self.assertEqual(L, [1] * 2)
def test_TREE10(self): """Exponential Sequence.""" W = PartiallySortedArray([1, 2, 4]) T = gdmCodeTree(W) self.assertEqual(T.toStringWithAllWeightsCalculated(), '(7,(3,[1],[2]),[4])') L = T.depths() self.assertEqual(sorted(L), [1, 2, 2])
def test_TREE4(self): """Alpha Equal One. Four Equal Weights.""" W = PartiallySortedArray([10] * 4) T = gdmCodeTree(W) self.assertEqual(T.toStringWithAllWeightsCalculated(), '(40,(20,[10],[10]),(20,[10],[10]))') 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 = gdmCodeTree(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_TREE9(self): """Alpha Equal Two. Single very small weight.""" W = PartiallySortedArray([1] + [8] * 3) T = gdmCodeTree(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 = gdmCodeTree(W) L = T.depths() self.assertEqual(L, [3] * 8)