Skip to content

Commit

Permalink
Add unit tests for operator overloads in ocean.time.Time
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-palmer-sociomantic committed Nov 26, 2019
1 parent 1f7e784 commit 5b0a3a1
Showing 1 changed file with 125 additions and 0 deletions.
125 changes: 125 additions & 0 deletions src/ocean/time/Time.d
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,23 @@ struct TimeSpan
mixin("return TimeSpan(ticks_ " ~ op ~ " t.ticks_);");
}

unittest
{
TimeSpan time_span;
time_span.ticks_ = 5;

TimeSpan test_span;
test_span.ticks_ = 10;

auto res = time_span + test_span;
test!("==")(res.ticks(), 15);

test_span.ticks_ = 3;

res = time_span - test_span;
test!("==")(res.ticks(), 2);
}

/**
* Add or subtract the specified TimeSpan to this TimeSpan, assigning
* the result to this instance.
Expand All @@ -177,6 +194,23 @@ struct TimeSpan
return this;
}

unittest
{
TimeSpan time_span;
time_span.ticks_ = 5;

TimeSpan test_span;
test_span.ticks_ = 10;

time_span += test_span;
test!("==")(time_span.ticks(), 15);

test_span.ticks_ = 3;

time_span -= test_span;
test!("==")(time_span.ticks(), 12);
}

/**
* Scale the TimeSpan by the specified amount. This should not be
* used to convert to a different unit. Use the unit accessors
Expand All @@ -193,6 +227,18 @@ struct TimeSpan
mixin("return TimeSpan(ticks_ " ~ op ~ " v);");
}

unittest
{
TimeSpan time_span;
time_span.ticks_ = 5;

auto res = time_span * 10;
test!("==")(res.ticks(), 50);

res = time_span / 5;
test!("==")(res.ticks(), 1);
}

/**
* Scales this TimeSpan and assigns the result to this instance.
*
Expand All @@ -206,6 +252,18 @@ struct TimeSpan
return this;
}

unittest
{
TimeSpan time_span;
time_span.ticks_ = 5;

time_span *= 10;
test!("==")(time_span.ticks(), 50);

time_span /= 5;
test!("==")(time_span.ticks(), 10);
}

/**
* Perform integer division with the given time span.
*
Expand All @@ -219,6 +277,17 @@ struct TimeSpan
return ticks_ / t.ticks;
}

unittest
{
TimeSpan time_span;
time_span.ticks_ = 10;

TimeSpan test_span;
test_span.ticks_ = 5;

test!("==")(time_span / test_span, 2);
}

/**
* Negate a time span. Returns a new TimeSpan.
*
Expand All @@ -230,6 +299,16 @@ struct TimeSpan
return TimeSpan(-ticks_);
}

unittest
{
TimeSpan time_span;
time_span.ticks_ = 10;

auto res = (-time_span);

test!("==")(res.ticks(), -10);
}

/**
* Convert to nanoseconds
*
Expand Down Expand Up @@ -535,6 +614,23 @@ struct Time
mixin("return Time(ticks_ " ~ op ~ " t.ticks_);");
}

unittest
{
Time time_span;
time_span.ticks_ = 5;

TimeSpan test_span;
test_span.ticks_ = 10;

auto res = time_span + test_span;
test!("==")(res.ticks(), 15);

test_span.ticks_ = 3;

res = time_span - test_span;
test!("==")(res.ticks(), 2);
}

/**********************************************************************
Adds or subtracts the specified time span to the time, assigning
Expand All @@ -553,6 +649,23 @@ struct Time
return this;
}

unittest
{
Time time_span;
time_span.ticks_ = 5;

TimeSpan test_span;
test_span.ticks_ = 10;

time_span += test_span;
test!("==")(time_span.ticks(), 15);

test_span.ticks_ = 3;

time_span -= test_span;
test!("==")(time_span.ticks(), 12);
}

/**********************************************************************
Returns a time span which represents the difference in time
Expand All @@ -570,6 +683,18 @@ struct Time
return TimeSpan(ticks_ - t.ticks_);
}

unittest
{
Time time_span;
time_span.ticks_ = 5;

TimeSpan test_span;
test_span.ticks_ = 3;

auto res = time_span - test_span;
test!("==")(res.ticks(), 2);
}

/**********************************************************************
$(I Property.) Retrieves the date component.
Expand Down

0 comments on commit 5b0a3a1

Please sign in to comment.