gitlab.com/SiaPrime/SiaPrime@v1.4.1/types/timestamp_test.go (about)

     1  package types
     2  
     3  import (
     4  	"sort"
     5  	"testing"
     6  )
     7  
     8  // TestTimestampSorting verifies that using sort.Sort accurately sorts
     9  // timestamps.
    10  func TestTimestampSorting(t *testing.T) {
    11  	ts := TimestampSlice{
    12  		CurrentTimestamp(),
    13  		CurrentTimestamp() - 5,
    14  		CurrentTimestamp() + 5,
    15  		CurrentTimestamp() + 12,
    16  		CurrentTimestamp() - 3,
    17  		CurrentTimestamp() - 25,
    18  	}
    19  
    20  	sort.Sort(ts)
    21  	currentTime := ts[0]
    22  	for _, timestamp := range ts {
    23  		if timestamp < currentTime {
    24  			t.Error("timestamp slice not properly sorted")
    25  		}
    26  		currentTime = timestamp
    27  	}
    28  }