| 168 | } |
| 169 | |
| 170 | func (s *OptionsTestSuite) TestGetFloat() { |
| 171 | o := options.New() |
| 172 | o.Set("float64", 3.14) |
| 173 | o.Set("float32", float32(2.71)) |
| 174 | o.Set("int", 42) |
| 175 | o.Set("int16", int16(16)) |
| 176 | o.Set("string", "not_a_float") |
| 177 | |
| 178 | // Float types |
| 179 | s.Require().InDelta(3.14, o.GetFloat("float64", 0.0), 0.000001) |
| 180 | s.Require().InDelta(2.71, o.GetFloat("float32", 0.0), 0.000001) |
| 181 | |
| 182 | // Integer types |
| 183 | s.Require().InDelta(42.0, o.GetFloat("int", 0.0), 0.000001) |
| 184 | s.Require().InDelta(16.0, o.GetFloat("int16", 0.0), 0.000001) |
| 185 | |
| 186 | // Non-existing key |
| 187 | s.Require().InDelta(1.618, o.GetFloat("non_existing_key", 1.618), 0.000001) |
| 188 | |
| 189 | // Type mismatch |
| 190 | s.Require().Panics(func() { |
| 191 | o.GetFloat("string", 0.0) |
| 192 | }) |
| 193 | } |
| 194 | |
| 195 | func testOptions() *options.Options { |
| 196 | o := options.New() |