Refactored HashCodeTest to reduce copy-and-paste code.