Add tests and code for train