1 // Copyright (c) 2014-2017 The btcsuite developers
2 // Use of this source code is governed by an ISC
3 // license that can be found in the LICENSE file.
12 // TestBigToCompact ensures BigToCompact converts big integers to the expected
13 // compact representation.
14 func TestBigToCompact(t *testing.T) {
23 for x, test := range tests {
24 n := big.NewInt(test.in)
27 t.Errorf("TestBigToCompact test #%d failed: got %d want %d\n",
34 // TestCompactToBig ensures CompactToBig converts numbers using the compact
35 // representation to the expected big intergers.
36 func TestCompactToBig(t *testing.T) {
44 for x, test := range tests {
45 n := CompactToBig(test.in)
46 want := big.NewInt(test.out)
48 t.Errorf("TestCompactToBig test #%d failed: got %d want %d\n",
49 x, n.Int64(), want.Int64())
55 // TestCalcWork ensures CalcWork calculates the expected work value from values
56 // in compact representation.
57 func TestCalcWork(t *testing.T) {
65 for x, test := range tests {
66 bits := uint32(test.in)
69 if r.Int64() != test.out {
70 t.Errorf("TestCalcWork test #%d failed: got %v want %d\n",
71 x, r.Int64(), test.out)