12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package chord
- import (
- "crypto/sha1"
- "fmt"
- "math/big"
- "reflect"
- "testing"
- "trial/achord/models"
- )
- func TestNewFingerTable(t *testing.T) {
- g := newFingerTable(NewInode("8", "0.0.0.0:8003"), sha1.New().Size())
- for i, j := range g {
- fmt.Printf("%d, %x, %x\n", i, j.Id, j.Node.Id)
- }
- }
- func TestNewFingerEntry(t *testing.T) {
- hashSize := 5 //sha1.New().Size() * 8
- id := []byte{4} //GetHashID("0.0.0.0:8083")[:1]
- xInt := (&big.Int{}).SetBytes(id)
- for i := 0; i < 100; i++ {
- nextHash := fingerID(id, i, hashSize)
- aInt := (&big.Int{}).SetBytes(nextHash)
- fmt.Printf("%d, %d %d\n", xInt, aInt, hashSize)
- }
- }
- func Test_newFingerTable(t *testing.T) {
- type args struct {
- node *models.Node
- m int
- }
- tests := []struct {
- name string
- args args
- want fingerTable
- }{
- // TODO: Add test cases.
- // {"1", args{NewInode("8", "0.0.0.0:8083"), 1}, fingerTable},
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- if got := newFingerTable(tt.args.node, tt.args.m); !reflect.DeepEqual(got, tt.want) {
- t.Errorf("newFingerTable() = %v, want %v", got, tt.want)
- }
- })
- }
- }
- func Test_newFingerEntry(t *testing.T) {
- type args struct {
- id []byte
- node *models.Node
- }
- tests := []struct {
- name string
- args args
- want *fingerEntry
- }{
- // TODO: Add test cases.
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- if got := newFingerEntry(tt.args.id, tt.args.node); !reflect.DeepEqual(got, tt.want) {
- t.Errorf("newFingerEntry() = %v, want %v", got, tt.want)
- }
- })
- }
- }
- func Test_fingerID(t *testing.T) {
- type args struct {
- n []byte
- i int
- m int
- }
- tests := []struct {
- name string
- args args
- want []byte
- }{
- // TODO: Add test cases.
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- if got := fingerID(tt.args.n, tt.args.i, tt.args.m); !reflect.DeepEqual(got, tt.want) {
- t.Errorf("fingerID() = %v, want %v", got, tt.want)
- }
- })
- }
- }
|