Refactored to remove repetitive lines

Refactored to remove repetitive lines from the test cases.