| 85 | } |
| 86 | |
| 87 | func TestStatic_Float(t *testing.T) { |
| 88 | tests := []struct { |
| 89 | arg any |
| 90 | want float64 |
| 91 | }{ |
| 92 | {arg: -math.MaxFloat64}, |
| 93 | {arg: -1.0}, |
| 94 | {arg: 0.0}, |
| 95 | {arg: 10.0 + math.SmallestNonzeroFloat64}, |
| 96 | {arg: 1.0}, |
| 97 | {arg: math.MaxFloat64}, |
| 98 | {arg: int(3117), want: 3117.0}, |
| 99 | {arg: time.Duration(101), want: 101.0}, |
| 100 | {arg: "test", want: math.NaN()}, |
| 101 | {arg: true, want: math.NaN()}, |
| 102 | {arg: StatusError, want: math.NaN()}, |
| 103 | {arg: KindServer, want: math.NaN()}, |
| 104 | {arg: []int{1}, want: math.NaN()}, |
| 105 | {arg: []float64{1.0}, want: math.NaN()}, |
| 106 | {arg: []bool{true}, want: math.NaN()}, |
| 107 | {arg: []string{"test"}, want: math.NaN()}, |
| 108 | } |
| 109 | |
| 110 | for _, tt := range tests { |
| 111 | t.Run(testName(tt.arg), func(t *testing.T) { |
| 112 | static := newStatic(tt.arg) |
| 113 | f := static.Float() |
| 114 | |
| 115 | if static.Type == TypeFloat { |
| 116 | assert.Equal(t, tt.arg, f) |
| 117 | } else if math.IsNaN(tt.want) { |
| 118 | assert.True(t, math.IsNaN(f)) |
| 119 | } else { |
| 120 | assert.Equal(t, tt.want, f) |
| 121 | } |
| 122 | }) |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | func TestStatic_String(t *testing.T) { |
| 127 | tests := []struct { |