Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
omar committed Dec 6, 2018
1 parent 16b3f5d commit fc5ad2e
Show file tree
Hide file tree
Showing 9 changed files with 736 additions and 11 deletions.
145 changes: 145 additions & 0 deletions src/ByteSizeLib.Tests/BinaryByteSizeTest/ArithmeticMethods.cs
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 src/ByteSizeLib.Tests/BinaryByteSizeTest/CreatingMethods.cs
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);
}
}
}
Loading

0 comments on commit fc5ad2e

Please sign in to comment.