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.

60 lines
1017 B

3 years ago
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. "strings"
  5. "testing"
  6. )
  7. type test struct {
  8. hex string
  9. modhex string
  10. }
  11. func TestEncodeHexDecodeHex(t *testing.T) {
  12. var tests = []test{
  13. {
  14. modhex: "dteffuje",
  15. hex: "2d344e83",
  16. },
  17. {
  18. modhex: "DTEFFUJE",
  19. hex: "2d344e83",
  20. },
  21. {
  22. modhex: "dTeFfUjE",
  23. hex: "2d344e83",
  24. },
  25. {
  26. modhex: "hknhfjbrjnlnldnhcujvddbikngjrtgh",
  27. hex: "69b6481c8baba2b60e8f22179b58cd56",
  28. },
  29. {
  30. modhex: "urtubjtnuihvntcreeeecvbregfjibtn",
  31. hex: "ecde18dbe76fbd0c33330f1c354871db",
  32. },
  33. }
  34. for _, tc := range tests {
  35. src, _ := hex.DecodeString(tc.hex)
  36. modhex := EncodeToString(src)
  37. if modhex != strings.ToLower(modhex) {
  38. t.Errorf("Encode Incorrect: Actual: %s; Expected: %s\n", modhex, tc.modhex)
  39. }
  40. hexBytes, err := DecodeString(tc.modhex)
  41. if err != nil {
  42. t.Error(err)
  43. }
  44. hexStr := hex.EncodeToString(hexBytes)
  45. if hexStr != tc.hex {
  46. t.Errorf("Decode Incorrect: Actual: %s; Expected: %s\n", hexStr, tc.hex)
  47. }
  48. }
  49. }