refactor encode_test.go to use one table-driven test