| 1 |
// Copyright (c) 2018-2022, Maxime Soulé |
| 2 |
// All rights reserved. |
| 3 |
// |
| 4 |
// This source code is licensed under the BSD-style license found in the |
| 5 |
// LICENSE file in the root directory of this source tree. |
| 6 |
|
| 7 |
package td_test |
| 8 |
|
| 9 |
import ( |
| 10 |
"math" |
| 11 |
"testing" |
| 12 |
|
| 13 |
"github.com/maxatome/go-testdeep/td" |
| 14 |
) |
| 15 |
|
| 16 |
func TestNaN(t *testing.T) { |
| 17 |
checkOK(t, math.NaN(), td.NaN()) |
| 18 |
checkOK(t, float32(math.NaN()), td.NaN()) |
| 19 |
|
| 20 |
checkError(t, float32(12), td.NaN(), |
| 21 |
expectedError{ |
| 22 |
Message: mustBe("values differ"), |
| 23 |
Path: mustBe("DATA"), |
| 24 |
Got: mustBe("(float32) 12"), |
| 25 |
Expected: mustBe("NaN"), |
| 26 |
}) |
| 27 |
checkError(t, float64(12), td.NaN(), |
| 28 |
expectedError{ |
| 29 |
Message: mustBe("values differ"), |
| 30 |
Path: mustBe("DATA"), |
| 31 |
Got: mustBe("12.0"), |
| 32 |
Expected: mustBe("NaN"), |
| 33 |
}) |
| 34 |
|
| 35 |
checkError(t, 12, td.NaN(), |
| 36 |
expectedError{ |
| 37 |
Message: mustBe("type mismatch"), |
| 38 |
Path: mustBe("DATA"), |
| 39 |
Got: mustBe("int"), |
| 40 |
Expected: mustBe("float32 OR float64"), |
| 41 |
}) |
| 42 |
} |
| 43 |
|
| 44 |
func TestNotNaN(t *testing.T) { |
| 45 |
checkOK(t, float64(12), td.NotNaN()) |
| 46 |
checkOK(t, float32(12), td.NotNaN()) |
| 47 |
|
| 48 |
checkError(t, float32(math.NaN()), td.NotNaN(), |
| 49 |
expectedError{ |
| 50 |
Message: mustBe("values differ"), |
| 51 |
Path: mustBe("DATA"), |
| 52 |
Got: mustBe("(float32) NaN"), |
| 53 |
Expected: mustBe("not NaN"), |
| 54 |
}) |
| 55 |
checkError(t, math.NaN(), td.NotNaN(), |
| 56 |
expectedError{ |
| 57 |
Message: mustBe("values differ"), |
| 58 |
Path: mustBe("DATA"), |
| 59 |
Got: mustBe("NaN"), |
| 60 |
Expected: mustBe("not NaN"), |
| 61 |
}) |
| 62 |
|
| 63 |
checkError(t, 12, td.NotNaN(), |
| 64 |
expectedError{ |
| 65 |
Message: mustBe("type mismatch"), |
| 66 |
Path: mustBe("DATA"), |
| 67 |
Got: mustBe("int"), |
| 68 |
Expected: mustBe("float32 OR float64"), |
| 69 |
}) |
| 70 |
} |
| 71 |
|
| 72 |
func TestNaNTypeBehind(t *testing.T) { |
| 73 |
equalTypes(t, td.NaN(), nil) |
| 74 |
equalTypes(t, td.NotNaN(), nil) |
| 75 |
} |