-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathelementary_test.rb
More file actions
56 lines (42 loc) · 1.36 KB
/
elementary_test.rb
File metadata and controls
56 lines (42 loc) · 1.36 KB
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
require "./test/test_helper"
class ElementaryTest < Minitest::Test
include Primitives
@@delta = 1e-5
def setup
@point = Elementary::Point.new(2.3, 5.1)
@line_segment = Elementary::LineSegment.new(Elementary::Point.new(2.2, 3.3),Elementary::Point.new(5.5, 6.6))
end
def test_point_attributes_set_correctly_on_instance_create
assert_in_delta 2.3, @point.x, @@delta
assert_in_delta 5.1, @point.y, @@delta
end
def test_point_initializer_rises_type_error_if_arguments_dont_satisfy_the_requirement_type
assert_raises TypeError do
Elementary::Point.new(1.2, "3")
end
end
def test_move_method_correctly_moved_the_point
p = @point.move 5, 5
assert_in_delta 7.3, p.x, @@delta
assert_in_delta 10.1, p.y, @@delta
end
def test_dangerous_move_method_correctly_moved_the_point
p = @point.dup
p.move! 5, 5
assert_in_delta 7.3, p.x, @@delta
assert_in_delta 10.1, p.y, @@delta
end
def test_move_method_doesnt_affect_point_instance_on_which_it_was_applied
original = @point
_ = original.move 777, 777
assert_in_delta 2.3, original.x, @@delta
assert_in_delta 5.1, original.y, @@delta
end
def test_line_length
length = @line_segment.length
assert_in_delta 4.66690, length, @@delta
end
def test_to_straight_line
# test will be added when straight line class is approved
end
end