'Test FeatureState\'s _calculate_bucket function.'

def test_calculate_bucket(self):

    feature_state = self.world._make_state(config={})
    NUM_USERS = (FeatureState.NUM_BUCKETS * 2000)
    fullnames = []
    for i in xrange(NUM_USERS):
        fullnames.append(('t2_%s' % str(i)))
    counter = collections.Counter()
    for fullname in fullnames:
        bucket = feature_state._calculate_bucket(fullname)
        counter[bucket] += 1
        self.assertEqual(bucket, feature_state._calculate_bucket(fullname))
    for bucket in xrange(FeatureState.NUM_BUCKETS):
        expected = (NUM_USERS / FeatureState.NUM_BUCKETS)
        actual = counter[bucket]
        percent_equal = (float(actual) / expected)
        self.assertAlmostEqual(percent_equal, 1.0, delta=0.1, msg=('bucket:    %s' % bucket))
