Example #1
0
  def testGetRapporMasksWithOnePRR(self):
    # Set randomness function to be used to sample 32 random bits
    # Set randomness function that takes two integers and returns a
    # random integer cohort in [a, b]

    params = copy.copy(self.typical_instance)
    params.flag_oneprr = True

    num_words = params.num_bloombits // 32 + 1
    rand = MockRandom()
    rand_funcs = rappor.SimpleRandFuncs(params, rand)

    # First two calls to get_rappor_masks for identical inputs
    # Third call for a different input
    print '\tget_rappor_masks 1'
    cohort_1, f_bits_1, mask_indices_1 = rappor.get_rappor_masks(
        "0", "abc", params, rand_funcs)
    print '\tget_rappor_masks 2'
    cohort_2, f_bits_2, mask_indices_2 = rappor.get_rappor_masks(
        "0", "abc", params, rand_funcs)
    print '\tget_rappor_masks 3'
    cohort_3, f_bits_3, mask_indices_3 = rappor.get_rappor_masks(
        "0", "abcd", params, rand_funcs)

    # First two outputs should be identical, i.e., identical PRRs
    self.assertEquals(f_bits_1, f_bits_2)
    self.assertEquals(mask_indices_1, mask_indices_2)
    self.assertEquals(cohort_1, cohort_2)

    # Third PRR should be different from the first PRR
    self.assertNotEqual(f_bits_1, f_bits_3)
    self.assertNotEqual(mask_indices_1, mask_indices_3)
    self.assertNotEqual(cohort_1, cohort_3)

    # Now testing with flag_oneprr false
    params.flag_oneprr = False
    cohort_1, f_bits_1, mask_indices_1 = rappor.get_rappor_masks(
        "0", "abc", params, rand_funcs)
    cohort_2, f_bits_2, mask_indices_2 = rappor.get_rappor_masks(
        "0", "abc", params, rand_funcs)

    self.assertNotEqual(f_bits_1, f_bits_2)
    self.assertNotEqual(mask_indices_1, mask_indices_2)
    self.assertNotEqual(cohort_1, cohort_2)
Example #2
0
    def testGetRapporMasksWithOnePRR(self):
        # Set randomness function to be used to sample 32 random bits
        # Set randomness function that takes two integers and returns a
        # random integer cohort in [a, b]

        params = copy.copy(self.typical_instance)
        params.flag_oneprr = True

        num_words = params.num_bloombits // 32 + 1
        rand = MockRandom()
        rand_funcs = rappor.SimpleRandFuncs(params, rand)

        # First two calls to get_rappor_masks for identical inputs
        # Third call for a different input
        print '\tget_rappor_masks 1'
        cohort_1, f_bits_1, mask_indices_1 = rappor.get_rappor_masks(
            "0", "abc", params, rand_funcs)
        print '\tget_rappor_masks 2'
        cohort_2, f_bits_2, mask_indices_2 = rappor.get_rappor_masks(
            "0", "abc", params, rand_funcs)
        print '\tget_rappor_masks 3'
        cohort_3, f_bits_3, mask_indices_3 = rappor.get_rappor_masks(
            "0", "abcd", params, rand_funcs)

        # First two outputs should be identical, i.e., identical PRRs
        self.assertEquals(f_bits_1, f_bits_2)
        self.assertEquals(mask_indices_1, mask_indices_2)
        self.assertEquals(cohort_1, cohort_2)

        # Third PRR should be different from the first PRR
        self.assertNotEqual(f_bits_1, f_bits_3)
        self.assertNotEqual(mask_indices_1, mask_indices_3)
        self.assertNotEqual(cohort_1, cohort_3)

        # Now testing with flag_oneprr false
        params.flag_oneprr = False
        cohort_1, f_bits_1, mask_indices_1 = rappor.get_rappor_masks(
            "0", "abc", params, rand_funcs)
        cohort_2, f_bits_2, mask_indices_2 = rappor.get_rappor_masks(
            "0", "abc", params, rand_funcs)

        self.assertNotEqual(f_bits_1, f_bits_2)
        self.assertNotEqual(mask_indices_1, mask_indices_2)
        self.assertNotEqual(cohort_1, cohort_2)
Example #3
0
  def testGetRapporMasksWithoutOnePRR(self):
    params = copy.copy(self.typical_instance)
    params.prob_f = 0.5  # For simplicity

    num_words = params.num_bloombits // 32 + 1
    rand = MockRandom()
    rand_funcs = rappor.SimpleRandFuncs(params, rand)
    rand_funcs.cohort_rand_fn = (lambda a, b: a)

    assigned_cohort, f_bits, mask_indices = rappor.get_rappor_masks(
        0, ["abc"], params, rand_funcs)

    self.assertEquals(0, assigned_cohort)
    self.assertEquals(0x000db6d, f_bits)  # dependent on 3 MockRandom values
    self.assertEquals(0x0006db6, mask_indices)
Example #4
0
    def testGetRapporMasksWithoutOnePRR(self):
        params = copy.copy(self.typical_instance)
        params.prob_f = 0.5  # For simplicity

        num_words = params.num_bloombits // 32 + 1
        rand = MockRandom()
        rand_funcs = rappor.SimpleRandFuncs(params, rand)
        rand_funcs.cohort_rand_fn = (lambda a, b: a)

        assigned_cohort, f_bits, mask_indices = rappor.get_rappor_masks(
            0, ["abc"], params, rand_funcs)

        self.assertEquals(0, assigned_cohort)
        self.assertEquals(0x000db6d,
                          f_bits)  # dependent on 3 MockRandom values
        self.assertEquals(0x0006db6, mask_indices)