From 56b041d24524cd1c97beac7d10a247a987fb7249 Mon Sep 17 00:00:00 2001 From: Luciano Gaube Date: Tue, 4 Jun 2019 14:46:46 +0100 Subject: [PATCH] Fix issue #819 Add new overload for Minus Operator --- src/Humanizer.Tests.Shared/Bytes/ArithmeticTests.cs | 13 ++++++++++++- src/Humanizer/Bytes/ByteSize.cs | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Humanizer.Tests.Shared/Bytes/ArithmeticTests.cs b/src/Humanizer.Tests.Shared/Bytes/ArithmeticTests.cs index 6d791c8e5..251af9494 100644 --- a/src/Humanizer.Tests.Shared/Bytes/ArithmeticTests.cs +++ b/src/Humanizer.Tests.Shared/Bytes/ArithmeticTests.cs @@ -99,7 +99,7 @@ public void IncrementOperator() } [Fact] - public void MinusOperator() + public void NegativeOperator() { var size = ByteSize.FromBytes(2); @@ -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); + } } } diff --git a/src/Humanizer/Bytes/ByteSize.cs b/src/Humanizer/Bytes/ByteSize.cs index 5863e9bc0..2c9fe5e36 100644 --- a/src/Humanizer/Bytes/ByteSize.cs +++ b/src/Humanizer/Bytes/ByteSize.cs @@ -398,6 +398,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);