Testing the Progression Values

I created two tests to test the common types of progression; the first will use date/time comparisons, where the next one will use numerical comparisons.  The first is in the case of calculating a reoccurring task, where the other option is for calculating custom measurements, as we will see.  I created the first test as below:

public void TestDueDatePercentage()
    DateTime completionDate = new DateTime(2007, 1, 1);
    DateTime lastCompletionDate = new DateTime(2006, 6, 1);
    DateTime currentDate = new DateTime(2006, 9, 1);

    //Get the time span difference between the date values
    TimeSpan fullValue = completionDate.Subtract(lastCompletionDate);
    TimeSpan partialValue = completionDate.Subtract(currentDate);

    //Make sure the values and day counts are different, with full value being larger
    Assert.AreNotSame(fullValue, partialValue);
    Assert.AreNotEqual(fullValue.Days, partialValue.Days);
    Assert.Greater(fullValue.Days, partialValue.Days);

    double fullDays = Convert.ToDouble(fullValue.Days);
    double partialDays = Convert.ToDouble(partialValue.Days);

    //Get the percentage value of dividing partial value by the full value
    double percentage = partialDays / fullDays;
    Console.WriteLine("TestDueDatePercentage percentage:  " + percentage.ToString());
    //Make sure the value is within a particular range
    Assert.IsTrue(percentage > 0.40);
    Assert.IsTrue(percentage < 0.60);

I created a task that was last completed on 6/1/2006 and will be due on 1/1/2007.  It is currently 9/1/2006 in this scenario, and I test to see that whenever I get the days, that I can calculate the percentage.  I get a value in the .57 range, and so this test worked; this is the reason for the big range, because the actual date comparison value will vary greatly.  Also, to actually get a decimal value, you have to use double or float.  I use double for ease of use, and this works great for this purpose (int returns 0 or 1).  The next test compares integer comparison.

public void TestMeasurementPercentage()
    double fullValue = 5000;
    double partialValue = 2500;

    //Calculate the current percentage
    double percentage = partialValue / fullValue;

    Console.WriteLine("TestMeasurementPercentage percentage: " + percentage.ToString());
    //Make sure the value is within a particular range
    Assert.IsTrue(percentage > 0.49);
    Assert.IsTrue(percentage < 0.51);

I am comparing a task that is halfway complete, and so I create the percentage and test the range.  I use a +1 approach because it could be off slightly; decimal point values have a habit of being slightly off, even though the measurement should be exact.  This test also works.


No Comments