Skip to content

Commit

Permalink
Release 1.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianstevens committed Apr 30, 2024
1 parent 7cc6b33 commit d1dce16
Show file tree
Hide file tree
Showing 48 changed files with 1,470 additions and 996 deletions.
89 changes: 89 additions & 0 deletions Source/Meadow.Units.Tests/DigitalStorageTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using Xunit;

namespace Meadow.Units.Tests;

public class DigitalStorageTests
{
[Fact]
public void DigitalStorageOneByteConstructor()
{
var one = new DigitalStorage(1, DigitalStorage.UnitType.Bytes);
Assert.True(one.Bytes == 1);
}

[Fact]
public void DigitalStorageOneKBConstructor()
{
var one = new DigitalStorage(1, DigitalStorage.UnitType.KiloBytes);
Assert.True(one.Bytes == 1000);
Assert.True(one.Bits == one.Bytes * 8);

var oneA = new DigitalStorage(1000, DigitalStorage.UnitType.Bytes);
Assert.True(oneA.KiloBytes == 1);
}

[Fact]
public void DigitalStorageOneKiBConstructor()
{
var one = new DigitalStorage(1, DigitalStorage.UnitType.KibiBytes);
Assert.True(one.Bytes == 1024);
Assert.True(one.Bits == one.Bytes * 8);

var oneA = new DigitalStorage(1024, DigitalStorage.UnitType.Bytes);
Assert.True(oneA.KibiBytes == 1);
Assert.True(oneA.Kibibits == 0.125);
}

[Fact]
public void DigitalStorageOneMBConstructor()
{
var one = new DigitalStorage(1, DigitalStorage.UnitType.MegaBytes);
Assert.True(one.Bytes == 1000_000);
Assert.True(one.Bits == one.Bytes * 8);

var oneA = new DigitalStorage(1000_000, DigitalStorage.UnitType.Bytes);
Assert.True(oneA.MegaBytes == 1);
}

[Fact]
public void DigitalStorageOneMiBConstructor()
{
var one = new DigitalStorage(1, DigitalStorage.UnitType.MebiBytes);
Assert.True(one.Bytes == 1024 * 1024);
Assert.True(one.Bits == one.Bytes * 8);

var oneA = new DigitalStorage(1024 * 1024, DigitalStorage.UnitType.Bytes);
Assert.True(oneA.MebiBytes == 1);
Assert.True(oneA.Mebibits == 0.125);
}

[Fact]
public void DigitalStorageOneGBConstructor()
{
var one = new DigitalStorage(1, DigitalStorage.UnitType.GigaBytes);
Assert.True(one.Bytes == 1000_000_000);
Assert.True(one.Bits == one.Bytes * 8);
}

[Fact]
public void DigitalStorageOneGiBConstructor()
{
var one = new DigitalStorage(1, DigitalStorage.UnitType.GibiBytes);
Assert.True(one.Bytes == 1024 * 1024 * 1024);
Assert.True(one.Bits == one.Bytes * 8);

var oneA = new DigitalStorage(1024 * 1024 * 1024, DigitalStorage.UnitType.Bytes);
Assert.True(oneA.GibiBytes == 1);
}

[Fact]
public void Subtraction()
{
var total = new DigitalStorage(30431968, DigitalStorage.UnitType.KibiBytes);
var available = new DigitalStorage(25975940, DigitalStorage.UnitType.KibiBytes);
var inUse = new DigitalStorage(4456028, DigitalStorage.UnitType.KibiBytes);

var testAvailable = total - inUse;
Assert.Equal(available.Bytes, testAvailable.Bytes);
}
}
105 changes: 51 additions & 54 deletions Source/Meadow.Units.Tests/MassTests.cs
Original file line number Diff line number Diff line change
@@ -1,72 +1,69 @@
using Xunit;
using System;
using Meadow.Units;
using MU = Meadow.Units.Mass.UnitType;

namespace Meadow.Units.Tests
namespace Meadow.Units.Tests;

