|
| 1 | +package eppoclient |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestToFloat64(t *testing.T) { |
| 8 | + tests := []struct { |
| 9 | + name string |
| 10 | + input interface{} |
| 11 | + expected float64 |
| 12 | + expectErr bool |
| 13 | + }{ |
| 14 | + {"Float64Input", 123.456, 123.456, false}, |
| 15 | + {"StringInputValid", "789.012", 789.012, false}, |
| 16 | + {"StringInputInvalid", "abc", 0, true}, |
| 17 | + {"SemVerInputInvalid", "1.2.3", 0, true}, |
| 18 | + {"BoolInput", true, 0, true}, |
| 19 | + {"IntInput", 123, 0, true}, |
| 20 | + } |
| 21 | + |
| 22 | + for _, tt := range tests { |
| 23 | + t.Run(tt.name, func(t *testing.T) { |
| 24 | + result, err := ToFloat64(tt.input) |
| 25 | + if (err != nil) != tt.expectErr { |
| 26 | + t.Errorf("ToFloat64(%v) error = %v, expectErr %v", tt.input, err, tt.expectErr) |
| 27 | + return |
| 28 | + } |
| 29 | + if !tt.expectErr && result != tt.expected { |
| 30 | + t.Errorf("ToFloat64(%v) = %v, want %v", tt.input, result, tt.expected) |
| 31 | + } |
| 32 | + }) |
| 33 | + } |
| 34 | +} |
0 commit comments