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.

36 lines
975 B

  1. package kademlia
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestNewID(t *testing.T) {
  7. // get some IDs
  8. // for i := 0; i < 10; i++ {
  9. // id, err := NewID()
  10. // assert.Nil(t, err)
  11. // fmt.Println(id)
  12. // }
  13. idA, err := IDFromString("0fd85ddddf15aeec2d5d8b01b013dbca030a18d7")
  14. assert.Nil(t, err)
  15. assert.Equal(t, "0fd85ddddf15aeec2d5d8b01b013dbca030a18d7", idA.String())
  16. }
  17. func TestIDCmp(t *testing.T) {
  18. idA, err := IDFromString("0fd85ddddf15aeec2d5d8b01b013dbca030a18d7")
  19. assert.Nil(t, err)
  20. idB, err := IDFromString("c48d8b53dbefb609ed4e94d386dd5b22efcb2c5b")
  21. assert.Nil(t, err)
  22. assert.True(t, !idA.Cmp(idB))
  23. }
  24. func TestIDDistance(t *testing.T) {
  25. idA, err := IDFromString("0fd85ddddf15aeec2d5d8b01b013dbca030a18d7")
  26. assert.Nil(t, err)
  27. idB, err := IDFromString("c48d8b53dbefb609ed4e94d386dd5b22efcb2c5b")
  28. assert.Nil(t, err)
  29. assert.Equal(t, "cb55d68e04fa18e5c0131fd236ce80e8ecc1348c", idA.Distance(idB).String())
  30. }