Beispiel #1
0
    def test_distrib(self):
        epsilon = 1.0
        runs = 10000
        mech = StringToInt(Geometric().set_sensitivity(1).set_epsilon(epsilon))
        count = [0, 0]

        for _ in range(runs):
            if mech.randomise("0") == "0":
                count[0] += 1

            if mech.randomise("1") == "0":
                count[1] += 1

        self.assertGreater(count[0], count[1])
        self.assertLessEqual(count[0] / runs,
                             count[1] * np.exp(epsilon) / runs + 0.05)
Beispiel #2
0
 def test_randomise(self):
     mech = StringToInt(Geometric().set_sensitivity(1).set_epsilon(1))
     self.assertIsInstance(mech.randomise("1"), str)
Beispiel #3
0
 def test_no_parent(self):
     with self.assertRaises(TypeError):
         StringToInt()
Beispiel #4
0
 def test_not_none(self):
     mech = StringToInt(Geometric())
     self.assertIsNotNone(mech)
     _mech = mech.copy()
     self.assertIsNotNone(_mech)
Beispiel #5
0
 def test_set_epsilon_locally(self):
     mech = StringToInt(Geometric().set_sensitivity(1))
     mech.set_epsilon(1)
     self.assertIsNotNone(mech)
Beispiel #6
0
 def test_empty_mechanism(self):
     mech = StringToInt(Geometric())
     with self.assertRaises(ValueError):
         mech.randomise("1")
Beispiel #7
0
 def test_randomise(self):
     mech = StringToInt(Geometric(epsilon=1))
     self.assertIsInstance(mech.randomise("1"), str)