def test_hash_effectiveness(self):
        range_third = int(Range.RANGE_MAX_VALUE / 3)
        partitioner1 = HashPartitioner('node1', 'MIN..%s' % range_third)
        partitioner2 = HashPartitioner('node2', '%s..%s' % (range_third, range_third + range_third))
        partitioner3 = HashPartitioner('node2', '%s..MAX' % (range_third + range_third))

        refs_count = 1000

        refs = self._generate_refs(count=refs_count)

        p1_count = 0
        p2_count = 0
        p3_count = 0

        for ref in refs:
            if partitioner1._is_in_hash_range(ref):
                p1_count += 1
            # note if and not else-if.
            if partitioner2._is_in_hash_range(ref):
                p2_count += 1
            if partitioner3._is_in_hash_range(ref):
                p3_count += 1

        self.assertEqual(p1_count + p2_count + p3_count, refs_count,
                         'Sum should equal all sensors.')

        # Test effectiveness by checking if the  sd is within 20% of mean
        mean = refs_count / 3
        variance = float((p1_count - mean)**2 + (p1_count - mean)**2 + (p3_count - mean)**2) / 3
        sd = math.sqrt(variance)

        self.assertTrue(sd / mean <= 0.2, 'Some values deviate too much from the mean.')
dataset/ETHPy150Open StackStorm/st2/st2reactor/tests/unit/test_hash_partitioner.py/HashPartitionerTest.test_hash_effectiveness/original