2017-01-31 01:32:50 +01:00
|
|
|
// Copyright (c) 2013-2017 The btcsuite developers
|
2013-07-18 17:06:35 +02:00
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2017-08-20 02:21:36 +02:00
|
|
|
package blockchain
|
2013-07-18 17:06:35 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestTimeSorter tests the timeSorter implementation.
|
|
|
|
func TestTimeSorter(t *testing.T) {
|
|
|
|
tests := []struct {
|
2017-01-31 01:32:50 +01:00
|
|
|
in []int64
|
|
|
|
want []int64
|
2013-07-18 17:06:35 +02:00
|
|
|
}{
|
|
|
|
{
|
2017-01-31 01:32:50 +01:00
|
|
|
in: []int64{
|
|
|
|
1351228575, // Fri Oct 26 05:16:15 UTC 2012 (Block #205000)
|
|
|
|
1348310759, // Sat Sep 22 10:45:59 UTC 2012 (Block #200000)
|
|
|
|
1305758502, // Wed May 18 22:41:42 UTC 2011 (Block #125000)
|
|
|
|
1347777156, // Sun Sep 16 06:32:36 UTC 2012 (Block #199000)
|
|
|
|
1349492104, // Sat Oct 6 02:55:04 UTC 2012 (Block #202000)
|
2013-07-18 17:06:35 +02:00
|
|
|
},
|
2017-01-31 01:32:50 +01:00
|
|
|
want: []int64{
|
|
|
|
1305758502, // Wed May 18 22:41:42 UTC 2011 (Block #125000)
|
|
|
|
1347777156, // Sun Sep 16 06:32:36 UTC 2012 (Block #199000)
|
|
|
|
1348310759, // Sat Sep 22 10:45:59 UTC 2012 (Block #200000)
|
|
|
|
1349492104, // Sat Oct 6 02:55:04 UTC 2012 (Block #202000)
|
|
|
|
1351228575, // Fri Oct 26 05:16:15 UTC 2012 (Block #205000)
|
2013-07-18 17:06:35 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
2017-01-31 01:32:50 +01:00
|
|
|
result := make([]int64, len(test.in))
|
2013-07-18 17:06:35 +02:00
|
|
|
copy(result, test.in)
|
2017-08-20 02:21:36 +02:00
|
|
|
sort.Sort(timeSorter(result))
|
2013-07-18 17:06:35 +02:00
|
|
|
if !reflect.DeepEqual(result, test.want) {
|
|
|
|
t.Errorf("timeSorter #%d got %v want %v", i, result,
|
|
|
|
test.want)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|