...

Source file src/github.com/blang/semver/sort_test.go

Documentation: github.com/blang/semver

     1  package semver
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestSort(t *testing.T) {
     9  	v100, _ := Parse("1.0.0")
    10  	v010, _ := Parse("0.1.0")
    11  	v001, _ := Parse("0.0.1")
    12  	versions := []Version{v010, v100, v001}
    13  	Sort(versions)
    14  
    15  	correct := []Version{v001, v010, v100}
    16  	if !reflect.DeepEqual(versions, correct) {
    17  		t.Fatalf("Sort returned wrong order: %s", versions)
    18  	}
    19  }
    20  
    21  func BenchmarkSort(b *testing.B) {
    22  	v100, _ := Parse("1.0.0")
    23  	v010, _ := Parse("0.1.0")
    24  	v001, _ := Parse("0.0.1")
    25  	b.ReportAllocs()
    26  	b.ResetTimer()
    27  	for n := 0; n < b.N; n++ {
    28  		Sort([]Version{v010, v100, v001})
    29  	}
    30  }
    31  

View as plain text