def test_simpleflake_parts_random(self): random_bits = random.getrandbits(5) flake = sf.simpleflake(random_bits=random_bits) rand_result = sf.extract_bits(flake, sf.SIMPLEFLAKE_RANDOM_SHIFT, sf.SIMPLEFLAKE_RANDOM_LENGTH) self.assertEquals(random_bits, rand_result)
def test_simpleflake_parts_timestamp(self): coolstamp = SIMPLEFLAKE_EPOCH + 1234321.0 epoch_flake = simpleflake(timestamp=coolstamp) timestamp = extract_bits(epoch_flake, SIMPLEFLAKE_TIMESTAMP_SHIFT, SIMPLEFLAKE_TIMESTAMP_LENGTH) self.assertEquals(coolstamp, (timestamp / 1000.0) + SIMPLEFLAKE_EPOCH)
def test_simpleflake_parts_timestamp(self): coolstamp = sf.SIMPLEFLAKE_EPOCH + 1234321.0 epoch_flake = sf.simpleflake(timestamp=coolstamp) timestamp = sf.extract_bits(epoch_flake, sf.SIMPLEFLAKE_TIMESTAMP_SHIFT, sf.SIMPLEFLAKE_TIMESTAMP_LENGTH) self.assertEquals(coolstamp, (timestamp / 1000.0) + sf.SIMPLEFLAKE_EPOCH)