-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
736 additions
and
11 deletions.
There are no files selected for viewing
145 changes: 145 additions & 0 deletions
145
src/ByteSizeLib.Tests/BinaryByteSizeTest/ArithmeticMethods.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
using Xunit; | ||
|
||
namespace ByteSizeLib.Tests.BinaryByteSizeTests | ||
{ | ||
public class ArithmeticMethods | ||
{ | ||
[Fact] | ||
public void AddMethod() | ||
{ | ||
var size1 = BinaryByteSize.FromBytes(1); | ||
var result = size1.Add(size1); | ||
|
||
Assert.Equal(2, result.Bytes); | ||
Assert.Equal(16, result.Bits); | ||
} | ||
|
||
[Fact] | ||
public void AddBitsMethod() | ||
{ | ||
var size = BinaryByteSize.FromBytes(1).AddBits(8); | ||
|
||
Assert.Equal(2, size.Bytes); | ||
Assert.Equal(16, size.Bits); | ||
} | ||
|
||
[Fact] | ||
public void AddBytesMethod() | ||
{ | ||
var size = BinaryByteSize.FromBytes(1).AddBytes(1); | ||
|
||
Assert.Equal(2, size.Bytes); | ||
Assert.Equal(16, size.Bits); | ||
} | ||
|
||
[Fact] | ||
public void AddKibiBytesMethod() | ||
{ | ||
var size = BinaryByteSize.FromKibiBytes(2).AddKibiBytes(2); | ||
|
||
Assert.Equal(4 * 1024 * 8, size.Bits); | ||
Assert.Equal(4 * 1024, size.Bytes); | ||
Assert.Equal(4, size.KibiBytes); | ||
} | ||
|
||
[Fact] | ||
public void AddMebiBytesMethod() | ||
{ | ||
var size = BinaryByteSize.FromMebiBytes(2).AddMebiBytes(2); | ||
|
||
Assert.Equal(4 * 1024 * 1024 * 8, size.Bits); | ||
Assert.Equal(4 * 1024 * 1024, size.Bytes); | ||
Assert.Equal(4 * 1024, size.KibiBytes); | ||
Assert.Equal(4, size.MebiBytes); | ||
} | ||
|
||
[Fact] | ||
public void AddGibiBytesMethod() | ||
{ | ||
var size = BinaryByteSize.FromGibiBytes(2).AddGibiBytes(2); | ||
|
||
Assert.Equal(4d * 1024 * 1024 * 1024 * 8, size.Bits); | ||
Assert.Equal(4d * 1024 * 1024 * 1024, size.Bytes); | ||
Assert.Equal(4d * 1024 * 1024, size.KibiBytes); | ||
Assert.Equal(4d * 1024, size.MebiBytes); | ||
Assert.Equal(4d, size.GibiBytes); | ||
} | ||
|
||
[Fact] | ||
public void AddTebiBytesMethod() | ||
{ | ||
var size = BinaryByteSize.FromTebiBytes(2).AddTebiBytes(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.KibiBytes); | ||
Assert.Equal(4d * 1024 * 1024, size.MebiBytes); | ||
Assert.Equal(4d * 1024, size.GibiBytes); | ||
Assert.Equal(4d, size.TebiBytes); | ||
} | ||
|
||
[Fact] | ||
public void AddPebiBytesMethod() | ||
{ | ||
var size = BinaryByteSize.FromPebiBytes(2).AddPebiBytes(2); | ||
|
||
Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 8, size.Bits); | ||
Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024, size.Bytes); | ||
Assert.Equal(4d * 1024 * 1024 * 1024 * 1024, size.KibiBytes); | ||
Assert.Equal(4d * 1024 * 1024 * 1024, size.MebiBytes); | ||
Assert.Equal(4d * 1024 * 1024, size.GibiBytes); | ||
Assert.Equal(4d * 1024, size.TebiBytes); | ||
Assert.Equal(4d, size.PebiBytes); | ||
} | ||
|
||
[Fact] | ||
public void SubtractMethod() | ||
{ | ||
var size = BinaryByteSize.FromBytes(4).Subtract(BinaryByteSize.FromBytes(2)); | ||
|
||
Assert.Equal(16, size.Bits); | ||
Assert.Equal(2, size.Bytes); | ||
} | ||
|
||
[Fact] | ||
public void IncrementOperator() | ||
{ | ||
var size = BinaryByteSize.FromBytes(2); | ||
size++; | ||
|
||
Assert.Equal(24, size.Bits); | ||
Assert.Equal(3, size.Bytes); | ||
} | ||
|
||
|
||
[Fact] | ||
public void MinusOperatorUnary() | ||
{ | ||
var size = BinaryByteSize.FromBytes(2); | ||
|
||
size = -size; | ||
|
||
Assert.Equal(-16, size.Bits); | ||
Assert.Equal(-2, size.Bytes); | ||
} | ||
|
||
[Fact] | ||
public void MinusOperatorBinary() | ||
{ | ||
var size = BinaryByteSize.FromBytes(4) - BinaryByteSize.FromBytes(2); | ||
|
||
Assert.Equal(16, size.Bits); | ||
Assert.Equal(2, size.Bytes); | ||
} | ||
|
||
[Fact] | ||
public void DecrementOperator() | ||
{ | ||
var size = BinaryByteSize.FromBytes(2); | ||
size--; | ||
|
||
Assert.Equal(8, size.Bits); | ||
Assert.Equal(1, size.Bytes); | ||
} | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
src/ByteSizeLib.Tests/BinaryByteSizeTest/CreatingMethods.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
using Xunit; | ||
|
||
namespace ByteSizeLib.Tests.BinaryByteSizeTests | ||
{ | ||
public class CreatingMethods | ||
{ | ||
[Fact] | ||
public void Constructor() | ||
{ | ||
// Arrange | ||
double bytes = 1125899906842624; | ||
|
||
// Act | ||
var result = new BinaryByteSize(bytes); | ||
|
||
// Assert | ||
Assert.Equal(bytes * 8, result.Bits); | ||
Assert.Equal(bytes, result.Bytes); | ||
Assert.Equal(bytes / 1024, result.KibiBytes); | ||
Assert.Equal(bytes / 1024 / 1024, result.MebiBytes); | ||
Assert.Equal(bytes / 1024 / 1024 / 1024, result.GibiBytes); | ||
Assert.Equal(bytes / 1024 / 1024 / 1024 / 1024, result.TebiBytes); | ||
Assert.Equal(1, result.PebiBytes); | ||
} | ||
|
||
[Fact] | ||
public void FromBitsMethod() | ||
{ | ||
// Arrange | ||
long value = 8; | ||
|
||
// Act | ||
var result = BinaryByteSize.FromBits(value); | ||
|
||
// Assert | ||
Assert.Equal(8, result.Bits); | ||
Assert.Equal(1, result.Bytes); | ||
} | ||
|
||
[Fact] | ||
public void FromBytesMethod() | ||
{ | ||
// Arrange | ||
double value = 1.5; | ||
|
||
// Act | ||
var result = BinaryByteSize.FromBytes(value); | ||
|
||
// Assert | ||
Assert.Equal(12, result.Bits); | ||
Assert.Equal(1.5, result.Bytes); | ||
} | ||
|
||
[Fact] | ||
public void FromKibiBytesMethod() | ||
{ | ||
// Arrange | ||
double value = 1.5; | ||
|
||
// Act | ||
var result = BinaryByteSize.FromKibiBytes(value); | ||
|
||
// Assert | ||
Assert.Equal(1536, result.Bytes); | ||
Assert.Equal(1.5, result.KibiBytes); | ||
} | ||
|
||
[Fact] | ||
public void FromMebiBytesMethod() | ||
{ | ||
// Arrange | ||
double value = 1.5; | ||
|
||
// Act | ||
var result = BinaryByteSize.FromMebiBytes(value); | ||
|
||
// Assert | ||
Assert.Equal(1572864, result.Bytes); | ||
Assert.Equal(1.5, result.MebiBytes); | ||
} | ||
|
||
[Fact] | ||
public void FromGibiBytesMethod() | ||
{ | ||
// Arrange | ||
double value = 1.5; | ||
|
||
// Act | ||
var result = BinaryByteSize.FromGibiBytes(value); | ||
|
||
// Assert | ||
Assert.Equal(1610612736, result.Bytes); | ||
Assert.Equal(1.5, result.GibiBytes); | ||
} | ||
|
||
[Fact] | ||
public void FromTebiBytesMethod() | ||
{ | ||
// Arrange | ||
double value = 1.5; | ||
|
||
// Act | ||
var result = BinaryByteSize.FromTebiBytes(value); | ||
|
||
// Assert | ||
Assert.Equal(1649267441664, result.Bytes); | ||
Assert.Equal(1.5, result.TebiBytes); | ||
} | ||
|
||
[Fact] | ||
public void FromPebiBytesMethod() | ||
{ | ||
// Arrange | ||
double value = 1.5; | ||
|
||
// Act | ||
var result = BinaryByteSize.FromPebiBytes(value); | ||
|
||
// Assert | ||
Assert.Equal(1688849860263936, result.Bytes); | ||
Assert.Equal(1.5, result.PebiBytes); | ||
} | ||
} | ||
} |
Oops, something went wrong.