def test_and_operation(self): and_bitmaps = { "test:andops:1": (1, 1, 0, 1, 0, 0, 0, 0, 1, 1), "test:andops:2": (1, 0, 0, 1, 1, 0, 1, 0, 1, 1), "test:andops:3": (1, 0, 0, 1, 0, 0, 0, 0, 1, 1), "test:andops:4": (1, 1, 0, 1, 0, 0, 0, 0, 0, 1), } result = (1, 0, 0, 1, 0, 0, 0, 0, 0, 1) # Initial State for key, val in and_bitmaps.items(): for i in range(len(val)): self.r.setbit(key, i, val[i]) # After login store_key_default = "test:andops:result" store_key = LoginMetrics.and_operation(and_bitmaps.keys(), store_key_default) #Check if the store key is the same self.assertEquals(store_key_default, store_key) for i in range(len(result)): self.assertEquals(result[i], self.r.getbit(store_key, i))
def test_and_operation_random_result_key(self): and_bitmaps = { "test:andops:1": (1, 1, 0, 1, 0, 0, 0, 0, 1, 1), "test:andops:2": (1, 0, 0, 1, 1, 0, 1, 0, 1, 1), "test:andops:3": (1, 0, 0, 1, 0, 0, 0, 0, 1, 1), "test:andops:4": (1, 1, 0, 1, 0, 0, 0, 0, 0, 1), } result = (1, 0, 0, 1, 0, 0, 0, 0, 0, 1) # Initial State for key, val in and_bitmaps.items(): for i in range(len(val)): self.r.setbit(key, i, val[i]) # After login store_key = LoginMetrics.and_operation(and_bitmaps.keys()) for i in range(len(result)): self.assertEquals(result[i], self.r.getbit(store_key, i))