//****************************************************************************************************** // TimeTest.cs - Gbtc // // Copyright © 2012, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may // not use this file except in compliance with the License. You may obtain a copy of the License at: // // http://www.opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 02/01/2011 - Denis Kholine // 12/13/2012 - Starlynn Danyelle Gilliam // Modified Header. // //****************************************************************************************************** #region [ University of Illinois/NCSA Open Source License ] /* Copyright © <2012> All rights reserved. Developed by: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal with the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers. • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimers in the documentation and/or other materials provided with the distribution. • Neither the names of , nor the names of its contributors may be used to endorse or promote products derived from this Software without specific prior written permission. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. */ #endregion using System; using System.Collections.Generic; using System.Globalization; using GSF.Units; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace GSF.Core.Tests { /// ///This is a test class for TimeTest and is intended ///to contain all TimeTest Unit Tests /// [TestClass] public class TimeTest { private TestContext testContextInstance; /// ///Gets or sets the test context which provides ///information about and functionality for the current test run. /// public TestContext TestContext { get { return testContextInstance; } set { testContextInstance = value; } } #region Additional test attributes // //You can use the following additional attributes as you write your tests: // //Use ClassInitialize to run code before running the first test in the class //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //Use ClassCleanup to run code after all tests in a class have run //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //Use TestInitialize to run code before running each test //[TestInitialize()] //public void MyTestInitialize() //{ //} // //Use TestCleanup to run code after each test has run //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion /// /// A test for Time Constructor /// Creates a new . /// /// New time value in seconds. [TestMethod] public void TimeConstructorTest() { List values = new List(); //Initialization values.Add(0); foreach (Double value in values) { Time target = new Time(value); Assert.IsInstanceOfType(target, typeof(Time)); Assert.IsNotNull(target); } values.Clear(); } /// /// A test for Time Constructor /// Creates a new . /// /// New time value as a . [TestMethod] public void TimeSpanConstructorTest() { List values = new List(); //Initialization values.Add(0); foreach (Double value in values) { TimeSpan target = new TimeSpan(1, 1, 1); Assert.IsInstanceOfType(target, typeof(TimeSpan)); Assert.IsNotNull(target); } values.Clear(); } /// /// A test for CompareTo /// Compares this instance to a specified object and returns an indication of their relative values. /// /// An object to compare, or null. /// /// A signed number indicating the relative values of this instance and value. Returns less than zero /// if this instance is less than value, zero if this instance is equal to value, or greater than zero /// if this instance is greater than value. /// /// value is not a or . [TestMethod] public void CompareToTest() { Time target = new Time(10F); object value = new Time(10F); int expected = 0; int actual; actual = target.CompareTo(value); Assert.AreEqual(expected, actual); } /// /// A test for CompareTo /// Compares this instance to a specified and returns an indication of their /// relative values. /// /// An to compare. /// /// A signed number indicating the relative values of this instance and value. Returns less than zero /// if this instance is less than value, zero if this instance is equal to value, or greater than zero /// if this instance is greater than value. /// [TestMethod] public void CompareToDoubleTest() { Time target = new Time(10F); double value = 10F; int expected = 0; int actual; actual = target.CompareTo(value); Assert.AreEqual(expected, actual); } /// /// A test for CompareTo /// Compares this instance to a specified and returns an indication of their /// relative values. /// /// A to compare. /// /// A signed number indicating the relative values of this instance and value. Returns less than zero /// if this instance is less than value, zero if this instance is equal to value, or greater than zero /// if this instance is greater than value. /// [TestMethod] public void CompareToTimeSpanTest() { Time target = new Time(10F); TimeSpan value = new TimeSpan(0, 0, 10); int expected = 0; int actual; actual = target.CompareTo(value); Assert.AreEqual(expected, actual); } /// /// A test for CompareTo /// Compares this instance to a specified and returns an indication of their /// relative values. /// /// A to compare. /// /// A signed number indicating the relative values of this instance and value. Returns less than zero /// if this instance is less than value, zero if this instance is equal to value, or greater than zero /// if this instance is greater than value. /// [TestMethod] public void CompareToTimeTest() { Time target = new Time(10F); Time value = new Time(10F); int expected = 0; int actual; actual = target.CompareTo(value); Assert.AreEqual(expected, actual); } /// /// A test for Equals /// Returns a value indicating whether this instance is equal to a specified value. /// /// An value to compare to this instance. /// /// True if obj has the same value as this instance; otherwise, False. /// [TestMethod] public void EqualsDoubleTest() { Time target = new Time(10F); double obj = 10F; bool expected = true; bool actual; actual = target.Equals(obj); Assert.AreEqual(expected, actual); } /// /// A test for Equals /// Returns a value indicating whether this instance is equal to a specified value. /// /// A value to compare to this instance. /// /// True if obj has the same value as this instance; otherwise, False. /// [TestMethod] public void EqualsTimeSpanTest() { Time target = new Time(10F); TimeSpan obj = new TimeSpan(0, 0, 10); bool expected = true; bool actual; actual = target.Equals(obj); Assert.AreEqual(expected, actual); } /// /// A test for Equals /// Returns a value indicating whether this instance is equal to a specified value. /// /// A value to compare to this instance. /// /// True if obj has the same value as this instance; otherwise, False. /// [TestMethod] public void EqualsTest() { Time target = new Time(10F); Time obj = new Time(10F); bool expected = true; bool actual; actual = target.Equals(obj); Assert.AreEqual(expected, actual); } /// /// A test for Equals /// Returns a value indicating whether this instance is equal to a specified object. /// /// An object to compare, or null. /// /// True if obj is an instance of or and equals the value of this instance; /// otherwise, False. /// [TestMethod] public void EqualsObjectTest() { Time target = new Time(10F); object obj = new Time(10F); bool expected = true; bool actual; actual = target.Equals(obj); Assert.AreEqual(expected, actual); } /// /// A test for FromAtomicUnitsOfTime (Statis method) /// Creates a new value from the specified in atomic units of time. /// /// New value in atomic units of time. /// New object from the specified in atomic units of time. [TestMethod] public void FromAtomicUnitsOfTimeTest() { double value = 10F; Time expected = new Time(0.0000000000000002418884254); Time actual; actual = Time.FromAtomicUnitsOfTime(value); Assert.AreEqual(expected, actual); } /// /// A test for FromDays /// Creates a new value from the specified in days. /// /// New value in days. /// New object from the specified in days. [TestMethod] public void FromDaysTest() { double value = 10F; Time expected = new Time(864000.0); Time actual; actual = Time.FromDays(value); Assert.AreEqual(expected, actual); } /// /// A test for FromHours /// Creates a new value from the specified in hours. /// /// New value in hours. /// New object from the specified in hours. [TestMethod] public void FromHoursTest() { double value = 1F; Time expected = new Time(3600); Time actual; actual = Time.FromHours(value); Assert.AreEqual(expected, actual); } /// /// A test for FromKe /// Creates a new value from the specified in ke, /// the traditional Chinese unit of decimal time. /// /// New value in ke. /// New object from the specified in ke. [TestMethod] public void FromKeTest() { double value = 10F; Time expected = new Time(8640.0); Time actual; actual = Time.FromKe(value); Assert.AreEqual(expected, actual); } /// /// Creates a new value from the specified in minutes. /// /// New value in minutes. /// New object from the specified in minutes. [TestMethod] public void FromMinutesTest() { double value = 10F; Time expected = new Time(600.0); Time actual; actual = Time.FromMinutes(value); Assert.AreEqual(expected, actual); } /// /// A test for FromPlanckTime /// Creates a new value from the specified in Planck time. /// /// New value in Planck time. /// New object from the specified in Planck time. [TestMethod] public void FromPlanckTimeTest() { double value = 10F; Time expected = new Time(1.3512118179999999E-42); Time actual; actual = Time.FromPlanckTime(value); Assert.AreEqual(expected, actual); } /// /// A test for FromWeeks /// Creates a new value from the specified in weeks. /// /// New value in weeks. /// New object from the specified in weeks. [TestMethod] public void FromWeeksTest() { double value = 10F; Time expected = new Time(6048000.0); Time actual; actual = Time.FromWeeks(value); Assert.AreEqual(expected, actual); } /// /// A test for GetHashCode /// Returns the hash code for this instance. /// /// /// A 32-bit signed integer hash code. /// [TestMethod] public void GetHashCodeTest() { Time target = new Time(10); int expected = 1076101120; int actual; actual = target.GetHashCode(); Assert.AreEqual(expected, actual); } /// /// A test for GetTypeCode /// Returns the for value type . /// /// The enumerated constant, . [TestMethod] public void GetTypeCodeTest() { Time target = new Time(10F); TypeCode expected = new TypeCode(); expected = Type.GetTypeCode(typeof(Double)); TypeCode actual; actual = target.GetTypeCode(); Assert.AreEqual(expected, actual); } /// /// A test for Parse /// Converts the string representation of a number in a specified style to its equivalent. /// /// A string containing a number to convert. /// /// A bitwise combination of System.Globalization.NumberStyles values that indicates the permitted format of s. /// /// /// A equivalent to the number contained in s. /// /// /// style is not a System.Globalization.NumberStyles value. -or- style is not a combination of /// System.Globalization.NumberStyles.AllowHexSpecifier and System.Globalization.NumberStyles.HexNumber values. /// /// s is null. /// /// s represents a number less than or greater than . /// /// s is not in a format compliant with style. [TestMethod] public void ParseStyleTest() { double value = 10F; string s = value.ToString(); NumberStyles style = new NumberStyles(); Time expected = new Time(value); Time actual; actual = Time.Parse(s, style); Assert.AreEqual(expected, actual); } /// /// A test for Parse /// Converts the string representation of a number to its equivalent. /// /// A string containing a number to convert. /// /// A equivalent to the number contained in s. /// /// s is null. /// /// s represents a number less than or greater than . /// /// s is not in the correct format. [TestMethod] public void ParseTimeTest() { double value = 10F; string s = value.ToString(); Time expected = new Time(value); Time actual; actual = Time.Parse(s); Assert.AreEqual(expected, actual); } /// /// A test for Parse /// Converts the string representation of a number in a specified culture-specific format to its equivalent. /// /// A string containing a number to convert. /// /// A that supplies culture-specific formatting information about s. /// /// /// A equivalent to the number contained in s. /// /// s is null. /// /// s represents a number less than or greater than . /// /// s is not in the correct format. [TestMethod] public void ParseProviderTest() { double value = 10F; string s = value.ToString(); IFormatProvider provider = null; Time expected = new Time(value); Time actual; actual = Time.Parse(s, provider); Assert.AreEqual(expected, actual); } /// /// A test for Parse /// Converts the string representation of a number in a specified style and culture-specific format to its equivalent. /// /// A string containing a number to convert. /// /// A bitwise combination of System.Globalization.NumberStyles values that indicates the permitted format of s. /// /// /// A that supplies culture-specific formatting information about s. /// /// /// A equivalent to the number contained in s. /// /// /// style is not a System.Globalization.NumberStyles value. -or- style is not a combination of /// System.Globalization.NumberStyles.AllowHexSpecifier and System.Globalization.NumberStyles.HexNumber values. /// /// s is null. /// /// s represents a number less than or greater than . /// /// s is not in a format compliant with style. [TestMethod] public void ParseTest() { double value = 10F; string s = value.ToString(); NumberStyles style = new NumberStyles(); IFormatProvider provider = null; Time expected = new Time(value); Time actual; actual = Time.Parse(s, style, provider); Assert.AreEqual(expected, actual); } /// /// A test for SecondsPerMonth /// Returns the number of seconds in the specified month and year. /// /// The year. /// The month (a number ranging from 1 to 12). /// /// The number of seconds, as a , in the month for the specified year. /// /// /// Month is less than 1 or greater than 12. -or- year is less than 1 or greater than 9999. /// [TestMethod] public void SecondsPerMonthTest() { int year = 2012; int month = 1; int expected = 2678400; int actual; actual = Time.SecondsPerMonth(year, month); Assert.AreEqual(expected, actual); } /// /// A test for SecondsPerYear /// Returns the number of seconds in the specified year. /// /// The year. /// /// The number of seconds in the specified year. /// /// /// Year is less than 1 or greater than 9999. /// [TestMethod] public void SecondsPerYearTest() { int year = 1; long expected = 31536000; long actual; actual = Time.SecondsPerYear(year); Assert.AreEqual(expected, actual); } /// ///A test for System.IConvertible.ToBoolean /// [TestMethod] [DeploymentItem("GSF.Core.dll")] public void ToBooleanTest() { IConvertible target = new Time(10F); IFormatProvider provider = null; bool expected = true; bool actual; actual = target.ToBoolean(provider); Assert.AreEqual(expected, actual); } /// ///A test for System.IConvertible.ToByte /// [TestMethod] [DeploymentItem("GSF.Core.dll")] public void ToByteTest() { IConvertible target = new Time(10F); IFormatProvider provider = null; byte expected = 10; byte actual; actual = target.ToByte(provider); Assert.AreEqual(expected, actual); } ///// /////A test for System.IConvertible.ToChar ///// //[TestMethod] //[DeploymentItem("GSF.Core.dll")] //public void ToCharTest() //{ // Assert.Inconclusive("Can't cast from 'Double' to 'Char'."); //} ///// /////A test for System.IConvertible.ToDateTime ///// //[TestMethod] //[DeploymentItem("GSF.Core.dll")] //public void ToDateTimeTest() //{ // Assert.Inconclusive("Can't cast from 'Double' to 'Char'."); //} /// ///A test for System.IConvertible.ToDecimal /// [TestMethod] [DeploymentItem("GSF.Core.dll")] public void ToDecimalTest() { IConvertible target = new Time(10F); IFormatProvider provider = null; Decimal expected = new Decimal(10F); Decimal actual; actual = target.ToDecimal(provider); Assert.AreEqual(expected, actual); } /// ///A test for System.IConvertible.ToDouble /// [TestMethod] [DeploymentItem("GSF.Core.dll")] public void ToDoubleTest() { IConvertible target = new Time(10F); IFormatProvider provider = null; double expected = 10F; double actual; actual = target.ToDouble(provider); Assert.AreEqual(expected, actual); } /// ///A test for System.IConvertible.ToInt16 /// [TestMethod] [DeploymentItem("GSF.Core.dll")] public void ToInt16Test() { IConvertible target = new Time(10F); IFormatProvider provider = null; short expected = 10; short actual; actual = target.ToInt16(provider); Assert.AreEqual(expected, actual); } /// ///A test for System.IConvertible.ToInt32 /// [TestMethod] [DeploymentItem("GSF.Core.dll")] public void ToInt32Test() { IConvertible target = new Time(10F); IFormatProvider provider = null; int expected = 10; int actual; actual = target.ToInt32(provider); Assert.AreEqual(expected, actual); } /// ///A test for System.IConvertible.ToInt64 /// [TestMethod] [DeploymentItem("GSF.Core.dll")] public void ToInt64Test() { IConvertible target = new Time(10F); IFormatProvider provider = null; long expected = 10; long actual; actual = target.ToInt64(provider); Assert.AreEqual(expected, actual); } /// ///A test for System.IConvertible.ToSByte /// [TestMethod] [DeploymentItem("GSF.Core.dll")] public void ToSByteTest() { IConvertible target = new Time(10F); IFormatProvider provider = null; sbyte expected = 10; sbyte actual; actual = target.ToSByte(provider); Assert.AreEqual(expected, actual); } /// ///A test for System.IConvertible.ToSingle /// [TestMethod] [DeploymentItem("GSF.Core.dll")] public void ToSingleTest() { IConvertible target = new Time(10F); IFormatProvider provider = null; float expected = 10F; float actual; actual = target.ToSingle(provider); Assert.AreEqual(expected, actual); } /// ///A test for System.IConvertible.ToType /// [TestMethod] [DeploymentItem("GSF.Core.dll")] public void ToTypeTest() { double value = 10F; IConvertible target = new Time(value); Type conversionType = typeof(Double); IFormatProvider provider = null; object expected = new Time(value); object actual; actual = target.ToType(conversionType, provider); Assert.AreEqual(expected, actual); } /// ///A test for System.IConvertible.ToUInt16 /// [TestMethod] [DeploymentItem("GSF.Core.dll")] public void ToUInt16Test() { IConvertible target = new Time(10F); IFormatProvider provider = null; ushort expected = 10; ushort actual; actual = target.ToUInt16(provider); Assert.AreEqual(expected, actual); } /// ///A test for System.IConvertible.ToUInt32 /// [TestMethod] [DeploymentItem("GSF.Core.dll")] public void ToUInt32Test() { IConvertible target = new Time(10F); IFormatProvider provider = null; uint expected = 10; uint actual; actual = target.ToUInt32(provider); Assert.AreEqual(expected, actual); } /// ///A test for System.IConvertible.ToUInt64 /// [TestMethod] [DeploymentItem("GSF.Core.dll")] public void ToUInt64Test() { IConvertible target = new Time(10F); IFormatProvider provider = null; ulong expected = 10; ulong actual; actual = target.ToUInt64(provider); Assert.AreEqual(expected, actual); } /// /// A test for ToAtomicUnitsOfTime /// Gets the value in atomic units of time. /// /// Value of in atomic units of time. [TestMethod] public void ToAtomicUnitsOfTimeTest() { Time target = new Time(10F); double expected = 4.1341374575750989E+17; double actual; actual = target.ToAtomicUnitsOfTime(); Assert.AreEqual(expected, actual); } /// ///A test for ToDays /// [TestMethod] public void ToDaysTest() { Time target = new Time(10F); double expected = 0.00011574074074074075; double actual; actual = target.ToDays(); Assert.AreEqual(expected, actual); } /// ///A test for ToHours /// [TestMethod] public void ToHoursTest() { Time target = new Time(10F); double expected = 0.0027777777777777779; double actual; actual = target.ToHours(); Assert.AreEqual(expected, actual); } /// /// A test for ToKe /// Gets the value in ke, the traditional Chinese unit of decimal time. /// /// Value of in ke. [TestMethod] public void ToKeTest() { Time target = new Time(10F); double expected = 0.011574074074074073; double actual; actual = target.ToKe(); Assert.AreEqual(expected, actual); } /// /// A test for ToMinutes /// Gets the value in minutes. /// /// Value of in minutes. [TestMethod] public void ToMinutesTest() { Time target = new Time(10F); double expected = 0.16666666666666666; double actual; actual = target.ToMinutes(); Assert.AreEqual(expected, actual); } /// /// A test for ToPlanckTime /// Gets the value in Planck time. /// /// Value of in Planck time. [TestMethod] public void ToPlanckTimeTest() { Time target = new Time(10F); double expected = 7.4007641635354617E+43; double actual; actual = target.ToPlanckTime(); Assert.AreEqual(expected, actual); } ///// ///// A test for ToString ///// Converts the numeric value of this instance to its equivalent string representation using the ///// specified format and culture-specific format information. ///// ///// ///// Note that this ToString overload matches , use ///// to convert value into a textual representation ///// of years, days, hours, minutes and seconds. ///// ///// A format specification. ///// ///// A that supplies culture-specific formatting information. ///// ///// ///// The string representation of the value of this instance as specified by format and provider. ///// //[TestMethod] //public void ToStringFormatProviderTest() //{ // double value = 10F; // Time target = new Time(value); // string format = string.Empty; // IFormatProvider provider = null; // string expected = value.ToString(); // string actual; // actual = target.ToString(format, provider); // Assert.AreEqual(expected, actual); //} ///// ///// A test for ToString ///// Converts the numeric value of this instance to its equivalent string representation, using ///// the specified format. ///// ///// ///// Note that this ToString overload matches , use ///// to convert value into a textual ///// representation of years, days, hours, minutes and seconds. ///// ///// A format string. ///// ///// The string representation of the value of this instance as specified by format. ///// //[TestMethod] //public void ToStringFormatTest() //{ // double value = 10F; // Time target = new Time(value); // string format = string.Empty; // string expected = value.ToString(); // string actual; // actual = target.ToString(format); // Assert.AreEqual(expected, actual); //} ///// ///// A test for ToString ///// Converts the value into a textual representation of years, days, hours, ///// minutes and seconds with the specified number of fractional digits given string array of ///// time names. ///// ///// Number of fractional digits to display for seconds. ///// Time names array to use during textual conversion. ///// ///// Set second precision to -1 to suppress seconds display. ///// ///// array needs one string entry for each of the following names:
///// "Year", "Years", "Day", "Days", "Hour", "Hours", "Minute", "Minutes", "Second", "Seconds", ///// "Less Than 60 Seconds", "0 Seconds". /////
/////
///// ///// The string representation of the value of this instance, consisting of the number of ///// years, days, hours, minutes and seconds represented by this value. ///// //[TestMethod] //public void ToStringSecondPrecisionTimeNamesTest() //{ // Time target = new Time(10F); // int secondPrecision = 2; // string[] timeNames = { "Year", "Years", "Day", "Days", "Hour", "Hours", "Minute", "Minutes", "Second", "Seconds", "Less Than 60 Seconds", "0 Seconds" }; // string expected = "10.00 Seconds"; // string actual; // actual = target.ToString(secondPrecision, timeNames); // Assert.AreEqual(expected, actual); //} /// /// A test for ToString /// Converts the numeric value of this instance to its equivalent string representation using the /// specified culture-specific format information. /// /// /// Note that this ToString overload matches , use /// to convert value into a textual /// representation of years, days, hours, minutes and seconds. /// /// /// A that supplies culture-specific formatting information. /// /// /// The string representation of the value of this instance as specified by provider. /// [TestMethod] public void ToStringProviderTest() { double value = 10F; Time target = new Time(value); IFormatProvider provider = null; string expected = value.ToString(); string actual; actual = target.ToString(provider); Assert.AreEqual(expected, actual); } ///// ///// A test for ToString ///// Converts the value into a textual representation of years, days, hours, ///// minutes and seconds with the specified number of fractional digits. ///// ///// Number of fractional digits to display for seconds. ///// Set second precision to -1 to suppress seconds display. ///// ///// The string representation of the value of this instance, consisting of the number of ///// years, days, hours, minutes and seconds represented by this value. ///// //[TestMethod] //public void ToStringSecondPrecisionTest() //{ // double value = 10F; // Time target = new Time(value); // int secondPrecision = 2; // string expected = "10.00 Seconds"; // string actual; // actual = target.ToString(secondPrecision); // Assert.AreEqual(expected, actual); //} ///// ///// A test for ToString ///// Converts the value into a textual representation of years, days, hours, ///// minutes and seconds. ///// ///// ///// Note that this ToString overload will not display fractional seconds. To allow display of ///// fractional seconds, or completely remove second resolution from the textual representation, ///// use the overload instead. ///// ///// ///// The string representation of the value of this instance, consisting of the number of ///// years, days, hours, minutes and seconds represented by this value. ///// //[TestMethod] //public void ToStringTest() //{ // double value = 10F; // Time target = new Time(value); // string expected = "10 Seconds"; // string actual; // actual = target.ToString(); // Assert.AreEqual(expected, actual); //} /// /// A test for ToTicks /// Converts the value, in seconds, to 100-nanosecond tick intervals. /// /// A object. [TestMethod] public void ToTicksTest() { Time target = new Time(10F); Ticks expected = new Ticks(100000000); Ticks actual; actual = target.ToTicks(); Assert.AreEqual(expected, actual); } /// /// A test for ToWeeks /// Gets the value in weeks. /// /// Value of in weeks. [TestMethod] public void ToWeeksTest() { Time target = new Time(1000000F); double expected = 1.6534391534391535; double actual; actual = target.ToWeeks(); Assert.AreEqual(expected, actual); } /// /// A test for TryParse /// Converts the string representation of a number to its equivalent. A return value /// indicates whether the conversion succeeded or failed. /// /// A string containing a number to convert. /// /// When this method returns, contains the value equivalent to the number contained in s, /// if the conversion succeeded, or zero if the conversion failed. The conversion fails if the s parameter is null, /// is not of the correct format, or represents a number less than or greater than . /// This parameter is passed uninitialized. /// /// true if s was converted successfully; otherwise, false. [TestMethod] public void TryParseTest() { double value = 10F; string s = value.ToString(); Time result = new Time(value); Time resultExpected = new Time(value); bool expected = true; bool actual; actual = Time.TryParse(s, out result); Assert.AreEqual(resultExpected, result); Assert.AreEqual(expected, actual); } ///// ///// A test for TryParse ///// Converts the string representation of a number to its equivalent. A return value ///// indicates whether the conversion succeeded or failed. ///// ///// A string containing a number to convert. ///// ///// When this method returns, contains the value equivalent to the number contained in s, ///// if the conversion succeeded, or zero if the conversion failed. The conversion fails if the s parameter is null, ///// is not of the correct format, or represents a number less than or greater than . ///// This parameter is passed uninitialized. ///// ///// true if s was converted successfully; otherwise, false. //[TestMethod] //public void TryParseStyleProviderResultTest() //{ // double value = 10F; // string s = value.ToString(); // NumberStyles style = new NumberStyles(); // IFormatProvider provider = null; // Time result = new Time(); // Time resultExpected = new Time(); // bool expected = true; // bool actual; // actual = Time.TryParse(s, style, provider, out result); // Assert.AreEqual(resultExpected, result); // Assert.AreEqual(expected, actual); //} /// ///A test for op_Addition /// [TestMethod] public void op_AdditionTest() { Time value1 = new Time(10F); Time value2 = new Time(10F); Time expected = new Time(20F); Time actual; actual = (value1 + value2); Assert.AreEqual(expected, actual); } /// ///A test for op_Division /// [TestMethod] public void op_DivisionTest() { Time value1 = new Time(10F); Time value2 = new Time(10F); Time expected = new Time(1F); Time actual; actual = (value1 / value2); Assert.AreEqual(expected, actual); } /// ///A test for op_Equality /// [TestMethod] public void op_EqualityTest() { Time value1 = new Time(10F); Time value2 = new Time(10F); bool expected = true; bool actual; actual = (value1 == value2); Assert.AreEqual(expected, actual); } /// ///A test for op_Exponent /// [TestMethod] public void op_ExponentTest() { Time value1 = new Time(2F); Time value2 = new Time(3F); double expected = 8F; double actual; actual = Time.op_Exponent(value1, value2); Assert.AreEqual(expected, actual); } /// ///A test for op_GreaterThan /// [TestMethod] public void op_GreaterThanTest() { Time value1 = new Time(10F); Time value2 = new Time(9F); bool expected = true; bool actual; actual = (value1 > value2); Assert.AreEqual(expected, actual); } /// ///A test for op_GreaterThanOrEqual /// [TestMethod] public void op_GreaterThanOrEqualTest() { Time value1 = new Time(10F); Time value2 = new Time(10F); bool expected = true; bool actual; actual = (value1 >= value2); Assert.AreEqual(expected, actual); } ///// /////A test for op_Implicit ///// //[TestMethod] //public void op_ImplicitTimeSpanTest() //{ // Time value = new Time(10F); // TimeSpan expected = new TimeSpan(1, 1, 1); // TimeSpan actual; // actual = value; // Assert.AreEqual(expected, actual); //} /// ///A test for op_Implicit /// [TestMethod] public void op_ImplicitDoubleTest() { Time value = new Time(10F); double expected = 10F; double actual; actual = value; Assert.AreEqual(expected, actual); } /// ///A test for op_Implicit /// [TestMethod] public void op_ImplicitTest2() { TimeSpan value = new TimeSpan(0, 0, 10); Time expected = new Time(10F); Time actual; actual = value; Assert.AreEqual(expected, actual); } /// ///A test for op_Implicit /// [TestMethod] public void op_ImplicitTest3() { double value = 10F; Time expected = new Time(10F); Time actual; actual = value; Assert.AreEqual(expected, actual); } /// ///A test for op_Inequality /// [TestMethod] public void op_InequalityTest() { Time value1 = new Time(10F); Time value2 = new Time(9F); bool expected = true; bool actual; actual = (value1 != value2); Assert.AreEqual(expected, actual); } /// ///A test for op_LessThan /// [TestMethod] public void op_LessThanTest() { Time value1 = new Time(10F); Time value2 = new Time(11F); bool expected = true; bool actual; actual = (value1 < value2); Assert.AreEqual(expected, actual); } /// ///A test for op_LessThanOrEqual /// [TestMethod] public void op_LessThanOrEqualTest() { Time value1 = new Time(10F); Time value2 = new Time(10F); bool expected = true; bool actual; actual = (value1 <= value2); Assert.AreEqual(expected, actual); } /// ///A test for op_Modulus /// [TestMethod] public void op_ModulusTest() { Time value1 = new Time(10F); Time value2 = new Time(10F); Time expected = new Time(0F); Time actual; actual = (value1 % value2); Assert.AreEqual(expected, actual); } /// ///A test for op_Multiply /// [TestMethod] public void op_MultiplyTest() { Time value1 = new Time(10F); Time value2 = new Time(10F); Time expected = new Time(100F); Time actual; actual = (value1 * value2); Assert.AreEqual(expected, actual); } /// ///A test for op_Subtraction /// [TestMethod] public void op_SubtractionTest() { Time value1 = new Time(10F); Time value2 = new Time(10F); Time expected = new Time(0F); Time actual; actual = (value1 - value2); Assert.AreEqual(expected, actual); } } }