added tests and implementation for code variant helper function