|
| 1 | +require_relative '../../spec_helper' |
| 2 | +require_relative 'fixtures/classes' |
| 3 | + |
| 4 | +ruby_version_is "4.0" do |
| 5 | + describe "Math.log1p" do |
| 6 | + it "calculates Math.log(1 + arg)" do |
| 7 | + Math.log1p(3).should == Math.log(1 + 3) |
| 8 | + end |
| 9 | + |
| 10 | + it "preserves precision that can be lost otherwise" do |
| 11 | + Math.log1p(1e-16).should be_close(1.0e-16, TOLERANCE) |
| 12 | + Math.log1p(1e-16).should != 0.0 |
| 13 | + end |
| 14 | + |
| 15 | + it "raises an Math::DomainError if the argument is less than 1" do |
| 16 | + -> { Math.log1p(-1-1e-15) }.should raise_error(Math::DomainError, "Numerical argument is out of domain - log1p") |
| 17 | + end |
| 18 | + |
| 19 | + it "raises a TypeError if the argument cannot be coerced with Float()" do |
| 20 | + -> { Math.log1p("test") }.should raise_error(TypeError, "can't convert String into Float") |
| 21 | + end |
| 22 | + |
| 23 | + it "raises a TypeError for numerical values passed as string" do |
| 24 | + -> { Math.log1p("10") }.should raise_error(TypeError, "can't convert String into Float") |
| 25 | + end |
| 26 | + |
| 27 | + it "does not accept a second argument for the base" do |
| 28 | + -> { Math.log1p(9, 3) }.should raise_error(ArgumentError, "wrong number of arguments (given 2, expected 1)") |
| 29 | + end |
| 30 | + |
| 31 | + it "returns NaN given NaN" do |
| 32 | + Math.log1p(nan_value).nan?.should be_true |
| 33 | + end |
| 34 | + |
| 35 | + it "raises a TypeError if the argument is nil" do |
| 36 | + -> { Math.log1p(nil) }.should raise_error(TypeError, "can't convert nil into Float") |
| 37 | + end |
| 38 | + |
| 39 | + it "accepts any argument that can be coerced with Float()" do |
| 40 | + Math.log1p(MathSpecs::Float.new).should be_close(0.6931471805599453, TOLERANCE) |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + describe "Math#log1p" do |
| 45 | + it "is accessible as a private instance method" do |
| 46 | + IncludesMath.new.send(:log1p, 4.21).should be_close(1.65057985576528, TOLERANCE) |
| 47 | + end |
| 48 | + end |
| 49 | +end |
0 commit comments