From c0719af7d873c5f40226577aa8ce79b9d85c06aa Mon Sep 17 00:00:00 2001 From: Stephen Ierodiaconou Date: Thu, 13 Oct 2022 15:12:28 +0200 Subject: [PATCH 1/2] Add test for Float#to_i raising FloatDomainError when NaN --- core/float/shared/to_i.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/core/float/shared/to_i.rb b/core/float/shared/to_i.rb index 960295f095..79a12afcfd 100644 --- a/core/float/shared/to_i.rb +++ b/core/float/shared/to_i.rb @@ -1,5 +1,6 @@ describe :float_to_i, shared: true do it "returns self truncated to an Integer" do + -> { (0.0 / 0.0).send(@method) }.should raise_error(FloatDomainError) 899.2.send(@method).should eql(899) -1.122256e-45.send(@method).should eql(0) 5_213_451.9201.send(@method).should eql(5213451) From aebaac699c663282b9e9c39364f1e432b15e8cb5 Mon Sep 17 00:00:00 2001 From: Stephen Ierodiaconou Date: Thu, 13 Oct 2022 15:47:40 +0200 Subject: [PATCH 2/2] Move case to its own example and use nan_value helper --- core/float/shared/to_i.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/float/shared/to_i.rb b/core/float/shared/to_i.rb index 79a12afcfd..33b32ca533 100644 --- a/core/float/shared/to_i.rb +++ b/core/float/shared/to_i.rb @@ -1,6 +1,5 @@ describe :float_to_i, shared: true do it "returns self truncated to an Integer" do - -> { (0.0 / 0.0).send(@method) }.should raise_error(FloatDomainError) 899.2.send(@method).should eql(899) -1.122256e-45.send(@method).should eql(0) 5_213_451.9201.send(@method).should eql(5213451) @@ -8,4 +7,8 @@ -9223372036854775808.1.send(@method).should eql(-9223372036854775808) 9223372036854775808.1.send(@method).should eql(9223372036854775808) end + + it "raises a FloatDomainError for NaN" do + -> { nan_value.send(@method) }.should raise_error(FloatDomainError) + end end