def test_bias_limits(self):
     """ Test case to ensure that if bias is outside (0, 1), it will fail.
     """
     self.assertRaises(ValueError,
                       lambda: randomization.efrons_biased_coin(100000, -1))
     self.assertRaises(ValueError,
                       lambda: randomization.efrons_biased_coin(100000, 0))
     self.assertRaises(ValueError,
                       lambda: randomization.efrons_biased_coin(100000, 1))
     self.assertRaises(ValueError,
                       lambda: randomization.efrons_biased_coin(100000, 1.5))
    def test_distribution(self):
        """ Test Case to ensure the distribution of groups is close to uniform.

        Note: This test MAY fail.  It is entirely possible, with a probability
        of :math:`2^{-n}` where :math:`n` is the number of subjects to randomize
        """
        result = randomization.efrons_biased_coin(100000)
        percent_group_1 = (float(sum([value == 1 for value in result])) /
                           float(len(result)))

        self.assertTrue(percent_group_1 > 0.48)
        self.assertTrue(percent_group_1 < 0.52)

        # Test with bias set
        result = randomization.efrons_biased_coin(100000, 0.8)
        percent_group_1 = (float(sum([value == 1 for value in result])) /
                           float(len(result)))
        self.assertTrue(percent_group_1 > 0.48)
        self.assertTrue(percent_group_1 < 0.52)
 def test_n_groups(self):
     """ Test Case to ensure the correct number of groups are output"""
     result = randomization.efrons_biased_coin(100)
     self.assertEqual(len(set(result)), 2)
     result = randomization.efrons_biased_coin(100, 0.8)
     self.assertEqual(len(set(result)), 2)
 def test_length(self):
     """ Test Case to ensure the correct number of subjects are output"""
     result = randomization.efrons_biased_coin(100)
     self.assertEqual(len(result), 100)
     result = randomization.efrons_biased_coin(100, 0.8)
     self.assertEqual(len(result), 100)