MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestHash_Difficulty

Function TestHash_Difficulty

crypto/hash/hash_test.go:231–282  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

229}
230
231func TestHash_Difficulty(t *testing.T) {
232 tests := []struct {
233 hash Hash
234 difficulty int
235 }{
236 {
237 Hash([HashSize]byte{ // Make go vet happy.
238 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
239 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
240 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
242 }),
243 7,
244 },
245 {
246 Hash([HashSize]byte{ // Make go vet happy.
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
251 }),
252 256,
253 },
254 {
255 Hash([HashSize]byte{ // Make go vet happy.
256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00,
260 }),
261 8,
262 },
263 }
264 for i, v := range tests {
265 if v.hash.Difficulty() != v.difficulty {
266 t.Errorf(
267 "Difficulty test #%d, hash:%s actual difficulty == %d, expect %d ",
268 i, v.hash.String(), v.hash.Difficulty(), v.difficulty,
269 )
270 }
271 }
272
273 nilDifficulty := (*Hash)(nil).Difficulty()
274 if nilDifficulty != -1 {
275 t.Errorf("difficulty test nil expect -1 got %d", nilDifficulty)
276 }
277
278 newDifficulty := new(Hash).Difficulty()
279 if newDifficulty != 256 {
280 t.Errorf("difficulty test new(Hash) expect 256 got %d", newDifficulty)
281 }
282}
283
284func unmarshalAndMarshalYAML(str string) string {
285 var hash Hash

Callers

nothing calls this directly

Calls 4

HashTypeAlias · 0.85
ErrorfMethod · 0.80
DifficultyMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected