1
exercism fetch ruby complex-numbers

complex_numbers_test.rb

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
require 'minitest/autorun'
require_relative 'complex_numbers'

# Common test data version: 1.0.0 '117d062'
class ComplexNumbersTest < Minitest::Test
  def test_imaginary_unit
    # skip
    expected = ComplexNumber.new(-1, 0)
    assert_equal expected, ComplexNumber.new(0, 1) * ComplexNumber.new(0, 1)
  end

  def test_add_purely_real_numbers
    skip
    expected = ComplexNumber.new(3, 0)
    assert_equal expected, ComplexNumber.new(1, 0) + ComplexNumber.new(2, 0)
  end

  def test_add_purely_imaginary_numbers
    skip
    expected = ComplexNumber.new(0, 3)
    assert_equal expected, ComplexNumber.new(0, 1) + ComplexNumber.new(0, 2)
  end

  def test_add_numbers_with_real_and_imaginary_part
    skip
    expected = ComplexNumber.new(4, 6)
    assert_equal expected, ComplexNumber.new(1, 2) + ComplexNumber.new(3, 4)
  end

  def test_subtract_purely_real_numbers
    skip
    expected = ComplexNumber.new(-1, 0)
    assert_equal expected, ComplexNumber.new(1, 0) - ComplexNumber.new(2, 0)
  end

  def test_subtract_purely_imaginary_numbers
    skip
    expected = ComplexNumber.new(0, -1)
    assert_equal expected, ComplexNumber.new(0, 1) - ComplexNumber.new(0, 2)
  end

  def test_subtract_numbers_with_real_and_imaginary_part
    skip
    expected = ComplexNumber.new(-2, -2)
    assert_equal expected, ComplexNumber.new(1, 2) - ComplexNumber.new(3, 4)
  end

  def test_multiply_purely_real_numbers
    skip
    expected = ComplexNumber.new(2, 0)
    assert_equal expected, ComplexNumber.new(1, 0) * ComplexNumber.new(2, 0)
  end

  def test_multiply_purely_imaginary_numbers
    skip
    expected = ComplexNumber.new(-2, 0)
    assert_equal expected, ComplexNumber.new(0, 1) * ComplexNumber.new(0, 2)
  end

  def test_multiply_numbers_with_real_and_imaginary_part
    skip
    expected = ComplexNumber.new(-5, 10)
    assert_equal expected, ComplexNumber.new(1, 2) * ComplexNumber.new(3, 4)
  end

  def test_divide_purely_real_numbers
    skip
    expected = ComplexNumber.new(0.5, 0)
    assert_equal expected, ComplexNumber.new(1, 0) / ComplexNumber.new(2, 0)
  end

  def test_divide_purely_imaginary_numbers
    skip
    expected = ComplexNumber.new(0.5, 0)
    assert_equal expected, ComplexNumber.new(0, 1) / ComplexNumber.new(0, 2)
  end

  def test_divide_numbers_with_real_and_imaginary_part
    skip
    expected = ComplexNumber.new(0.44, 0.08)
    assert_equal expected, ComplexNumber.new(1, 2) / ComplexNumber.new(3, 4)
  end

  def test_absolute_value_of_a_positive_purely_real_number
    skip
    expected = 5
    assert_equal expected, ComplexNumber.new(5, 0).abs
  end

  def test_absolute_value_of_a_negative_purely_real_number
    skip
    expected = 5
    assert_equal expected, ComplexNumber.new(-5, 0).abs
  end

  def test_absolute_value_of_a_purely_imaginary_number_with_positive_imaginary_part
    skip
    expected = 5
    assert_equal expected, ComplexNumber.new(0, 5).abs
  end

  def test_absolute_value_of_a_purely_imaginary_number_with_negative_imaginary_part
    skip
    expected = 5
    assert_equal expected, ComplexNumber.new(0, -5).abs
  end

  def test_absolute_value_of_a_number_with_real_and_imaginary_part
    skip
    expected = 5
    assert_equal expected, ComplexNumber.new(3, 4).abs
  end

  def test_conjugate_a_purely_real_number
    skip
    expected = ComplexNumber.new(5, 0)
    assert_equal expected, ComplexNumber.new(5, 0).conjugate
  end

  def test_conjugate_a_purely_imaginary_number
    skip
    expected = ComplexNumber.new(0, -5)
    assert_equal expected, ComplexNumber.new(0, 5).conjugate
  end

  def test_conjugate_a_number_with_real_and_imaginary_part
    skip
    expected = ComplexNumber.new(1, -1)
    assert_equal expected, ComplexNumber.new(1, 1).conjugate
  end

  def test_real_part_of_a_purely_real_number
    skip
    expected = 1
    assert_equal expected, ComplexNumber.new(1, 0).real
  end

  def test_real_part_of_a_purely_imaginary_number
    skip
    expected = 0
    assert_equal expected, ComplexNumber.new(0, 1).real
  end

  def test_real_part_of_a_number_with_real_and_imaginary_part
    skip
    expected = 1
    assert_equal expected, ComplexNumber.new(1, 2).real
  end

  def test_imaginary_part_of_a_purely_real_number
    skip
    expected = 0
    assert_equal expected, ComplexNumber.new(1, 0).imaginary
  end

  def test_imaginary_part_of_a_purely_imaginary_number
    skip
    expected = 1
    assert_equal expected, ComplexNumber.new(0, 1).imaginary
  end

  def test_imaginary_part_of_a_number_with_real_and_imaginary_part
    skip
    expected = 2
    assert_equal expected, ComplexNumber.new(1, 2).imaginary
  end

  def test_eulers_identityformula
    skip
    expected = ComplexNumber.new(-1, 0)
    assert_equal expected, ComplexNumber.new(0, Math::PI).exp
  end

  def test_exponential_of_0
    skip
    expected = ComplexNumber.new(1, 0)
    assert_equal expected, ComplexNumber.new(0, 0).exp
  end

  def test_exponential_of_a_purely_real_number
    skip
    expected = ComplexNumber.new(Math::E, 0)
    assert_equal expected, ComplexNumber.new(1, 0).exp
  end

  # Problems in exercism evolve over time, as we find better ways to ask
  # questions.
  # The version number refers to the version of the problem you solved,
  # not your solution.
  #
  # Define a constant named VERSION inside of the top level BookKeeping
  # module, which may be placed near the end of your file.
  #
  # In your file, it will look like this:
  #
  # module BookKeeping
  #   VERSION = 1 # Where the version number matches the one in the test.
  # end
  #
  # If you are curious, read more about constants on RubyDoc:
  # http://ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/constants.html

  def test_bookkeeping
    skip
    assert_equal 1, BookKeeping::VERSION
  end
end