TestHashString tests the stringized output for hashes.
(t *testing.T)
| 115 | |
| 116 | // TestHashString tests the stringized output for hashes. |
| 117 | func TestHashString(t *testing.T) { |
| 118 | // Block 100000 hash. |
| 119 | wantStr := "000000000003ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506" |
| 120 | hash := Hash([HashSize]byte{ // Make go vet happy. |
| 121 | 0x06, 0xe5, 0x33, 0xfd, 0x1a, 0xda, 0x86, 0x39, |
| 122 | 0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2, |
| 123 | 0x78, 0xd4, 0xaa, 0xec, 0x1c, 0x0b, 0x20, 0xaa, |
| 124 | 0x27, 0xba, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 125 | }) |
| 126 | |
| 127 | hashStr := hash.String() |
| 128 | if hashStr != wantStr { |
| 129 | t.Errorf("string: wrong hash string - got %v, want %v", |
| 130 | hashStr, wantStr) |
| 131 | } |
| 132 | for n := 0; n < 2*HashSize; n++ { |
| 133 | var l = HashSize |
| 134 | if n < l { |
| 135 | l = n |
| 136 | } |
| 137 | expect := string([]byte(wantStr)[:2*l]) |
| 138 | actual := hash.Short(n) |
| 139 | if expect != actual { |
| 140 | t.Errorf("short result mismatched: expect=%s actual=%s", expect, actual) |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | // TestNewHashFromStr executes tests against the NewHashFromStr function. |
| 146 | func TestNewHashFromStr(t *testing.T) { |