Skip to content

Commit

Permalink
clean up some formatting (#1453)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Feb 24, 2024
1 parent dfe6226 commit b294b70
Show file tree
Hide file tree
Showing 157 changed files with 8,556 additions and 7,629 deletions.
8 changes: 4 additions & 4 deletions src/Humanizer.Tests/ArticlePrefixSortTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public void SortStringArrayIgnoringArticlePrefixes(string[] input, string[] expe
[Fact]
public void An_Empty_String_Array_Throws_ArgumentOutOfRangeException()
{
string[] items = [];
void action() => EnglishArticle.AppendArticlePrefix(items);
Assert.Throws<ArgumentOutOfRangeException>(action);
}
string[] items = [];
void action() => EnglishArticle.AppendArticlePrefix(items);
Assert.Throws<ArgumentOutOfRangeException>(action);
}
}
154 changes: 84 additions & 70 deletions src/Humanizer.Tests/Bytes/ArithmeticTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,136 +5,150 @@ public class ArithmeticTests
[Fact]
public void Add()
{
var size1 = ByteSize.FromBytes(1);
var result = size1.Add(size1);
var size1 = ByteSize.FromBytes(1);
var result = size1.Add(size1);

Assert.Equal(2, result.Bytes);
Assert.Equal(16, result.Bits);
}
Assert.Equal(2, result.Bytes);
Assert.Equal(16, result.Bits);
}

[Fact]
public void AddBits()
{
var size = ByteSize.FromBytes(1).AddBits(8);
var size = ByteSize
.FromBytes(1)
.AddBits(8);

Assert.Equal(2, size.Bytes);
Assert.Equal(16, size.Bits);
}
Assert.Equal(2, size.Bytes);
Assert.Equal(16, size.Bits);
}

[Fact]
public void AddBytes()
{
var size = ByteSize.FromBytes(1).AddBytes(1);
var size = ByteSize
.FromBytes(1)
.AddBytes(1);

Assert.Equal(2, size.Bytes);
Assert.Equal(16, size.Bits);
}
Assert.Equal(2, size.Bytes);
Assert.Equal(16, size.Bits);
}

[Fact]
public void AddKilobytes()
{
var size = ByteSize.FromKilobytes(2).AddKilobytes(2);
var size = ByteSize
.FromKilobytes(2)
.AddKilobytes(2);

Assert.Equal(4 * 1024 * 8, size.Bits);
Assert.Equal(4 * 1024, size.Bytes);
Assert.Equal(4, size.Kilobytes);
}
Assert.Equal(4 * 1024 * 8, size.Bits);
Assert.Equal(4 * 1024, size.Bytes);
Assert.Equal(4, size.Kilobytes);
}

[Fact]
public void AddMegabytes()
{
var size = ByteSize.FromMegabytes(2).AddMegabytes(2);
var size = ByteSize
.FromMegabytes(2)
.AddMegabytes(2);

Assert.Equal(4 * 1024 * 1024 * 8, size.Bits);
Assert.Equal(4 * 1024 * 1024, size.Bytes);
Assert.Equal(4 * 1024, size.Kilobytes);
Assert.Equal(4, size.Megabytes);
}
Assert.Equal(4 * 1024 * 1024 * 8, size.Bits);
Assert.Equal(4 * 1024 * 1024, size.Bytes);
Assert.Equal(4 * 1024, size.Kilobytes);
Assert.Equal(4, size.Megabytes);
}

[Fact]
public void AddGigabytes()
{
var size = ByteSize.FromGigabytes(2).AddGigabytes(2);
var size = ByteSize
.FromGigabytes(2)
.AddGigabytes(2);

Assert.Equal(4d * 1024 * 1024 * 1024 * 8, size.Bits);
Assert.Equal(4d * 1024 * 1024 * 1024, size.Bytes);
Assert.Equal(4d * 1024 * 1024, size.Kilobytes);
Assert.Equal(4d * 1024, size.Megabytes);
Assert.Equal(4d, size.Gigabytes);
}
Assert.Equal(4d * 1024 * 1024 * 1024 * 8, size.Bits);
Assert.Equal(4d * 1024 * 1024 * 1024, size.Bytes);
Assert.Equal(4d * 1024 * 1024, size.Kilobytes);
Assert.Equal(4d * 1024, size.Megabytes);
Assert.Equal(4d, size.Gigabytes);
}

[Fact]
public void AddTerabytes()
{
var size = ByteSize.FromTerabytes(2).AddTerabytes(2);

Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 8, size.Bits);
Assert.Equal(4d * 1024 * 1024 * 1024 * 1024, size.Bytes);
Assert.Equal(4d * 1024 * 1024 * 1024, size.Kilobytes);
Assert.Equal(4d * 1024 * 1024, size.Megabytes);
Assert.Equal(4d * 1024, size.Gigabytes);
Assert.Equal(4d, size.Terabytes);
}
var size = ByteSize
.FromTerabytes(2)
.AddTerabytes(2);

Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 8, size.Bits);
Assert.Equal(4d * 1024 * 1024 * 1024 * 1024, size.Bytes);
Assert.Equal(4d * 1024 * 1024 * 1024, size.Kilobytes);
Assert.Equal(4d * 1024 * 1024, size.Megabytes);
Assert.Equal(4d * 1024, size.Gigabytes);
Assert.Equal(4d, size.Terabytes);
}