public class MassTests
{
public class MassTests
[Fact()]
public void MassCtors()
{
[Fact()]
public void MassCtors()
{
Mass t = new Mass(100, MU.Grams);
Assert.True(t.Grams == 100);
Mass t = new Mass(100, MU.Grams);
Assert.True(t.Grams == 100);

Mass t2 = new Mass();
Assert.True(t2.Grams == 0);
}
Mass t2 = new Mass();
Assert.True(t2.Grams == 0);
}

[Fact()]
public void MassConversions()
{
Mass t = new Mass(1000, MU.Grams);
Assert.True(t.Kilograms.Equals3DigitPrecision(1));
Assert.True(t.Ounces.Equals4DigitPrecision(35.274));
Assert.True(t.Pounds.Equals4DigitPrecision(2.20462));
Assert.True(t.TonsMetric.Equals4DigitPrecision(0.001));
Assert.True(t.TonsUSShort.Equals4DigitPrecision(0.00110231));
Assert.True(t.TonsUKLong.Equals4DigitPrecision(0.000984207));
Assert.True(t.Grains.Equals4DigitPrecision(15432.3584));
Assert.True(t.Karats.Equals4DigitPrecision(5000));
[Fact()]
public void MassConversions()
{
Mass t = new Mass(1000, MU.Grams);
Assert.True(t.Kilograms.Equals3DigitPrecision(1));
Assert.True(t.Ounces.Equals4DigitPrecision(35.274));
Assert.True(t.Pounds.Equals4DigitPrecision(2.20462));
Assert.True(t.TonsMetric.Equals4DigitPrecision(0.001));
Assert.True(t.TonsUSShort.Equals4DigitPrecision(0.00110231));
Assert.True(t.TonsUKLong.Equals4DigitPrecision(0.000984207));
Assert.True(t.Grains.Equals4DigitPrecision(15432.3584));
Assert.True(t.Karats.Equals4DigitPrecision(5000));


Mass t2 = new Mass(10, MU.Pounds);
Assert.True(t2.Kilograms.Equals4DigitPrecision(4.53592));
Mass t2 = new Mass(10, MU.Pounds);
Assert.True(t2.Kilograms.Equals4DigitPrecision(4.53592));

Mass t3 = new Mass(50, MU.Grains);
Assert.True(t3.Grams.Equals4DigitPrecision(3.23995));
}
Mass t3 = new Mass(50, MU.Grains);
Assert.True(t3.Grams.Equals4DigitPrecision(3.23995));
}

[Fact()]
public void MassMathOps()
{
Mass t1 = new Mass(1, MU.Kilograms);
Mass t2 = new Mass(10, MU.Kilograms);
Mass t3 = new Mass(-3, MU.Kilograms);
Assert.True(t1 != t2);
Assert.True((t1 + t2) == new Mass(11, MU.Kilograms));
Assert.True((t2 - t1) == new Mass(9, MU.Kilograms));
[Fact()]
public void MassMathOps()
{
Mass t1 = new Mass(1, MU.Kilograms);
Mass t2 = new Mass(10, MU.Kilograms);
Mass t3 = new Mass(-3, MU.Kilograms);
Assert.True(t1 != t2);
Assert.True((t1 + t2) == new Mass(11, MU.Kilograms));
Assert.True((t2 - t1) == new Mass(9, MU.Kilograms));

Assert.True(t3.Abs() == new Mass(3, MU.Kilograms));
}
Assert.True(t3.Abs() == new Mass(3, MU.Kilograms));
}

[Fact()]
public void MassComparisons()
{
Mass t1 = new Mass(1);
Mass t2 = new Mass(10);
Mass t3 = new Mass(10);
[Fact()]
public void MassComparisons()
{
Mass t1 = new Mass(1);
Mass t2 = new Mass(10);
Mass t3 = new Mass(10);

Assert.True(t1 < t2);
Assert.True(t2 <= t3);
Assert.True(t2 > t1);
Assert.True(t3 >= t2);
Assert.True(t1 < t2);
Assert.True(t2 <= t3);
Assert.True(t2 > t1);
Assert.True(t3 >= t2);

Assert.True(t2 == t3);
Assert.True(t2 == t3);

Assert.True(t2 == new Mass(10, MU.Grams));
Assert.True(t2 > new Mass(5, MU.Grams));
}
Assert.True(t2 == new Mass(10, MU.Grams));
Assert.True(t2 > new Mass(5, MU.Grams));
}
}
1 change: 0 additions & 1 deletion Source/Meadow.Units/AngularAcceleration3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.ComponentModel;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using Meadow.Units.Conversions;

namespace Meadow.Units
{
Expand Down
1 change: 0 additions & 1 deletion Source/Meadow.Units/AngularVelocity3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.ComponentModel;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using Meadow.Units.Conversions;

namespace Meadow.Units
{
Expand Down
3 changes: 1 addition & 2 deletions Source/Meadow.Units/Azimuth16PointCardinalNames.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
namespace Meadow.Units
namespace Meadow.Units
{
/// <summary>
/// Cardinal compass directions
Expand Down
Loading

0 comments on commit d1dce16

Please sign in to comment.