Improve key definition unit tests and add equality implementation