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.

47 lines
1.3 KiB

  1. package merkle
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestSimpleMap(t *testing.T) {
  8. {
  9. db := NewSimpleMap()
  10. db.Set("key1", "value1")
  11. assert.Equal(t, "376bf717ebe3659a34f68edb833dfdcf4a2d3c10", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
  12. }
  13. {
  14. db := NewSimpleMap()
  15. db.Set("key1", "value2")
  16. assert.Equal(t, "72fd3a7224674377952214cb10ef21753ec803eb", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
  17. }
  18. {
  19. db := NewSimpleMap()
  20. db.Set("key1", "value1")
  21. db.Set("key2", "value2")
  22. assert.Equal(t, "23a160bd4eea5b2fcc0755d722f9112a15999abc", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
  23. }
  24. {
  25. db := NewSimpleMap()
  26. db.Set("key2", "value2") // NOTE: out of order
  27. db.Set("key1", "value1")
  28. assert.Equal(t, "23a160bd4eea5b2fcc0755d722f9112a15999abc", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
  29. }
  30. {
  31. db := NewSimpleMap()
  32. db.Set("key1", "value1")
  33. db.Set("key2", "value2")
  34. db.Set("key3", "value3")
  35. assert.Equal(t, "40df7416429148d03544cfafa86e1080615cd2bc", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
  36. }
  37. {
  38. db := NewSimpleMap()
  39. db.Set("key2", "value2") // NOTE: out of order
  40. db.Set("key1", "value1")
  41. db.Set("key3", "value3")
  42. assert.Equal(t, "40df7416429148d03544cfafa86e1080615cd2bc", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
  43. }
  44. }