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

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package modhex
  2. import (
  3. "encoding/hex"
  4. "testing"
  5. )
  6. type test struct {
  7. hex string
  8. modhex string
  9. }
  10. func TestEncodeHexDecodeHex(t *testing.T) {
  11. var tests = []test{
  12. {
  13. modhex: "dteffuje",
  14. hex: "2d344e83",
  15. },
  16. {
  17. modhex: "hknhfjbrjnlnldnhcujvddbikngjrtgh",
  18. hex: "69b6481c8baba2b60e8f22179b58cd56",
  19. },
  20. {
  21. modhex: "urtubjtnuihvntcreeeecvbregfjibtn",
  22. hex: "ecde18dbe76fbd0c33330f1c354871db",
  23. },
  24. }
  25. for _, tc := range tests {
  26. src, _ := hex.DecodeString(tc.hex)
  27. modhex := EncodeToString(src)
  28. if modhex != tc.modhex {
  29. t.Errorf("Encode Incorrect: Actual: %s; Expected: %s\n", modhex, tc.modhex)
  30. }
  31. hexBytes, err := DecodeString(tc.modhex)
  32. if err != nil {
  33. t.Error(err)
  34. }
  35. hexStr := hex.EncodeToString(hexBytes)
  36. if hexStr != tc.hex {
  37. t.Errorf("Decode Incorrect: Actual: %s; Expected: %s\n", hexStr, tc.hex)
  38. }
  39. }
  40. }