hash_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package hash
  2. import "testing"
  3. func TestSHA256(t *testing.T) {
  4. type TestCase struct {
  5. Input string
  6. Output string
  7. }
  8. testCases := []TestCase{
  9. {Input: "Gnocchi", Output: "5590208af75dc079e5e500fa39c982449ecbb02010f093a4de8b3377250c6f99"},
  10. {Input: "Spaghetti", Output: "dd81cff28075d9126e35ce2ba895a3ce95a9ecdc1ac899418ace10e7a697127d"},
  11. }
  12. for i, tc := range testCases {
  13. t.Logf("(%d) Testing %q", i, tc.Input)
  14. out := SHA256(tc.Input)
  15. if out != tc.Output {
  16. t.Errorf("Expected %q, got %q", tc.Output, out)
  17. }
  18. }
  19. }
  20. func TestSHA512(t *testing.T) {
  21. type TestCase struct {
  22. Input string
  23. Output string
  24. }
  25. testCases := []TestCase{
  26. {Input: "Gnocchi", Output: "43d0c2d7ee218cc30221c83e57c4ea3e6a68ce73225aff9b77c148e86f97c0b5d98a018a503115c4a81b9364cf132f5fc42878ece0412346aa60f2ea01f54756"},
  27. {Input: "Spaghetti", Output: "259f2043005a92915be7bd288050cffdc4f55201c823b5837e22b053ef982e364bf3625ee41c676b91047a450b33e66660ec6346690b234c2a0c47c832043ef2"},
  28. }
  29. for i, tc := range testCases {
  30. t.Logf("(%d) Testing %q", i, tc.Input)
  31. out := SHA512(tc.Input)
  32. if out != tc.Output {
  33. t.Errorf("Expected %q, got %q", tc.Output, out)
  34. }
  35. }
  36. }