[Fact]
public void Subtract()
{
var size = ByteSize.FromBytes(4).Subtract(ByteSize.FromBytes(2));
var size = ByteSize
.FromBytes(4)
.Subtract(ByteSize.FromBytes(2));

Assert.Equal(16, size.Bits);
Assert.Equal(2, size.Bytes);
}
Assert.Equal(16, size.Bits);
Assert.Equal(2, size.Bytes);
}

[Fact]
public void IncrementOperator()
{
var size = ByteSize.FromBytes(2);
size++;
var size = ByteSize.FromBytes(2);
size++;

Assert.Equal(24, size.Bits);
Assert.Equal(3, size.Bytes);
}
Assert.Equal(24, size.Bits);
Assert.Equal(3, size.Bytes);
}

[Fact]
public void NegativeOperator()
{
var size = ByteSize.FromBytes(2);
var size = ByteSize.FromBytes(2);

size = -size;
size = -size;

Assert.Equal(-16, size.Bits);
Assert.Equal(-2, size.Bytes);
}
Assert.Equal(-16, size.Bits);
Assert.Equal(-2, size.Bytes);
}

[Fact]
public void DecrementOperator()
{
var size = ByteSize.FromBytes(2);
size--;
var size = ByteSize.FromBytes(2);
size--;

Assert.Equal(8, size.Bits);
Assert.Equal(1, size.Bytes);
}
Assert.Equal(8, size.Bits);
Assert.Equal(1, size.Bytes);
}

[Fact]
public void PlusOperator()
{
var size1 = ByteSize.FromBytes(1);
var size2 = ByteSize.FromBytes(1);
var size1 = ByteSize.FromBytes(1);
var size2 = ByteSize.FromBytes(1);

var result = size1 + size2;
var result = size1 + size2;

Assert.Equal(2, result.Bytes);
}
Assert.Equal(2, result.Bytes);
}

[Fact]
public void MinusOperator()
{
var size1 = ByteSize.FromBytes(2);
var size2 = ByteSize.FromBytes(1);
var size1 = ByteSize.FromBytes(2);
var size2 = ByteSize.FromBytes(1);

var result = size1 - size2;
var result = size1 - size2;

Assert.Equal(1, result.Bytes);
}
}
Assert.Equal(1, result.Bytes);
}
}
48 changes: 24 additions & 24 deletions src/Humanizer.Tests/Bytes/ByteRateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ public class ByteRateTests
[InlineData(15 * 60 * 1024 * 1024, 60, "15 MB/s")]
public void HumanizesRates(long inputBytes, double perSeconds, string expectedValue)
{
var size = new ByteSize(inputBytes);
var interval = TimeSpan.FromSeconds(perSeconds);
var size = new ByteSize(inputBytes);
var interval = TimeSpan.FromSeconds(perSeconds);

var rate = size.Per(interval).Humanize();
var rate = size
.Per(interval)
.Humanize();

Assert.Equal(expectedValue, rate);
}
Assert.Equal(expectedValue, rate);
}

[Theory]
[InlineData(1, 1, TimeUnit.Second, "1 MB/s")]
Expand All @@ -32,27 +34,27 @@ public void HumanizesRates(long inputBytes, double perSeconds, string expectedVa
[InlineData(1, 10 * 60 * 60, TimeUnit.Hour, "102.4 KB/h")]
public void TimeUnitTests(long megabytes, double measurementIntervalSeconds, TimeUnit displayInterval, string expectedValue)
{
var size = ByteSize.FromMegabytes(megabytes);
var measurementInterval = TimeSpan.FromSeconds(measurementIntervalSeconds);
var size = ByteSize.FromMegabytes(megabytes);
var measurementInterval = TimeSpan.FromSeconds(measurementIntervalSeconds);

var rate = size.Per(measurementInterval);
var text = rate.Humanize(displayInterval);
var rate = size.Per(measurementInterval);
var text = rate.Humanize(displayInterval);

Assert.Equal(expectedValue, text);
}
Assert.Equal(expectedValue, text);
}

[Theory]
[InlineData(19854651984, 1, TimeUnit.Second, null, "18.49 GB/s")]
[InlineData(19854651984, 1, TimeUnit.Second, "#.##", "18.49 GB/s")]
public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, TimeUnit displayInterval, string? format, string expectedValue)
{
var size = ByteSize.FromBytes(bytes);
var measurementInterval = TimeSpan.FromSeconds(measurementIntervalSeconds);
var rate = size.Per(measurementInterval);
var text = rate.Humanize(format, displayInterval);
var size = ByteSize.FromBytes(bytes);
var measurementInterval = TimeSpan.FromSeconds(measurementIntervalSeconds);
var rate = size.Per(measurementInterval);
var text = rate.Humanize(format, displayInterval);

Assert.Equal(expectedValue, text);
}
Assert.Equal(expectedValue, text);
}

[Theory]
[InlineData(TimeUnit.Millisecond)]
Expand All @@ -62,12 +64,10 @@ public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, T
[InlineData(TimeUnit.Year)]
public void ThrowsOnUnsupportedData(TimeUnit units)
{
var dummyRate = ByteSize.FromBits(1).Per(TimeSpan.FromSeconds(1));

Assert.Throws<NotSupportedException>(() =>
{
dummyRate.Humanize(units);
});
}
var dummyRate = ByteSize
.FromBits(1)
.Per(TimeSpan.FromSeconds(1));

Assert.Throws<NotSupportedException>(() => dummyRate.Humanize(units));
}
}
Loading

0 comments on commit b294b70

Please sign in to comment.