test cases and function implementation