github.com/Bytom/bytom@v1.1.2-0.20210127130405-ae40204c0b09/protocol/bc/tx_status_test.go (about) 1 package bc 2 3 import ( 4 "testing" 5 ) 6 7 func TestSetBits(t *testing.T) { 8 cases := []struct { 9 op map[int]bool 10 result []bool 11 }{ 12 { 13 op: map[int]bool{ 14 0: true, 15 }, 16 result: []bool{true}, 17 }, 18 { 19 op: map[int]bool{ 20 0: false, 21 }, 22 result: []bool{false}, 23 }, 24 { 25 op: map[int]bool{ 26 0: false, 27 1: true, 28 }, 29 result: []bool{false, true}, 30 }, 31 { 32 op: map[int]bool{ 33 0: true, 34 1: false, 35 }, 36 result: []bool{true, false}, 37 }, 38 { 39 op: map[int]bool{ 40 0: true, 41 1: false, 42 2: false, 43 3: true, 44 4: true, 45 5: true, 46 6: false, 47 7: true, 48 8: false, 49 9: true, 50 }, 51 result: []bool{true, false, false, true, true, true, false, true, false, true}, 52 }, 53 } 54 55 for ci, c := range cases { 56 ts := NewTransactionStatus() 57 for i := 0; i < len(c.op); i++ { 58 if err := ts.SetStatus(i, c.op[i]); err != nil { 59 t.Errorf("test case #%d, %t", ci, err) 60 } 61 } 62 63 for i, v := range c.result { 64 result, err := ts.GetStatus(i) 65 if err != nil { 66 t.Errorf("test case #%d, %t", ci, err) 67 } 68 if result != v { 69 t.Errorf("bad result, %d want %t get %t", i, v, result) 70 } 71 } 72 } 73 }