Add test for encode