Skip to content

Instantly share code, notes, and snippets.

@JohanLarsson
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohanLarsson/91a8eefe9f64d7584b2d to your computer and use it in GitHub Desktop.
Save JohanLarsson/91a8eefe9f64d7584b2d to your computer and use it in GitHub Desktop.
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; }
}
}
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