Skip to content

Commit

Permalink
Showing 6 changed files with 39 additions and 0 deletions.
7 changes: 7 additions & 0 deletions spec/std/complex_spec.cr
Original file line number Diff line number Diff line change
@@ -168,4 +168,11 @@ describe "Complex" do
c = Complex.new(4, 6.2)
c.clone.should eq(c)
end

it "test zero?" do
Complex.new(0, 0).zero?.should eq true
Complex.new(0, 3.4).zero?.should eq false
Complex.new(1.2, 0).zero?.should eq false
Complex.new(1.2, 3.4).zero?.should eq false
end
end
9 changes: 9 additions & 0 deletions spec/std/number_spec.cr
Original file line number Diff line number Diff line change
@@ -166,6 +166,15 @@ describe "Number" do
ary[2].should eq(300.to_u8)
end

it "test zero?" do
0.zero?.should eq true
0.0.zero?.should eq true
0f32.zero?.should eq true
1.zero?.should eq false
1.0.zero?.should eq false
1f32.zero?.should eq false
end

describe "step" do
it "from int to float" do
count = 0
5 changes: 5 additions & 0 deletions spec/std/time/span_spec.cr
Original file line number Diff line number Diff line change
@@ -240,4 +240,9 @@ describe Time::Span do
it "should sum" do
[1.second, 5.seconds].sum.should eq(6.seconds)
end

it "test zero?" do
Time::Span.new(0).zero?.should eq true
Time::Span.new(123456789).zero?.should eq false
end
end
4 changes: 4 additions & 0 deletions src/complex.cr
Original file line number Diff line number Diff line change
@@ -223,6 +223,10 @@ struct Complex
def self.zero : Complex
new 0, 0
end

def zero? : Bool
@real == 0 && @imag == 0
end
end

struct Number
10 changes: 10 additions & 0 deletions src/number.cr
Original file line number Diff line number Diff line change
@@ -245,6 +245,16 @@ struct Number
self
end

# Returns `true` if value is equal to zero.
#
# ```
# 0.zero? # => true
# 5.zero? # => false
# ```
def zero? : Bool
self == 0
end

private class StepIterator(T, L, B)
include Iterator(T)

4 changes: 4 additions & 0 deletions src/time/span.cr
Original file line number Diff line number Diff line change
@@ -286,6 +286,10 @@ struct Time::Span
def self.zero
new(0)
end

def zero?
@ticks == 0
end
end

struct Int

0 comments on commit a431a57

Please sign in to comment.