|
| 1 | +package fp |
| 2 | + |
| 3 | +import ( |
| 4 | + _ "errors" |
| 5 | + "reflect" |
| 6 | + "testing" |
| 7 | +) |
| 8 | + |
| 9 | +func TestPosInt(t *testing.T) { |
| 10 | + r := PosInt(1) |
| 11 | + if !r { |
| 12 | + t.Errorf("PosInt failed. Expected=true, actual=false") |
| 13 | + t.Errorf(reflect.String.String()) |
| 14 | + } |
| 15 | + |
| 16 | + r = PosInt(-1) |
| 17 | + if r { |
| 18 | + t.Errorf("PosInt failed. Expected=false, actual=true") |
| 19 | + } |
| 20 | + |
| 21 | + var zero int |
| 22 | + var one int = 1 |
| 23 | + rPtr := PosIntPtr(&one) |
| 24 | + if !rPtr { |
| 25 | + t.Errorf("PosIntPtr failed. Expected=true, actual=false") |
| 26 | + } |
| 27 | + |
| 28 | + rPtr = PosIntPtr(&zero) |
| 29 | + if rPtr { |
| 30 | + t.Errorf("PosIntPtr failed. Expected=false, actual=true") |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +func TestPosInt64(t *testing.T) { |
| 35 | + r := PosInt64(1) |
| 36 | + if !r { |
| 37 | + t.Errorf("PosInt64 failed. Expected=true, actual=false") |
| 38 | + t.Errorf(reflect.String.String()) |
| 39 | + } |
| 40 | + |
| 41 | + r = PosInt64(-1) |
| 42 | + if r { |
| 43 | + t.Errorf("PosInt64 failed. Expected=false, actual=true") |
| 44 | + } |
| 45 | + |
| 46 | + var zero int64 |
| 47 | + var one int64 = 1 |
| 48 | + rPtr := PosInt64Ptr(&one) |
| 49 | + if !rPtr { |
| 50 | + t.Errorf("PosInt64Ptr failed. Expected=true, actual=false") |
| 51 | + } |
| 52 | + |
| 53 | + rPtr = PosInt64Ptr(&zero) |
| 54 | + if rPtr { |
| 55 | + t.Errorf("PosInt64Ptr failed. Expected=false, actual=true") |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +func TestPosInt32(t *testing.T) { |
| 60 | + r := PosInt32(1) |
| 61 | + if !r { |
| 62 | + t.Errorf("PosInt32 failed. Expected=true, actual=false") |
| 63 | + t.Errorf(reflect.String.String()) |
| 64 | + } |
| 65 | + |
| 66 | + r = PosInt32(-1) |
| 67 | + if r { |
| 68 | + t.Errorf("PosInt32 failed. Expected=false, actual=true") |
| 69 | + } |
| 70 | + |
| 71 | + var zero int32 |
| 72 | + var one int32 = 1 |
| 73 | + rPtr := PosInt32Ptr(&one) |
| 74 | + if !rPtr { |
| 75 | + t.Errorf("PosInt32Ptr failed. Expected=true, actual=false") |
| 76 | + } |
| 77 | + |
| 78 | + rPtr = PosInt32Ptr(&zero) |
| 79 | + if rPtr { |
| 80 | + t.Errorf("PosInt32Ptr failed. Expected=false, actual=true") |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +func TestPosInt16(t *testing.T) { |
| 85 | + r := PosInt16(1) |
| 86 | + if !r { |
| 87 | + t.Errorf("PosInt16 failed. Expected=true, actual=false") |
| 88 | + t.Errorf(reflect.String.String()) |
| 89 | + } |
| 90 | + |
| 91 | + r = PosInt16(-1) |
| 92 | + if r { |
| 93 | + t.Errorf("PosInt16 failed. Expected=false, actual=true") |
| 94 | + } |
| 95 | + |
| 96 | + var zero int16 |
| 97 | + var one int16 = 1 |
| 98 | + rPtr := PosInt16Ptr(&one) |
| 99 | + if !rPtr { |
| 100 | + t.Errorf("PosInt16Ptr failed. Expected=true, actual=false") |
| 101 | + } |
| 102 | + |
| 103 | + rPtr = PosInt16Ptr(&zero) |
| 104 | + if rPtr { |
| 105 | + t.Errorf("PosInt16Ptr failed. Expected=false, actual=true") |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +func TestPosInt8(t *testing.T) { |
| 110 | + r := PosInt8(1) |
| 111 | + if !r { |
| 112 | + t.Errorf("PosInt8 failed. Expected=true, actual=false") |
| 113 | + t.Errorf(reflect.String.String()) |
| 114 | + } |
| 115 | + |
| 116 | + r = PosInt8(-1) |
| 117 | + if r { |
| 118 | + t.Errorf("PosInt8 failed. Expected=false, actual=true") |
| 119 | + } |
| 120 | + |
| 121 | + var zero int8 |
| 122 | + var one int8 = 1 |
| 123 | + rPtr := PosInt8Ptr(&one) |
| 124 | + if !rPtr { |
| 125 | + t.Errorf("PosInt8Ptr failed. Expected=true, actual=false") |
| 126 | + } |
| 127 | + |
| 128 | + rPtr = PosInt8Ptr(&zero) |
| 129 | + if rPtr { |
| 130 | + t.Errorf("PosInt8Ptr failed. Expected=false, actual=true") |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +func TestPosFloat32(t *testing.T) { |
| 135 | + r := PosFloat32(1) |
| 136 | + if !r { |
| 137 | + t.Errorf("PosFloat32 failed. Expected=true, actual=false") |
| 138 | + t.Errorf(reflect.String.String()) |
| 139 | + } |
| 140 | + |
| 141 | + r = PosFloat32(-1) |
| 142 | + if r { |
| 143 | + t.Errorf("PosFloat32 failed. Expected=false, actual=true") |
| 144 | + } |
| 145 | + |
| 146 | + var zero float32 |
| 147 | + var one float32 = 1 |
| 148 | + rPtr := PosFloat32Ptr(&one) |
| 149 | + if !rPtr { |
| 150 | + t.Errorf("PosFloat32Ptr failed. Expected=true, actual=false") |
| 151 | + } |
| 152 | + |
| 153 | + rPtr = PosFloat32Ptr(&zero) |
| 154 | + if rPtr { |
| 155 | + t.Errorf("PosFloat32Ptr failed. Expected=false, actual=true") |
| 156 | + } |
| 157 | +} |
| 158 | + |
| 159 | +func TestPosFloat64(t *testing.T) { |
| 160 | + r := PosFloat64(1) |
| 161 | + if !r { |
| 162 | + t.Errorf("PosFloat64 failed. Expected=true, actual=false") |
| 163 | + t.Errorf(reflect.String.String()) |
| 164 | + } |
| 165 | + |
| 166 | + r = PosFloat64(-1) |
| 167 | + if r { |
| 168 | + t.Errorf("PosFloat64 failed. Expected=false, actual=true") |
| 169 | + } |
| 170 | + |
| 171 | + var zero float64 |
| 172 | + var one float64 = 1 |
| 173 | + rPtr := PosFloat64Ptr(&one) |
| 174 | + if !rPtr { |
| 175 | + t.Errorf("PosFloat64Ptr failed. Expected=true, actual=false") |
| 176 | + } |
| 177 | + |
| 178 | + rPtr = PosFloat64Ptr(&zero) |
| 179 | + if rPtr { |
| 180 | + t.Errorf("PosFloat64Ptr failed. Expected=false, actual=true") |
| 181 | + } |
| 182 | +} |
0 commit comments