public void PQTranslationsTest01() { PQ kilometers = new PQ(1, "km"); try { Console.WriteLine(kilometers.Convert("cm")); // this throws an exception } catch (Exception) { Console.WriteLine("No converter was found!"); } PQ.UnitConverters.Add(new SimpleSiUnitConverter()); Console.WriteLine(kilometers.Convert("cm")); // this results in 100,000 cm being printed Assert.IsTrue(kilometers.Validate()); }
public void TimeConvTest01() { TS y2kInstance = DateTime.Parse("2000-01-01"); PQ distance = DateTime.Parse("2010-01-01") - y2kInstance; // nothing specified; measured in seconds Console.WriteLine("{0}", distance); // outputs 315619200 s distance = distance.Convert("wk"); // outputs 521.857 wk distance.Precision = 3; Console.WriteLine("{0}", distance); distance = distance.Convert("a"); // 9.985 a distance.Precision = 3; Console.WriteLine("{0}", distance); //distance.UncertainRange = null; distance.NullFlavor = null; Assert.IsTrue(distance.Validate()); }
public void PQTranslationsTest02() { PQ kilometers = new PQ(1, "km"); try { Console.WriteLine(kilometers.Convert("cm")); // this throws an exception } catch (Exception) { Console.WriteLine("No converter was found!"); } // add unit converter PQ.UnitConverters.Add(new SimpleSiUnitConverter()); // convert PQ centimeters = kilometers.Convert("cm"); Console.WriteLine(centimeters); // this results in 100,000 m being printed Assert.AreNotEqual(kilometers, centimeters); }
public void DateSubTest01() { TS now = DateTime.Now, other = DateTime.Parse("2000-03-14"); // Subtract PQ dist = now - other; dist.Precision = 2; Console.WriteLine(dist.ToString()); // output: xxxxx.xx s // Convert To Weeks dist = dist.Convert("wk"); dist.Precision = 2; Console.WriteLine(dist); // output: yyyyy.yy wk Assert.IsTrue(dist.Validate()); }
public void PQTranslationsTest03() { PQ kilometers = new PQ(1, "km"); // add unit converter PQ.UnitConverters.Add(new SimpleSiUnitConverter()); try { // convert PQ temperature = kilometers.Convert("K"); Console.WriteLine(temperature); // this results in 100,000 m being printed Assert.IsFalse(temperature.Validate()); } catch (Exception e) { Console.WriteLine(e); // Make sure we get a 'cannot convert' exception message. Assert.IsTrue(e.ToString().Contains("Cannot convert")); } }
public void TimeConvTest02() { TS y2kInstance = DateTime.Parse("2000-01-01"); PQ distance = DateTime.Parse("2010-01-01") - y2kInstance; // nothing specified; measured in seconds Console.WriteLine("Before conversion: "); Console.WriteLine("{0}", distance); // outputs 315619200 s try { distance = distance.Convert("m"); // convert years to meters (should fail) distance.Precision = 3; Console.WriteLine("After conversion: "); Console.WriteLine("{0}", distance); Assert.IsTrue(distance.Validate()); } catch (Exception e) { Console.WriteLine("Error converting"); Console.WriteLine("{0}", e); } }