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, "3bb53f017d2f5b4f144692aa829a5c245ac2b123", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
  12. }
  13. {
  14. db := NewSimpleMap()
  15. db.Set("key1", "value2")
  16. assert.Equal(t, "14a68db29e3f930ffaafeff5e07c17a439384f39", 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, "275c6367f4be335f9c482b6ef72e49c84e3f8bda", 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, "275c6367f4be335f9c482b6ef72e49c84e3f8bda", 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, "48d60701cb4c96916f68a958b3368205ebe3809b", 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, "48d60701cb4c96916f68a958b3368205ebe3809b", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
  43. }
  44. }