add unit tests and swap function