File: acosh.rb

package info (click to toggle)
jruby 9.3.9.0%2Bds-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,856 kB
  • sloc: ruby: 517,823; java: 260,094; xml: 31,930; ansic: 5,777; yacc: 4,973; sh: 1,163; makefile: 105; jsp: 48; tcl: 40; exp: 11
file content (37 lines) | stat: -rw-r--r-- 1,760 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require_relative '../fixtures/classes'

describe :complex_math_acosh, shared: true do
  it "returns the principle value of the inverse hyperbolic cosine of the argument" do
    @object.send(:acosh, 14.2).should be_close(3.345146999647, TOLERANCE)
    @object.send(:acosh, 1.0).should be_close(0.0, TOLERANCE)
  end

  it "returns the principle value of the inverse hyperbolic cosine for numbers less than 1.0 as a Complex number" do
    @object.send(:acosh, 1.0 - TOLERANCE).should be_close(Complex(0.0, 0.00774598605746135), TOLERANCE)
    @object.send(:acosh, 0).should be_close(Complex(0.0, 1.5707963267949), TOLERANCE)
    @object.send(:acosh, -1.0).should be_close(Complex(0.0, 3.14159265358979), TOLERANCE)
  end

  it "returns the principle value of the inverse hyperbolic cosine for Complex numbers" do
    @object.send(:acosh, Complex(3, 4))
    @object.send(:acosh, Complex(3, 4)).imaginary.should be_close(0.93681246115572, TOLERANCE)
    @object.send(:acosh, Complex(3, 4)).real.should be_close(2.305509031243477, TOLERANCE)
  end
end

describe :complex_math_acosh_bang, shared: true do
  it "returns the principle value of the inverse hyperbolic cosine of the argument" do
    @object.send(:acosh!, 14.2).should be_close(3.345146999647, TOLERANCE)
    @object.send(:acosh!, 1.0).should be_close(0.0, TOLERANCE)
  end

  it "raises Errno::EDOM for numbers less than 1.0" do
    -> { @object.send(:acosh!, 1.0 - TOLERANCE) }.should raise_error(Errno::EDOM)
    -> { @object.send(:acosh!, 0) }.should raise_error(Errno::EDOM)
    -> { @object.send(:acosh!, -1.0) }.should raise_error(Errno::EDOM)
  end

  it "raises a TypeError when passed a Complex number" do
    -> { @object.send(:acosh!, Complex(4, 5)) }.should raise_error(TypeError)
  end
end