File: atan2.rb

package info (click to toggle)
ruby2.7 2.7.4-1%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 112,576 kB
  • sloc: ruby: 849,454; ansic: 697,834; yacc: 45,100; xml: 25,367; pascal: 10,051; javascript: 6,575; sh: 3,848; makefile: 759; cpp: 713; asm: 333; python: 295; lisp: 97; sed: 94; perl: 62; awk: 36
file content (34 lines) | stat: -rw-r--r-- 1,698 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
require_relative '../fixtures/classes'

describe :complex_math_atan2, shared: true do
  it "returns the arc tangent of the passed arguments" do
    @object.send(:atan2, 4.2, 0.3).should be_close(1.49948886200961, TOLERANCE)
    @object.send(:atan2, 0.0, 1.0).should be_close(0.0, TOLERANCE)
    @object.send(:atan2, -9.1, 3.2).should be_close(-1.23265379809025, TOLERANCE)
    @object.send(:atan2, 7.22, -3.3).should be_close(1.99950888779256, TOLERANCE)
  end

  it "returns the arc tangent for two Complex numbers" do
    CMath.atan2(Complex(3, 4), Complex(3.5, -4)).should be_close(Complex(-0.641757436698881, 1.10829873031207), TOLERANCE)
  end

  it "returns the arc tangent for Complex and real numbers" do
    CMath.atan2(Complex(3, 4), -7).should be_close(Complex(2.61576754731561, -0.494290673139855), TOLERANCE)
    CMath.atan2(5, Complex(3.5, -4)).should be_close(Complex(0.739102348493673, 0.487821626522923), TOLERANCE)
  end
end

describe :complex_math_atan2_bang, shared: true do
  it "returns the arc tangent of the passed arguments" do
    @object.send(:atan2!, 4.2, 0.3).should be_close(1.49948886200961, TOLERANCE)
    @object.send(:atan2!, 0.0, 1.0).should be_close(0.0, TOLERANCE)
    @object.send(:atan2!, -9.1, 3.2).should be_close(-1.23265379809025, TOLERANCE)
    @object.send(:atan2!, 7.22, -3.3).should be_close(1.99950888779256, TOLERANCE)
  end

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