-
Notifications
You must be signed in to change notification settings - Fork 12
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
1 parent
b084923
commit 68a3b9c
Showing
3 changed files
with
64 additions
and
0 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
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,33 @@ | ||
namespace Gu.Units.Tests | ||
{ | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
|
||
using NUnit.Framework; | ||
|
||
public class MassTests | ||
{ | ||
public static IReadOnlyList<ConversionData> ConversionSource { get; } = new[] | ||
{ | ||
new ConversionData("28.349523125 g", "1 oz"), | ||
new ConversionData("31.1034768 g", "1 troy", false), | ||
new ConversionData("1 lb", "0.45359237 kg"), | ||
new ConversionData("1 gr", "64.79891 mg", false), | ||
}; | ||
|
||
[TestCaseSource(nameof(ConversionSource))] | ||
public void Conversion(ConversionData data) | ||
{ | ||
var m1 = Mass.Parse(data.From, CultureInfo.InvariantCulture); | ||
var m2 = Mass.Parse(data.To, CultureInfo.InvariantCulture); | ||
if (data.Exactly) | ||
{ | ||
Assert.AreEqual(m1, m2); | ||
} | ||
else | ||
{ | ||
Assert.AreEqual(m1.ToString(), m2.ToString()); | ||
} | ||
} | ||
} | ||
} |
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,29 @@ | ||
namespace Gu.Units.Tests | ||
{ | ||
public class ConversionData | ||
{ | ||
public ConversionData(string @from, | ||
string to, | ||
bool exactly = true) | ||
{ | ||
this.From = @from; | ||
this.To = to; | ||
this.Exactly = exactly; | ||
} | ||
|
||
public string From { get; } | ||
|
||
public string To { get; } | ||
|
||
public bool Exactly { get; } | ||
|
||
|
||
public override string ToString() | ||
{ | ||
var equalitySymbol = this.Exactly | ||
? "==" | ||
: "~"; | ||
return $"{this.From} {equalitySymbol} {this.To}"; | ||
} | ||
} | ||
} |