Skip to content

Commit 9de99fa

Browse files
committed
Update tests
1 parent 4844a70 commit 9de99fa

File tree

3 files changed

+45
-17
lines changed

3 files changed

+45
-17
lines changed

src/Humanizer.Tests.Shared/Bytes/ByteRateTests.cs

+15-15
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, T
6767
[InlineData(TimeUnit.Month)]
6868
[InlineData(TimeUnit.Week)]
6969
[InlineData(TimeUnit.Year)]
70-
public void ThrowsOnUnsupportedData(TimeUnit units)
70+
public void ThowsOnUnsupportedData(TimeUnit units)
7171
{
7272
var dummyRate = ByteSize.FromBits(1).Per(TimeSpan.FromSeconds(1));
7373

@@ -78,13 +78,13 @@ public void ThrowsOnUnsupportedData(TimeUnit units)
7878
}
7979

8080
[Theory]
81-
[InlineData(400, 10, 400, 10, 0)] // 40.CompareTo(40)
82-
[InlineData(400, 10, 800, 20, 0)] // 40.CompareTo(40)
83-
[InlineData(800, 20, 400, 10, 0)] // 40.CompareTo(40)
84-
[InlineData(400, 10, 800, 10, -1)] // 40.CompareTo(80)
85-
[InlineData(800, 10, 400, 10, 1)] // 80.CompareTo(40)
86-
[InlineData(800, 10, 400, 20, 1)] // 80.CompareTo(20)
87-
[InlineData(400, 20, 800, 10, -1)] // 20.CompareTo(80)
81+
[InlineData(400, 10, 400, 10, 0)]
82+
[InlineData(400, 10, 800, 20, 0)]
83+
[InlineData(800, 20, 400, 10, 0)]
84+
[InlineData(400, 10, 800, 10, -1)]
85+
[InlineData(800, 10, 400, 10, 1)]
86+
[InlineData(800, 10, 400, 20, 1)]
87+
[InlineData(400, 20, 800, 10, -1)]
8888
public void ComparisonTests_SameTypes(long leftBytes, int leftIntervalSeconds, long rightBytes, int rightIntervalSeconds, int expectedValue)
8989
{
9090
var leftSize = ByteSize.FromBytes(leftBytes);
@@ -98,13 +98,13 @@ public void ComparisonTests_SameTypes(long leftBytes, int leftIntervalSeconds, l
9898
}
9999

100100
[Theory]
101-
[InlineData(1024, 10, 6, 1, 0)] // 1024.CompareTo(1024)
102-
[InlineData(1024, 10, 12, 2, 0)] // 1024.CompareTo(1024)
103-
[InlineData(2048, 20, 6, 1, 0)] // 1024.CompareTo(1024)
104-
[InlineData(1024, 10, 12, 1, -1)] // 1024.CompareTo(2048)
105-
[InlineData(2048, 10, 6, 1, 1)] // 2048.CompareTo(1024)
106-
[InlineData(2048, 10, 6, 2, 1)] // 2048.CompareTo(512)
107-
[InlineData(1024, 20, 12, 1, -1)] // 512.CompareTo(2048)
101+
[InlineData(1024, 10, 6, 1, 0)]
102+
[InlineData(1024, 10, 12, 2, 0)]
103+
[InlineData(2048, 20, 6, 1, 0)]
104+
[InlineData(1024, 10, 12, 1, -1)]
105+
[InlineData(2048, 10, 6, 1, 1)]
106+
[InlineData(2048, 10, 6, 2, 1)]
107+
[InlineData(1024, 20, 12, 1, -1)]
108108
public void ComparisonTests_DifferingTypes(long leftKiloBytes, int leftIntervalSeconds, long rightMegaBytes, int rightIntervalMinutes, int expectedValue)
109109
{
110110
var leftSize = ByteSize.FromKilobytes(leftKiloBytes);

src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
[assembly: System.Runtime.Versioning.TargetFrameworkAttribute(".NETStandard,Version=v1.0", FrameworkDisplayName="")]
33
namespace Humanizer.Bytes
44
{
5-
public class ByteRate
5+
public class ByteRate : System.IComparable, System.IComparable<Humanizer.Bytes.ByteRate>, System.IEquatable<Humanizer.Bytes.ByteRate>
66
{
77
public ByteRate(Humanizer.Bytes.ByteSize size, System.TimeSpan interval) { }
88
public System.TimeSpan Interval { get; }
99
public Humanizer.Bytes.ByteSize Size { get; }
10+
public int CompareTo(Humanizer.Bytes.ByteRate other) { }
11+
public int CompareTo(object obj) { }
12+
public bool Equals(Humanizer.Bytes.ByteRate other) { }
1013
public string Humanize(Humanizer.Localisation.TimeUnit timeUnit = 1) { }
1114
public string Humanize(string format, Humanizer.Localisation.TimeUnit timeUnit = 1) { }
15+
public override string ToString() { }
16+
public string ToString(string format, Humanizer.Localisation.TimeUnit timeUnit = 1) { }
1217
}
1318
public struct ByteSize : System.IComparable, System.IComparable<Humanizer.Bytes.ByteSize>, System.IEquatable<Humanizer.Bytes.ByteSize>
1419
{

src/Humanizer/Bytes/ByteRate.cs

+24-1
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,33 @@ public string Humanize(string format, TimeUnit timeUnit = TimeUnit.Second)
7676
return new ByteSize(Size.Bytes / Interval.TotalSeconds * displayInterval.TotalSeconds)
7777
.Humanize(format) + '/' + displayUnit;
7878
}
79-
79+
/// <summary>
80+
/// Returns the humanized string with default parameters.
81+
/// </summary>
82+
/// <returns></returns>
8083
public override string ToString()
8184
{
8285
return Humanize();
8386
}
8487

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

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

114+
/// <inheritdoc />
115+
/// <summary>
116+
/// Checks if two ByteRate objects have the same equivalent rate
117+
/// </summary>
118+
/// <param name="other"></param>
119+
/// <returns>True if rates are equivalent, otherwise false</returns>
98120
public bool Equals(ByteRate other)
99121
{
100122
return CompareTo(other) == 0;
101123
}
102124

125+
/// <inheritdoc />
103126
public int CompareTo(Object obj)
104127
{
105128
if (obj == null) return 1;

0 commit comments

Comments
 (0)