Skip to content

Commit 3658d14

Browse files
committed
stdlib: simplify tests for conversions of special floating point values
1 parent 423c1f0 commit 3658d14

File tree

1 file changed

+8
-37
lines changed

1 file changed

+8
-37
lines changed

validation-test/stdlib/FloatingPointConversion.swift.gyb

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import StdlibUnittest
1212

13-
1413
%{
1514

1615
floatNameToSignificandBits = { 'Float32':24, 'Float64':53, 'Float80':64 }
@@ -110,44 +109,16 @@ FloatingPointConversionFailures.test("${OtherFloat}To${Self}FailableConversion/d
110109

111110
% end
112111

113-
FloatingPointConversionTruncations.test("${OtherFloat}To${Self}Conversion/dest=NaN") {
114-
let input = ${OtherFloat}.nan
115-
var result = ${Self}(input)
116-
var resultConvertedBack = ${OtherFloat}(result)
117-
expectTrue(input.isNaN)
118-
expectTrue(resultConvertedBack.isNaN)
112+
FloatingPointConversionTruncations.test("${OtherFloat}To${Self}Conversion/special") {
113+
expectEqual( ${Self}.infinity, ${Self}( ${OtherFloat}.infinity))
114+
expectEqual(-${Self}.infinity, ${Self}(-${OtherFloat}.infinity))
115+
expectTrue(${Self}(${OtherFloat}.nan).isNaN)
119116
}
120117

121-
FloatingPointConversionFailures.test("${OtherFloat}To${Self}Conversion/dest=NaN") {
122-
let input = ${OtherFloat}.nan
123-
var result = ${Self}(exactly: input)
124-
expectEmpty(result)
125-
}
126-
127-
FloatingPointConversionTruncations.test("${OtherFloat}To${Self}Conversion/dest=inf") {
128-
let input = ${OtherFloat}.infinity
129-
var result = ${Self}(input)
130-
var resultConvertedBack = ${OtherFloat}(result)
131-
expectEqual(input, resultConvertedBack)
132-
}
133-
134-
FloatingPointConversionFailures.test("${OtherFloat}To${Self}Conversion/dest=inf") {
135-
let input = ${OtherFloat}.infinity
136-
var result = ${Self}(exactly: input)
137-
expectEqual(${Self}.infinity, result)
138-
}
139-
140-
FloatingPointConversionTruncations.test("${OtherFloat}To${Self}Conversion/dest=-inf") {
141-
let input = -${OtherFloat}.infinity
142-
var result = ${Self}(input)
143-
var resultConvertedBack = ${OtherFloat}(result)
144-
expectEqual(input, resultConvertedBack)
145-
}
146-
147-
FloatingPointConversionFailures.test("${OtherFloat}To${Self}Conversion/dest=-inf") {
148-
let input = -${OtherFloat}.infinity
149-
var result = ${Self}(exactly: input)
150-
expectEqual(-${Self}.infinity, result)
118+
FloatingPointConversionFailures.test("${OtherFloat}To${Self}Conversion/special") {
119+
expectEqual( ${Self}.infinity, ${Self}(exactly: ${OtherFloat}.infinity))
120+
expectEqual(-${Self}.infinity, ${Self}(exactly: -${OtherFloat}.infinity))
121+
expectEmpty(${Self}(exactly: ${OtherFloat}.nan))
151122
}
152123

153124
% if OtherFloat == 'Float80':

0 commit comments

Comments
 (0)