MCPcopy
hub / github.com/spf13/pflag / TestF32SWithDefault

Function TestF32SWithDefault

float32_slice_test.go:120–157  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

118}
119
120func TestF32SWithDefault(t *testing.T) {
121 var f32s []float32
122 f := setUpF32SFlagSetWithDefault(&f32s)
123
124 vals := []string{"1.0", "2.0"}
125 arg := fmt.Sprintf("--f32s=%s", strings.Join(vals, ","))
126 err := f.Parse([]string{arg})
127 if err != nil {
128 t.Fatal("expected no error; got", err)
129 }
130 for i, v := range f32s {
131 d64, err := strconv.ParseFloat(vals[i], 32)
132 if err != nil {
133 t.Fatalf("got error: %v", err)
134 }
135
136 d := float32(d64)
137 if d != v {
138 t.Fatalf("expected f32s[%d] to be %f but got: %f", i, d, v)
139 }
140 }
141
142 getF32S, err := f.GetFloat32Slice("f32s")
143 if err != nil {
144 t.Fatal("got an error from GetFloat32Slice():", err)
145 }
146 for i, v := range getF32S {
147 d64, err := strconv.ParseFloat(vals[i], 32)
148 if err != nil {
149 t.Fatalf("got error: %v", err)
150 }
151
152 d := float32(d64)
153 if d != v {
154 t.Fatalf("expected f32s[%d] to be %f from GetFloat32Slice but got: %f", i, d, v)
155 }
156 }
157}
158
159func TestF32SAsSliceValue(t *testing.T) {
160 var f32s []float32

Callers

nothing calls this directly

Calls 3

GetFloat32SliceMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected