Last active
August 29, 2015 14:07
-
-
Save JohanLarsson/91a8eefe9f64d7584b2d to your computer and use it in GitHub Desktop.
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
public class UnitPartsConverterSource : IEnumerable | |
{ | |
public static SiUnit Metres = new SiUnit("", "Metres", "m"); | |
public static SiUnit Kilograms = new SiUnit("", "Kilograms", "kg"); | |
public static SiUnit Seconds = new SiUnit("", "Seconds", "s"); | |
private List<Data> _datas = new List<Data> | |
{ | |
new Data("m^2", new UnitAndPower(Metres, 2)), | |
new Data("kg*m/s^2",new UnitAndPower(Kilograms, 1),new UnitAndPower(Metres, 1),new UnitAndPower(Seconds, -2)), | |
}; | |
public IEnumerator GetEnumerator() | |
{ | |
return _datas.GetEnumerator(); | |
} | |
public class Data | |
{ | |
public Data(string value, params UnitAndPower[] units) | |
{ | |
this.Value = value; | |
this.Units = units; | |
} | |
public string Value { get; set; } | |
public IEnumerable<UnitAndPower> Units { get; private set; } | |
} | |
} |
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
public class UnitPartsConverterTests | |
{ | |
[TestCaseSource(typeof(UnitPartsConverterSource))] | |
public void ConvertFrom(UnitPartsConverterSource.Data data) | |
{ | |
var converter = new UnitPartsConverter(); | |
Assert.IsTrue(converter.CanConvertFrom(null, typeof(string))); | |
var parts = (UnitParts)converter.ConvertFrom(null, null, data.Value); | |
CollectionAssert.AreEquivalent(data.Units, parts); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment