Add isSorted function with tests