github.com/dashpay/godash@v0.0.0-20160726055534-e038a21e0e3d/blockchain/timesorter_test.go (about) 1 // Copyright (c) 2013-2014 The btcsuite developers 2 // Copyright (c) 2016 The Dash developers 3 // Use of this source code is governed by an ISC 4 // license that can be found in the LICENSE file. 5 6 package blockchain_test 7 8 import ( 9 "reflect" 10 "sort" 11 "testing" 12 "time" 13 14 "github.com/dashpay/godash/blockchain" 15 ) 16 17 // TestTimeSorter tests the timeSorter implementation. 18 func TestTimeSorter(t *testing.T) { 19 tests := []struct { 20 in []time.Time 21 want []time.Time 22 }{ 23 { 24 in: []time.Time{ 25 time.Unix(1351228575, 0), // Fri Oct 26 05:16:15 UTC 2012 (Block #205000) 26 time.Unix(1351228575, 1), // Fri Oct 26 05:16:15 UTC 2012 (+1 nanosecond) 27 time.Unix(1348310759, 0), // Sat Sep 22 10:45:59 UTC 2012 (Block #200000) 28 time.Unix(1305758502, 0), // Wed May 18 22:41:42 UTC 2011 (Block #125000) 29 time.Unix(1347777156, 0), // Sun Sep 16 06:32:36 UTC 2012 (Block #199000) 30 time.Unix(1349492104, 0), // Sat Oct 6 02:55:04 UTC 2012 (Block #202000) 31 }, 32 want: []time.Time{ 33 time.Unix(1305758502, 0), // Wed May 18 22:41:42 UTC 2011 (Block #125000) 34 time.Unix(1347777156, 0), // Sun Sep 16 06:32:36 UTC 2012 (Block #199000) 35 time.Unix(1348310759, 0), // Sat Sep 22 10:45:59 UTC 2012 (Block #200000) 36 time.Unix(1349492104, 0), // Sat Oct 6 02:55:04 UTC 2012 (Block #202000) 37 time.Unix(1351228575, 0), // Fri Oct 26 05:16:15 UTC 2012 (Block #205000) 38 time.Unix(1351228575, 1), // Fri Oct 26 05:16:15 UTC 2012 (+1 nanosecond) 39 }, 40 }, 41 } 42 43 for i, test := range tests { 44 result := make([]time.Time, len(test.in)) 45 copy(result, test.in) 46 sort.Sort(blockchain.TstTimeSorter(result)) 47 if !reflect.DeepEqual(result, test.want) { 48 t.Errorf("timeSorter #%d got %v want %v", i, result, 49 test.want) 50 continue 51 } 52 } 53 }