public void TestbigNumberToConvert() { XmlConversionTable xmlConversion = new XmlInitTable().TableInit("Converter.Configs.InformationUnits.xml"); Conversion meters = new Conversion(1, 12345678901234567890, (ConversionTable)xmlConversion.ConversionTable, (Unit)xmlConversion.Unit); var result = meters.Convert(10); Assert.AreEqual("1.276513E-06 YB", result.Value + " " + result.UnitSymbol); }
public void TestDuplicateConversions() { XmlConversionTable xmlConversion = new XmlInitTable().TableInit("Converter.TestCases.LengthDuplicateConversions.xml"); Conversion meters = new Conversion(1, 10, (ConversionTable)xmlConversion.ConversionTable, (Unit)xmlConversion.Unit); var result = meters.Convert(2); Assert.AreEqual("1000 cm", result.Value + " " + result.UnitSymbol); }
public void TestLengthConversionFromFile() { var conversionTable = new XmlConversionTable(new ConversionTable(), new Unit()); conversionTable.XmlConversionTableInit("../../../Converter/Configs/LengthUnits.xml"); Conversion meters = new Conversion(1, 100, (ConversionTable)conversionTable.ConversionTable, (Unit)conversionTable.Unit); var result = meters.Convert(3); Assert.AreEqual("10000cm", result.Value + result.UnitSymbol); }
public void TestInformationConversionFromFile() { var conversionTable = new XmlConversionTable(new ConversionTable(), new Unit()); conversionTable.XmlConversionTableInit("../../../Converter/Configs/InformationUnits.xml"); Conversion meters = new Conversion(1, 115, (ConversionTable)conversionTable.ConversionTable, (Unit)conversionTable.Unit); var result = meters.Convert(9); //result is 1.2176098616781E-20 from http://www.bit-calculator.com/ Assert.AreEqual("1.21761E-20ZB", result.Value + result.UnitSymbol); Assert.AreEqual("1.21761E-20 ZettaBytes", result.Value + " " + result.UnitPlural); }
public void TestLengthConversionFromImplicitInit() { XmlConversionTable xmlConversion = new XmlInitTable().LengthTable; Conversion conversion = new Conversion(1, 100, (ConversionTable)xmlConversion.ConversionTable, (Unit)xmlConversion.Unit); Assert.AreEqual(conversion.UnitName, "Meter"); Assert.AreEqual(conversion.UnitPlural, "Meters"); Assert.AreEqual(conversion.UnitSymbol, "m"); var result = conversion.Convert(3); Assert.AreEqual("10000cm", result.Value + result.UnitSymbol); }
public void TestCreationFromFileImplicit() { XmlConversionTable xmlConversion = new XmlInitTable().InformationTable; Conversion conversion = new Conversion(1, 100, (ConversionTable)xmlConversion.ConversionTable, (Unit)xmlConversion.Unit); Assert.AreEqual(conversion.UnitName, "bit"); Assert.AreEqual(conversion.UnitPlural, "bits"); Assert.AreEqual(conversion.UnitSymbol, "b"); var result = conversion.Convert(3); Assert.AreEqual("0.01220703 KB", result.Value + " " + result.UnitSymbol); }
public void TestCreationFromFileExplicit() { var conversionTable = new XmlConversionTable(new ConversionTable(), new Unit()); conversionTable.XmlConversionTableInit("../../../Converter/Configs/InformationUnits.xml"); Conversion meters = new Conversion(1, 10, (ConversionTable)conversionTable.ConversionTable, (Unit)conversionTable.Unit); var result = meters.Convert(3); Assert.AreEqual(meters.UnitName, "bit"); Assert.AreEqual(meters.UnitPlural, "bits"); Assert.AreEqual(meters.UnitSymbol, "b"); Assert.AreEqual("0.001220703 KB", result.Value + " " + result.UnitSymbol); }
static void Main(string[] args) { string fromFileName = string.Empty; string toFileName = string.Empty; args.GetCommandLineSwitch(Constants.INFILE_SWITCH, ref fromFileName); args.GetCommandLineSwitch(Constants.OUTFILE_SWITCH, ref toFileName); try { if (fromFileName.Length > 0 && toFileName.Length > 0) { long val = long.Parse(args[0]); int fromVal = int.Parse(fromFileName); int toVal = int.Parse(toFileName); XmlConversionTable table = new XmlInitTable().LengthTable; //ConversionTable table = InitTable.LengthTableInit("Converter.TestCases.LengthDuplicateUnits.xml"); Conversion meters = new Conversion(fromVal, val, (ConversionTable)table.ConversionTable, (Unit)table.Unit); Conversion result = meters.Convert(toVal); if(val > 1) Console.WriteLine("ConversionTable from {0} to {1} is {2}", args[0] + " " + result.Unit.GetUnitPlural(fromVal), result.UnitPlural, result.Value + " " + result.UnitSymbol); else { Console.WriteLine("ConversionTable from {0} to {1} is {2}", args[0] + " " + result.Unit.GetUnitName(fromVal), result.UnitName, result.Value + " " + result.UnitSymbol); } Console.ReadLine(); } else { CommandLineHelper.ShowUsage(); } } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadLine(); } }
public void TestNotAvailableConversion() { XmlConversionTable xmlConversion = new XmlInitTable().TableInit("Converter.TestCases.LengthUnits.xml"); Conversion meters = new Conversion(2, 100, (ConversionTable)xmlConversion.ConversionTable, (Unit)xmlConversion.Unit); var result = meters.Convert(9); }