def test_create_shuffle_keep_same(): Key.set_random_seed(1111) Shuffle.set_random_seed(1112) # Empty shuffle. key = Key() assert key.__str__() == "" shuffle = Shuffle(key.get_size(), Shuffle.SHUFFLE_KEEP_SAME) assert shuffle.__str__() == "" # Non-empty shuffle. key = Key.create_random_key(8) assert key.__str__() == "00101100" shuffle = Shuffle(key.get_size(), Shuffle.SHUFFLE_KEEP_SAME) assert shuffle.__str__() == "0->0 1->1 2->2 3->3 4->4 5->5 6->6 7->7" for index in range(key.get_size()): assert shuffle.get_bit(key, index) == key.get_bit(index)
def test_create_shuffle_random(): Key.set_random_seed(1111) Shuffle.set_random_seed(1112) # Empty shuffle. key = Key() assert key.__str__() == "" shuffle = Shuffle(key.get_size(), Shuffle.SHUFFLE_RANDOM) assert shuffle.__str__() == "" # Non-empty shuffle. key = Key.create_random_key(16) assert key.__str__() == "0010110001010010" shuffle = Shuffle(key.get_size(), Shuffle.SHUFFLE_RANDOM) assert shuffle.__str__() == ("0->2 1->9 2->8 3->7 4->3 5->12 6->1 7->5 8->13 " "9->6 10->0 11->14 12->10 13->4 14->11 15->15") key = Key() assert key.__str__() == ""
def test_copy_without_noise(): Key.set_random_seed(3456) # Copy an empty key. key = Key() assert key.__str__() == "" key_copy = key.copy(0.0, Key.ERROR_METHOD_EXACT) assert key.__str__() == "" assert key_copy.__str__() == "" # Copy a non-empty key. key = Key.create_random_key(64) assert key.__str__() == "1110011000011110100111010001100011100000010011010101110100000010" key_copy = key.copy(0.0, Key.ERROR_METHOD_EXACT) assert key.__str__() == "1110011000011110100111010001100011100000010011010101110100000010" assert key_copy.__str__() == "1110011000011110100111010001100011100000010011010101110100000010" # Make sure that each key has an independent copy of the bits; i.e. that changing a bit in the # original key does not affect the copied key, or vice versa. key_copy.flip_bit(1) assert key.__str__() == "1110011000011110100111010001100011100000010011010101110100000010" assert key_copy.__str__() == "1010011000011110100111010001100011100000010011010101110100000010"
def test_str(): Key.set_random_seed(222) key = Key() assert key.__str__() == "" key = Key.create_random_key(8) assert key.__str__() == "00110010"