From b77f872bb976251d6cb09eda3e08b4542b9f35bc Mon Sep 17 00:00:00 2001 From: Anton Maminov Date: Tue, 30 Apr 2024 12:25:57 +0300 Subject: [PATCH] more operations --- spec/haversine/distance_spec.cr | 1 + src/haversine/distance.cr | 4 ++++ 2 files changed, 5 insertions(+) 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)