Skip to content

Commit

Permalink
Fix issue Humanizr#819
Browse files Browse the repository at this point in the history
Add new overload for Minus Operator
  • Loading branch information
lucianogaube authored and jvanrhyn committed Sep 10, 2020
1 parent ae20f1a commit 0a5f030
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Humanizer.Tests.Shared/Bytes/ArithmeticTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void IncrementOperator()
}

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

Expand Down Expand Up @@ -129,5 +129,16 @@ public void PlusOperator()

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

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

var result = size1 - size2;

Assert.Equal(1, result.Bytes);
}
}
}
5 changes: 5 additions & 0 deletions src/Humanizer/Bytes/ByteSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ public ByteSize Subtract(ByteSize bs)
return new ByteSize(b1.Bytes + b2.Bytes);
}

public static ByteSize operator -(ByteSize b1, ByteSize b2)
{
return new ByteSize(b1.Bytes - b2.Bytes);
}

public static ByteSize operator ++(ByteSize b)
{
return new ByteSize(b.Bytes + 1);
Expand Down

0 comments on commit 0a5f030

Please sign in to comment.