github.com/go-playground/pkg/v5@v5.29.1/net/http/quality_value_test.go (about) 1 package httpext 2 3 import "testing" 4 5 func TestQualityValue(t *testing.T) { 6 type args struct { 7 v string 8 qv float32 9 } 10 tests := []struct { 11 name string 12 args args 13 want string 14 }{ 15 { 16 name: "in-range", 17 args: args{v: "test", qv: 0.5}, 18 want: "test;q=0.5", 19 }, 20 { 21 name: "in-range-trailing-zeros", 22 args: args{v: "test", qv: 0.500}, 23 want: "test;q=0.5", 24 }, 25 { 26 name: "greater-than-range", 27 args: args{v: "test", qv: 1.500}, 28 want: "test;q=1", 29 }, 30 { 31 name: "less-than-range", 32 args: args{v: "test", qv: 0.0000001}, 33 want: "test;q=0.001", 34 }, 35 } 36 for _, tt := range tests { 37 t.Run(tt.name, func(t *testing.T) { 38 if got := QualityValue(tt.args.v, tt.args.qv); got != tt.want { 39 t.Errorf("QualityValue() = %v, want %v", got, tt.want) 40 } 41 }) 42 } 43 }