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.

33 lines
1.1 KiB

  1. package merkle
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestSimpleMap(t *testing.T) {
  8. tests := []struct {
  9. keys []string
  10. values []string // each string gets converted to []byte in test
  11. want string
  12. }{
  13. {[]string{"key1"}, []string{"value1"}, "fa9bc106ffd932d919bee935ceb6cf2b3dd72d8f"},
  14. {[]string{"key1"}, []string{"value2"}, "e00e7dcfe54e9fafef5111e813a587f01ba9c3e8"},
  15. // swap order with 2 keys
  16. {[]string{"key1", "key2"}, []string{"value1", "value2"}, "eff12d1c703a1022ab509287c0f196130123d786"},
  17. {[]string{"key2", "key1"}, []string{"value2", "value1"}, "eff12d1c703a1022ab509287c0f196130123d786"},
  18. // swap order with 3 keys
  19. {[]string{"key1", "key2", "key3"}, []string{"value1", "value2", "value3"}, "b2c62a277c08dbd2ad73ca53cd1d6bfdf5830d26"},
  20. {[]string{"key1", "key3", "key2"}, []string{"value1", "value3", "value2"}, "b2c62a277c08dbd2ad73ca53cd1d6bfdf5830d26"},
  21. }
  22. for i, tc := range tests {
  23. db := newSimpleMap()
  24. for i := 0; i < len(tc.keys); i++ {
  25. db.Set(tc.keys[i], []byte(tc.values[i]))
  26. }
  27. got := db.Hash()
  28. assert.Equal(t, tc.want, fmt.Sprintf("%x", got), "Hash didn't match on tc %d", i)
  29. }
  30. }