github.com/arieschain/arieschain@v0.0.0-20191023063405-37c074544356/consensus/bft/types_test.go (about) 1 package bft 2 3 import ( 4 "math/big" 5 "testing" 6 ) 7 8 func TestViewCompare(t *testing.T) { 9 // test equality 10 srvView := &View{ 11 Sequence: big.NewInt(2), 12 Round: big.NewInt(1), 13 } 14 tarView := &View{ 15 Sequence: big.NewInt(2), 16 Round: big.NewInt(1), 17 } 18 if r := srvView.Cmp(tarView); r != 0 { 19 t.Errorf("source(%v) should be equal to target(%v): have %v, want %v", srvView, tarView, r, 0) 20 } 21 22 // test larger Sequence 23 tarView = &View{ 24 Sequence: big.NewInt(1), 25 Round: big.NewInt(1), 26 } 27 if r := srvView.Cmp(tarView); r != 1 { 28 t.Errorf("source(%v) should be larger than target(%v): have %v, want %v", srvView, tarView, r, 1) 29 } 30 31 // test larger Round 32 tarView = &View{ 33 Sequence: big.NewInt(2), 34 Round: big.NewInt(0), 35 } 36 if r := srvView.Cmp(tarView); r != 1 { 37 t.Errorf("source(%v) should be larger than target(%v): have %v, want %v", srvView, tarView, r, 1) 38 } 39 40 // test smaller Sequence 41 tarView = &View{ 42 Sequence: big.NewInt(3), 43 Round: big.NewInt(1), 44 } 45 if r := srvView.Cmp(tarView); r != -1 { 46 t.Errorf("source(%v) should be smaller than target(%v): have %v, want %v", srvView, tarView, r, -1) 47 } 48 tarView = &View{ 49 Sequence: big.NewInt(2), 50 Round: big.NewInt(2), 51 } 52 if r := srvView.Cmp(tarView); r != -1 { 53 t.Errorf("source(%v) should be smaller than target(%v): have %v, want %v", srvView, tarView, r, -1) 54 } 55 }