Add tests for encode