sort implmentation and test cases