Refactored test codes.

* Extracted constants.
* Removed newline which decreases the readability.
* Extracted common checking logic to methods.
* Added some comments.