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

Function TestF32SDefault

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

Source from the content-addressed store, hash-verified

79}
80
81func TestF32SDefault(t *testing.T) {
82 var f32s []float32
83 f := setUpF32SFlagSetWithDefault(&f32s)
84
85 vals := []string{"0.0", "1.0"}
86
87 err := f.Parse([]string{})
88 if err != nil {
89 t.Fatal("expected no error; got", err)
90 }
91 for i, v := range f32s {
92 d64, err := strconv.ParseFloat(vals[i], 32)
93 if err != nil {
94 t.Fatalf("got error: %v", err)
95 }
96
97 d := float32(d64)
98 if d != v {
99 t.Fatalf("expected f32s[%d] to be %f but got: %f", i, d, v)
100 }
101 }
102
103 getF32S, err := f.GetFloat32Slice("f32s")
104 if err != nil {
105 t.Fatal("got an error from GetFloat32Slice():", err)
106 }
107 for i, v := range getF32S {
108 d64, err := strconv.ParseFloat(vals[i], 32)
109 if err != nil {
110 t.Fatal("got an error from GetFloat32Slice():", err)
111 }
112
113 d := float32(d64)
114 if d != v {
115 t.Fatalf("expected f32s[%d] to be %f from GetFloat32Slice but got: %f", i, d, v)
116 }
117 }
118}
119
120func TestF32SWithDefault(t *testing.T) {
121 var f32s []float32

Callers

nothing calls this directly

Calls 3

GetFloat32SliceMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected