finger_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package chord
  2. import (
  3. "crypto/sha1"
  4. "fmt"
  5. "math/big"
  6. "reflect"
  7. "testing"
  8. "trial/achord/models"
  9. )
  10. func TestNewFingerTable(t *testing.T) {
  11. g := newFingerTable(NewInode("8", "0.0.0.0:8003"), sha1.New().Size())
  12. for i, j := range g {
  13. fmt.Printf("%d, %x, %x\n", i, j.Id, j.Node.Id)
  14. }
  15. }
  16. func TestNewFingerEntry(t *testing.T) {
  17. hashSize := sha1.New().Size() * 8
  18. id := GetHashID("0.0.0.0:8083")
  19. xInt := (&big.Int{}).SetBytes(id)
  20. for i := 0; i < 100; i++ {
  21. nextHash := fingerID(id, i, hashSize)
  22. aInt := (&big.Int{}).SetBytes(nextHash)
  23. fmt.Printf("%d, %d %d\n", xInt, aInt, hashSize)
  24. }
  25. }
  26. func Test_newFingerTable(t *testing.T) {
  27. type args struct {
  28. node *models.Node
  29. m int
  30. }
  31. tests := []struct {
  32. name string
  33. args args
  34. want fingerTable
  35. }{
  36. // TODO: Add test cases.
  37. // {"1", args{NewInode("8", "0.0.0.0:8083"), 1}, fingerTable},
  38. }
  39. for _, tt := range tests {
  40. t.Run(tt.name, func(t *testing.T) {
  41. if got := newFingerTable(tt.args.node, tt.args.m); !reflect.DeepEqual(got, tt.want) {
  42. t.Errorf("newFingerTable() = %v, want %v", got, tt.want)
  43. }
  44. })
  45. }
  46. }
  47. func Test_newFingerEntry(t *testing.T) {
  48. type args struct {
  49. id []byte
  50. node *models.Node
  51. }
  52. tests := []struct {
  53. name string
  54. args args
  55. want *fingerEntry
  56. }{
  57. // TODO: Add test cases.
  58. }
  59. for _, tt := range tests {
  60. t.Run(tt.name, func(t *testing.T) {
  61. if got := newFingerEntry(tt.args.id, tt.args.node); !reflect.DeepEqual(got, tt.want) {
  62. t.Errorf("newFingerEntry() = %v, want %v", got, tt.want)
  63. }
  64. })
  65. }
  66. }
  67. func Test_fingerID(t *testing.T) {
  68. type args struct {
  69. n []byte
  70. i int
  71. m int
  72. }
  73. tests := []struct {
  74. name string
  75. args args
  76. want []byte
  77. }{
  78. // TODO: Add test cases.
  79. }
  80. for _, tt := range tests {
  81. t.Run(tt.name, func(t *testing.T) {
  82. if got := fingerID(tt.args.n, tt.args.i, tt.args.m); !reflect.DeepEqual(got, tt.want) {
  83. t.Errorf("fingerID() = %v, want %v", got, tt.want)
  84. }
  85. })
  86. }
  87. }