Skip to content

Commit

Permalink
Merge pull request #60 from engunneer/bug/compareTo
Browse files Browse the repository at this point in the history
Fix comparisons
  • Loading branch information
adrianstevens committed May 27, 2024
2 parents 6a0c193 + 7198845 commit 549797f
Show file tree
Hide file tree
Showing 71 changed files with 11,925 additions and 12,056 deletions.
42 changes: 42 additions & 0 deletions Source/Meadow.Units.Tests/CommonTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Xunit;
using System;
using System.Linq;
using Meadow.Units;

namespace Meadow.Units.Tests;

public class CommonTests
{
[Fact]
public void CompareToObjectOfSameType()
{
// find all comparable structs in the assembly
var testTypes = typeof(Temperature)
.Assembly
.GetTypes()
.Where(t => t.IsValueType && typeof(IComparable).IsAssignableFrom(t))
.ToArray();

var failCount = 0;
var successCount = 0;

foreach (var t in testTypes)
{
var testItemA = Activator.CreateInstance(t);
var testItemB = Activator.CreateInstance(t);

try
{
var shouldBeZero = (testItemA as IComparable).CompareTo(testItemB);
Assert.Equal(0, shouldBeZero);
successCount++;
}
catch (Exception)
{
failCount++;
}
}

Assert.True(failCount == 0, $"{failCount} out of {failCount + successCount} failed CompareTo(object)");
}
}
717 changes: 358 additions & 359 deletions Source/Meadow.Units/AbsoluteHumidity.cs

Large diffs are not rendered by default.

Loading

0 comments on commit 549797f

Please sign in to comment.