File: sort_test.go

package info (click to toggle)
golang-github-blang-semver 3.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, experimental, sid
  • size: 176 kB
  • sloc: makefile: 3
file content (30 lines) | stat: -rw-r--r-- 582 bytes parent folder | download | duplicates (4)
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
package semver

import (
	"reflect"
	"testing"
)

func TestSort(t *testing.T) {
	v100, _ := Parse("1.0.0")
	v010, _ := Parse("0.1.0")
	v001, _ := Parse("0.0.1")
	versions := []Version{v010, v100, v001}
	Sort(versions)

	correct := []Version{v001, v010, v100}
	if !reflect.DeepEqual(versions, correct) {
		t.Fatalf("Sort returned wrong order: %s", versions)
	}
}

func BenchmarkSort(b *testing.B) {
	v100, _ := Parse("1.0.0")
	v010, _ := Parse("0.1.0")
	v001, _ := Parse("0.0.1")
	b.ReportAllocs()
	b.ResetTimer()
	for n := 0; n < b.N; n++ {
		Sort([]Version{v010, v100, v001})
	}
}