Added a set of unit tests to ensure all branches of encode(E, R) get exercised.