implementing a dictionary swap function and its test