diff --git a/spec/haversine/distance_spec.cr b/spec/haversine/distance_spec.cr index 519627c..bf72999 100644 --- a/spec/haversine/distance_spec.cr +++ b/spec/haversine/distance_spec.cr @@ -23,5 +23,6 @@ describe Haversine::Distance do it { (dist1 + dist2).distance.should eq(3) } it { (dist1 - dist2).distance.should eq(1) } + it { [dist1, dist2].sum.distance.should eq(3) } end end diff --git a/src/haversine/distance.cr b/src/haversine/distance.cr index 30bd6a4..81406fb 100644 --- a/src/haversine/distance.cr +++ b/src/haversine/distance.cr @@ -17,6 +17,10 @@ module Haversine distance <=> other.distance end + def self.zero : Haversine::Distance + new(0) + end + # Adds the value of `self` to *other*. def +(other : Haversine::Distance) : Haversine::Distance Haversine::Distance.new(distance + other.distance)