From: Alexandre Terrasa Date: Mon, 24 Nov 2014 18:44:23 +0000 (-0500) Subject: range: implements `==` method on ranges X-Git-Tag: v0.6.11~16^2~3 X-Git-Url: http://nitlanguage.org range: implements `==` method on ranges Signed-off-by: Alexandre Terrasa --- diff --git a/lib/standard/collection/range.nit b/lib/standard/collection/range.nit index 27dd3f4..665b263 100644 --- a/lib/standard/collection/range.nit +++ b/lib/standard/collection/range.nit @@ -95,6 +95,20 @@ class Range[E: Discrete] last = to.predecessor(1) after = to end + + # Two ranges are equals if they have the same first and last elements. + # + # var a = new Range[Int](10, 15) + # var b = new Range[Int].without_last(10, 15) + # assert a == [10..15] + # assert a == [10..16[ + # assert not a == [10..15[ + # assert b == [10..15[ + # assert b == [10..14] + # assert not b == [10..15] + redef fun ==(o) do + return o isa Range[E] and self.first == o.first and self.last == o.last + end end private class IteratorRange[E: Discrete]