Skip to content

Commit

Permalink
add operations
Browse files Browse the repository at this point in the history
  • Loading branch information
mamantoha committed Apr 30, 2024
1 parent 6b31331 commit df64a82
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spec/ring_area_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@ describe RingArea do
it { (ring_area_1 == ring_area_2).should be_false }
it { (ring_area_1 > ring_area_2).should be_true }
end

describe "operations" do
ring_area_1 = RingArea.ring_area(coordinates)
ring_area_2 = RingArea.ring_area(other_coordinates)

it { (ring_area_1 + ring_area_2).should be_a(RingArea::Area) }
it { (ring_area_1 + ring_area_2).to_meters.should eq(7798346482558.176) }
it { (ring_area_1 - ring_area_2).to_meters.should eq(7699436737396.736) }
end
end
10 changes: 10 additions & 0 deletions src/ring_area/area.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,15 @@ module RingArea
def <=>(other : RingArea::Area)
area <=> other.area
end

# Adds the value of `self` to *other*.
def +(other : RingArea::Area) : RingArea::Area
RingArea::Area.new(self.area + other.area)
end

# Removes the value of *other* from `self`.
def -(other : RingArea::Area) : RingArea::Area
RingArea::Area.new(self.area - other.area)
end
end
end

0 comments on commit df64a82

Please sign in to comment.