Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Cirzen committed Mar 28, 2019
1 parent 4844a70 commit 9de99fa
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
30 changes: 15 additions & 15 deletions src/Humanizer.Tests.Shared/Bytes/ByteRateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, T
[InlineData(TimeUnit.Month)]
[InlineData(TimeUnit.Week)]
[InlineData(TimeUnit.Year)]
public void ThrowsOnUnsupportedData(TimeUnit units)
public void ThowsOnUnsupportedData(TimeUnit units)

This comment has been minimized.

Copy link
@Cirzen

Cirzen Mar 28, 2019

Author

Reverting back name as AzureDevops build process depends on it

{
var dummyRate = ByteSize.FromBits(1).Per(TimeSpan.FromSeconds(1));

Expand All @@ -78,13 +78,13 @@ public void ThrowsOnUnsupportedData(TimeUnit units)
}

[Theory]
[InlineData(400, 10, 400, 10, 0)] // 40.CompareTo(40)
[InlineData(400, 10, 800, 20, 0)] // 40.CompareTo(40)
[InlineData(800, 20, 400, 10, 0)] // 40.CompareTo(40)
[InlineData(400, 10, 800, 10, -1)] // 40.CompareTo(80)
[InlineData(800, 10, 400, 10, 1)] // 80.CompareTo(40)
[InlineData(800, 10, 400, 20, 1)] // 80.CompareTo(20)
[InlineData(400, 20, 800, 10, -1)] // 20.CompareTo(80)
[InlineData(400, 10, 400, 10, 0)]
[InlineData(400, 10, 800, 20, 0)]
[InlineData(800, 20, 400, 10, 0)]
[InlineData(400, 10, 800, 10, -1)]
[InlineData(800, 10, 400, 10, 1)]
[InlineData(800, 10, 400, 20, 1)]
[InlineData(400, 20, 800, 10, -1)]
public void ComparisonTests_SameTypes(long leftBytes, int leftIntervalSeconds, long rightBytes, int rightIntervalSeconds, int expectedValue)
{
var leftSize = ByteSize.FromBytes(leftBytes);
Expand All @@ -98,13 +98,13 @@ public void ComparisonTests_SameTypes(long leftBytes, int leftIntervalSeconds, l
}

[Theory]
[InlineData(1024, 10, 6, 1, 0)] // 1024.CompareTo(1024)
[InlineData(1024, 10, 12, 2, 0)] // 1024.CompareTo(1024)
[InlineData(2048, 20, 6, 1, 0)] // 1024.CompareTo(1024)
[InlineData(1024, 10, 12, 1, -1)] // 1024.CompareTo(2048)
[InlineData(2048, 10, 6, 1, 1)] // 2048.CompareTo(1024)
[InlineData(2048, 10, 6, 2, 1)] // 2048.CompareTo(512)
[InlineData(1024, 20, 12, 1, -1)] // 512.CompareTo(2048)
[InlineData(1024, 10, 6, 1, 0)]
[InlineData(1024, 10, 12, 2, 0)]
[InlineData(2048, 20, 6, 1, 0)]
[InlineData(1024, 10, 12, 1, -1)]
[InlineData(2048, 10, 6, 1, 1)]
[InlineData(2048, 10, 6, 2, 1)]
[InlineData(1024, 20, 12, 1, -1)]
public void ComparisonTests_DifferingTypes(long leftKiloBytes, int leftIntervalSeconds, long rightMegaBytes, int rightIntervalMinutes, int expectedValue)
{
var leftSize = ByteSize.FromKilobytes(leftKiloBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
[assembly: System.Runtime.Versioning.TargetFrameworkAttribute(".NETStandard,Version=v1.0", FrameworkDisplayName="")]
namespace Humanizer.Bytes
{
public class ByteRate
public class ByteRate : System.IComparable, System.IComparable<Humanizer.Bytes.ByteRate>, System.IEquatable<Humanizer.Bytes.ByteRate>
{
public ByteRate(Humanizer.Bytes.ByteSize size, System.TimeSpan interval) { }
public System.TimeSpan Interval { get; }
public Humanizer.Bytes.ByteSize Size { get; }
public int CompareTo(Humanizer.Bytes.ByteRate other) { }
public int CompareTo(object obj) { }
public bool Equals(Humanizer.Bytes.ByteRate other) { }
public string Humanize(Humanizer.Localisation.TimeUnit timeUnit = 1) { }
public string Humanize(string format, Humanizer.Localisation.TimeUnit timeUnit = 1) { }
public override string ToString() { }
public string ToString(string format, Humanizer.Localisation.TimeUnit timeUnit = 1) { }
}
public struct ByteSize : System.IComparable, System.IComparable<Humanizer.Bytes.ByteSize>, System.IEquatable<Humanizer.Bytes.ByteSize>
{
Expand Down
25 changes: 24 additions & 1 deletion src/Humanizer/Bytes/ByteRate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,33 @@ public string Humanize(string format, TimeUnit timeUnit = TimeUnit.Second)
return new ByteSize(Size.Bytes / Interval.TotalSeconds * displayInterval.TotalSeconds)
.Humanize(format) + '/' + displayUnit;
}

/// <summary>
/// Returns the humanized string with default parameters.
/// </summary>
/// <returns></returns>
public override string ToString()
{
return Humanize();
}

/// <summary>
/// Returns a humanized string of the current rate object using the supplied parameters
/// </summary>
/// <param name="timeUnit">Unit of time to calculate rate for (defaults is per second)</param>
/// <param name="format">The string format to use for the number of bytes</param>
/// <returns></returns>
public string ToString(string format, TimeUnit timeUnit = TimeUnit.Second)
{
return Humanize(format, timeUnit);
}

/// <inheritdoc />
/// <summary>
/// Compares the current ByteRate object to another supplied ByteRate object.
/// Rates are normalized before comparing, e.g. 60Mb/Min is equal to 1024KB/sec
/// </summary>
/// <param name="other">The ByteRate object to use for the comparison</param>
/// <returns>0 if the rates are equivalent, -1 if lower than the 'other' object, 1 if higher than the 'other' object</returns>
public int CompareTo(ByteRate other)
{
var left = Size.Bytes / Interval.TotalSeconds;
Expand All @@ -95,11 +111,18 @@ public int CompareTo(ByteRate other)
return right < left ? 1 : 0;
}

/// <inheritdoc />
/// <summary>
/// Checks if two ByteRate objects have the same equivalent rate
/// </summary>
/// <param name="other"></param>
/// <returns>True if rates are equivalent, otherwise false</returns>
public bool Equals(ByteRate other)
{
return CompareTo(other) == 0;
}

/// <inheritdoc />
public int CompareTo(Object obj)
{
if (obj == null) return 1;
Expand Down

0 comments on commit 9de99fa

Please sign in to comment.