Exemple #1
0
 def test_INIT1(self):
     """Alpha Equal One. Two Weights."""
     frequencies = PartiallySortedArray([10, 10])
     frequencies, externals, internals = INITIALIZE(frequencies)
     self.assertEqual(nodeListToString(internals),
                      '[(rangeSum(0,2),[select(0)],[select(1)])]')
     self.assertEqual(nodeListToWeightList(internals), [20])
     self.assertEqual(nodeListToWeightList(externals), [])
Exemple #2
0
 def test_DockInternals2(self):
     """Number of nodes to dock is a power of two minus one."""
     frequencies = PartiallySortedArray([14, 13, 12, 11, 10, 9, 8, 256])
     frequencies, externals, internals = INITIALIZE(frequencies)
     frequencies, externals, internals = GroupExternals(
         frequencies, externals, internals)
     frequencies, externals, internals = DockInternals(
         frequencies, externals, internals)
     self.assertEqual(nodeListToWeightList(internals), [77])
     self.assertEqual(nodeListToWeightList(externals), [256])
Exemple #3
0
 def test_DockInternals1(self):
     """Number of nodes to dock equal to a power of three."""
     frequencies = PartiallySortedArray([8] * 4 + [32])
     frequencies, externals, internals = INITIALIZE(frequencies)
     frequencies, externals, internals = GroupExternals(
         frequencies, externals, internals)
     frequencies, externals, internals = DockInternals(
         frequencies, externals, internals)
     self.assertEqual(nodeListToWeightList(internals), [32])
     self.assertEqual(nodeListToWeightList(externals), [32])
Exemple #4
0
 def test_INIT3(self):
     """Exponential Sequence."""
     frequencies = PartiallySortedArray(
         [10, 20, 40, 80, 160, 320, 640, 1280, 2560])
     frequencies, externals, internals = INITIALIZE(frequencies)
     self.assertEqual(nodeListToString(internals),
                      '[(rangeSum(0,2),[select(0)],[select(1)])]')
     self.assertEqual(nodeListToWeightList(internals), [30])
     self.assertEqual(nodeListToWeightList(externals),
                      [40, 80, 160, 320, 640, 1280, 2560])
Exemple #5
0
    def test_GroupExternals1(self):
        """Basic Example.
"""
        frequencies = PartiallySortedArray([10, 10, 11, 13, 14, 15, 20, 30])
        frequencies, externals, internals = INITIALIZE(frequencies)
        self.assertEqual(nodeListToWeightList(internals), [20])
        self.assertEqual(nodeListToWeightList(externals),
                         [11, 13, 14, 15, 20, 30])
        frequencies, externals, internals = GroupExternals(
            frequencies, externals, internals)
        self.assertEqual(nodeListToWeightList(internals), [24, 29, 40])
        self.assertEqual(nodeListToWeightList(externals), [30])
Exemple #6
0
 def test_Mix2(self):
     """Two Levels."""
     frequencies = PartiallySortedArray([8] * 8 + [255])
     frequencies, externals, internals = INITIALIZE(frequencies)
     self.assertEqual(nodeListToWeightList(internals), [16])
     self.assertEqual(nodeListToWeightList(externals), [8] * 6 + [255])
     frequencies, externals, internals = GroupExternals(
         frequencies, externals, internals)
     self.assertEqual(nodeListToWeightList(internals), [16] * 4)
     self.assertEqual(nodeListToWeightList(externals), [255])
     frequencies, externals, internals = DockInternals(
         frequencies, externals, internals)
     self.assertEqual(nodeListToWeightList(internals), [64])
     self.assertEqual(nodeListToWeightList(externals), [255])
     frequencies, externals, internals = MixInternalWithExternal(
         frequencies, externals, internals)
     self.assertEqual(nodeListToWeightList(internals), [319])
     self.assertEqual(nodeListToWeightList(externals), [])
Exemple #7
0
 def test_Mix1(self):
     """All weights equal."""
     frequencies = PartiallySortedArray([8] * 8)
     frequencies, externals, internals = INITIALIZE(frequencies)
     self.assertEqual(nodeListToWeightList(internals), [16])
     self.assertEqual(nodeListToWeightList(externals), [8] * 6)
     frequencies, externals, internals = GroupExternals(
         frequencies, externals, internals)
     self.assertEqual(nodeListToWeightList(internals), [16] * 4)
     self.assertEqual(nodeListToWeightList(externals), [])
     frequencies, externals, internals = DockInternals(
         frequencies, externals, internals)
     self.assertEqual(nodeListToWeightList(internals), [16] * 4)
     self.assertEqual(nodeListToWeightList(externals), [])
     frequencies, externals, internals = MixInternalWithExternal(
         frequencies, externals, internals)
     self.assertEqual(nodeListToWeightList(internals), [16] * 4)
     self.assertEqual(nodeListToWeightList(externals), [])