-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from engunneer/bug/compareTo
Fix comparisons
- Loading branch information
Showing
71 changed files
with
11,925 additions
and
12,056 deletions.
There are no files selected for viewing
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,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)"); | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.