refactor test code

same functionality in less code