'Check distribution of some samples.'

def _check_sample(self, n, pvals, sample):

    self.assertIsInstance(sample, np.ndarray)
    self.assertEqual(sample.shape, (len(pvals),))
    self.assertIn(sample.dtype, (np.dtype('int32'), np.dtype('int64')))
    self.assertEqual(sample.sum(), n)
    for (p, nexp) in zip(pvals, sample):
        self.assertGreaterEqual(nexp, 0)
        self.assertLessEqual(nexp, n)
        pexp = (float(nexp) / n)
        self.assertGreaterEqual(pexp, (p * 0.5))
        self.assertLessEqual(pexp, (p * 2.0))
