You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

49 lines
880 B

package modhex
import (
"encoding/hex"
"testing"
)
type test struct {
hex string
modhex string
}
func TestEncodeHexDecodeHex(t *testing.T) {
var tests = []test{
{
modhex: "dteffuje",
hex: "2d344e83",
},
{
modhex: "hknhfjbrjnlnldnhcujvddbikngjrtgh",
hex: "69b6481c8baba2b60e8f22179b58cd56",
},
{
modhex: "urtubjtnuihvntcreeeecvbregfjibtn",
hex: "ecde18dbe76fbd0c33330f1c354871db",
},
}
for _, tc := range tests {
src, _ := hex.DecodeString(tc.hex)
modhex := EncodeToString(src)
if modhex != tc.modhex {
t.Errorf("Encode Incorrect: Actual: %s; Expected: %s\n", modhex, tc.modhex)
}
hexBytes, err := DecodeString(tc.modhex)
if err != nil {
t.Error(err)
}
hexStr := hex.EncodeToString(hexBytes)
if hexStr != tc.hex {
t.Errorf("Decode Incorrect: Actual: %s; Expected: %s\n", hexStr, tc.hex)
}
}
}