forked from deroproject/derosuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscores_test.go
61 lines (52 loc) · 2.53 KB
/
scores_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2017-2018 DERO Project. All rights reserved.
// Use of this source code in any form is governed by RESEARCH license.
// license can be found in the LICENSE file.
// GPG: 0F39 E425 8C65 3947 702A 8234 08B2 0360 A03A 9DE8
//
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package blockchain
import "testing"
import "math/big"
import "github.com/deroproject/derosuite/crypto"
func Test_Scores_Sorting(t *testing.T) {
tips_scores := []BlockScore{
{
BLID: crypto.HashHexToHash("0000000000000000000000000000000000000000000000000000000000000000"),
Height: 76,
Cumulative_Difficulty: new(big.Int).SetUint64(95),
},
{
BLID: crypto.HashHexToHash("0000000000000000000000000000000000000000000000000000000000000099"),
Height: 7,
Cumulative_Difficulty: new(big.Int).SetUint64(99),
},
{
BLID: crypto.HashHexToHash("0000000000000000000000000000000000000000000000000000000000000011"),
Height: 45,
Cumulative_Difficulty: new(big.Int).SetUint64(99),
},
}
sort_descending_by_cumulative_difficulty(tips_scores)
if tips_scores[0].BLID != crypto.HashHexToHash("0000000000000000000000000000000000000000000000000000000000000011") {
t.Fatalf("core sorting test failed")
}
if tips_scores[1].BLID != crypto.HashHexToHash("0000000000000000000000000000000000000000000000000000000000000099") {
t.Fatalf("core sorting test 2 failed")
}
sort_ascending_by_height(tips_scores)
if tips_scores[0].BLID != crypto.HashHexToHash("0000000000000000000000000000000000000000000000000000000000000099") {
t.Fatalf("core sorting test by height failed")
}
if tips_scores[1].BLID != crypto.HashHexToHash("0000000000000000000000000000000000000000000000000000000000000011") {
t.Fatalf("core sorting test 2 by height failed")
}
}