Monday, 11 August 2008

Pex - test case 6 (revisited...again)

Hello,

I did some further test on test case 6 . I removed all pex assumptions regarding the dates. This time Pex had no problem finding the test cases necessary for a complete block coverage.

So the PUT states no assumptions regarding the dates;


[TestClass]
[PexClass(typeof(EmployeeServices))]
public partial class EmployeeServicesTest
{
[PexMethod()]
public void DeterminePensionContribution([PexAssumeUnderTest]EmployeeServices target, Employee aEmployee)
{
PexAssume.IsNotNull(aEmployee);
PexAssume.IsTrue(aEmployee.Salary > 1400 && aEmployee.Salary < 10000);
PexAssume.IsTrue(aEmployee.TypeContract == Contract.FullTime || aEmployee.TypeContract == Contract.PartTime);


PensionContribution result = target.DeterminePensionContribution(aEmployee);

PexValue.AddForValidation("BaseContribution", result.BaseContribution);
PexValue.AddForValidation("SupplementaryContribution", result.SupplementaryContribution);

if (aEmployee.Salary <= 3000)
Assert.IsTrue(result.BaseContribution == 80);
if (aEmployee.Salary > 3000)
Assert.IsTrue(result.BaseContribution == 135);
if (aEmployee.Salary <= 3000 && aEmployee.Age >= 45 && aEmployee.ServiceYears < 5)
Assert.IsTrue(result.SupplementaryContribution == 15);
if (aEmployee.Salary <= 3000 && aEmployee.Age < 45 && aEmployee.TypeContract == Contract.FullTime)
Assert.IsTrue(result.SupplementaryContribution == 15);
if (aEmployee.Salary <= 3000 && aEmployee.Age >= 45 && aEmployee.ServiceYears >= 5)
Assert.IsTrue(result.SupplementaryContribution == 25);
if (aEmployee.Salary > 3000 && aEmployee.Age < 45 && aEmployee.ServiceYears >= 5 && aEmployee.TypeContract == Contract.FullTime)
Assert.IsTrue(result.SupplementaryContribution == 25);
if (aEmployee.Salary > 3000 && aEmployee.Age < 45 && aEmployee.ServiceYears >= 5 && aEmployee.TypeContract == Contract.PartTime)
Assert.IsTrue(result.SupplementaryContribution == 20);
if (aEmployee.Salary > 3000 && aEmployee.Age >= 45 && aEmployee.ServiceYears >= 5)
Assert.IsTrue(result.SupplementaryContribution == 20);
if (aEmployee.Salary > 3000 && aEmployee.ServiceYears < 5)
Assert.IsTrue(result.SupplementaryContribution == 30);
}

}


When you run Pex this time it generated none less than 11 unit tests. The generated DateTime value are constructed with the Ticks argument, so it no easy to see the actual dateTime. Actually the first time I run this Pex generated a tick value with a value larger than 32 bit. When running the generated unit tests, an exception was thrown specifying thant the tick value should be between the DateTime.Minvalue.Ticks and DateTimeValue.Maxvalue.Ticks. It seemed to me that i generated a 64-bit value.
I haven't been able to reproduce this error though. May be it is one of the remarks in the release of this version 0.6x. I'm running on Windows XP SP2!

Nevertheless here are the generated unit tests.

public partial class EmployeeServicesTest
{
[TestMethod]
[PexGeneratedBy(typeof(EmployeeServicesTest))]
public void DeterminePensionContribution01()
{
PexValue.Generated.Clear();
Employee employee;
DateTime s0 = new DateTime(1L);
employee = EmployeeFactory.Create
(2, "", "", default(DateTime), s0, 8192u, Contract.FullTime);
EmployeeServices employeeServices = new EmployeeServices();
this.DeterminePensionContribution(employeeServices, employee);
PexValue.Generated.Validate("BaseContribution", "135");
PexValue.Generated.Validate("SupplementaryContribution", "20");
}

[TestMethod]
[PexGeneratedBy(typeof(EmployeeServicesTest))]
public void DeterminePensionContribution02()
{
PexValue.Generated.Clear();
Employee employee;
DateTime s0 = new DateTime(1L);
employee = EmployeeFactory.Create
(2, "", "", default(DateTime), s0, 1983u, Contract.FullTime);
EmployeeServices employeeServices = new EmployeeServices();
this.DeterminePensionContribution(employeeServices, employee);
PexValue.Generated.Validate("BaseContribution", "80");
PexValue.Generated.Validate("SupplementaryContribution", "25");
}

[TestMethod]
[PexGeneratedBy(typeof(EmployeeServicesTest))]
public void DeterminePensionContribution03()
{
PexValue.Generated.Clear();
Employee employee;
DateTime s0 = new DateTime(1L);
employee = EmployeeFactory.Create
(2, "", "", default(DateTime), s0, 8192u, Contract.PartTime);
EmployeeServices employeeServices = new EmployeeServices();
this.DeterminePensionContribution(employeeServices, employee);
PexValue.Generated.Validate("BaseContribution", "135");
PexValue.Generated.Validate("SupplementaryContribution", "20");
}

[TestMethod]
[PexGeneratedBy(typeof(EmployeeServicesTest))]
public void DeterminePensionContribution04()
{
PexValue.Generated.Clear();
Employee employee;
DateTime s0 = new DateTime(647341024241516544L);
DateTime s1 = new DateTime(1L);
employee = EmployeeFactory.Create(2, "", "", s0, s1, 8192u, Contract.FullTime);
EmployeeServices employeeServices = new EmployeeServices();
this.DeterminePensionContribution(employeeServices, employee);
PexValue.Generated.Validate("BaseContribution", "135");
PexValue.Generated.Validate("SupplementaryContribution", "25");
}

[TestMethod]
[PexGeneratedBy(typeof(EmployeeServicesTest))]
public void DeterminePensionContribution05()
{
PexValue.Generated.Clear();
Employee employee;
DateTime s0 = new DateTime(647341024241516544L);
DateTime s1 = new DateTime(1L);
employee = EmployeeFactory.Create(2, "", "", s0, s1, 1983u, Contract.FullTime);
EmployeeServices employeeServices = new EmployeeServices();
this.DeterminePensionContribution(employeeServices, employee);
PexValue.Generated.Validate("BaseContribution", "80");
PexValue.Generated.Validate("SupplementaryContribution", "15");
}

[TestMethod]
[PexGeneratedBy(typeof(EmployeeServicesTest))]
public void DeterminePensionContribution06()
{
PexValue.Generated.Clear();
Employee employee;
DateTime s0 = new DateTime(647341024241516544L);
DateTime s1 = new DateTime(1L);
employee = EmployeeFactory.Create(2, "", "", s0, s1, 8192u, Contract.PartTime);
EmployeeServices employeeServices = new EmployeeServices();
this.DeterminePensionContribution(employeeServices, employee);
PexValue.Generated.Validate("BaseContribution", "135");
PexValue.Generated.Validate("SupplementaryContribution", "20");
}

[TestMethod]
[PexGeneratedBy(typeof(EmployeeServicesTest))]
public void DeterminePensionContribution07()
{
PexValue.Generated.Clear();
Employee employee;
DateTime s0 = new DateTime(1262076461318144L);
DateTime s1 = new DateTime(634715138118123520L);
employee = EmployeeFactory.Create(2, "", "", s0, s1, 8192u, Contract.PartTime);
EmployeeServices employeeServices = new EmployeeServices();
this.DeterminePensionContribution(employeeServices, employee);
PexValue.Generated.Validate("BaseContribution", "135");
PexValue.Generated.Validate("SupplementaryContribution", "30");
}

[TestMethod]
[PexGeneratedBy(typeof(EmployeeServicesTest))]
public void DeterminePensionContribution08()
{
PexValue.Generated.Clear();
Employee employee;
DateTime s0 = new DateTime(56623104001835008L);
DateTime s1 = new DateTime(634715138118123520L);
employee = EmployeeFactory.Create(2, "", "", s0, s1, 1983u, Contract.FullTime);
EmployeeServices employeeServices = new EmployeeServices();
this.DeterminePensionContribution(employeeServices, employee);
PexValue.Generated.Validate("BaseContribution", "80");
PexValue.Generated.Validate("SupplementaryContribution", "15");
}

[TestMethod]
[PexGeneratedBy(typeof(EmployeeServicesTest))]
public void DeterminePensionContribution09()
{
PexValue.Generated.Clear();
Employee employee;
DateTime s0 = new DateTime(647341024241516544L);
DateTime s1 = new DateTime(634715138118123520L);
employee = EmployeeFactory.Create(2, "", "", s0, s1, 8192u, Contract.FullTime);
EmployeeServices employeeServices = new EmployeeServices();
this.DeterminePensionContribution(employeeServices, employee);
PexValue.Generated.Validate("BaseContribution", "135");
PexValue.Generated.Validate("SupplementaryContribution", "30");
}

[TestMethod]
[PexGeneratedBy(typeof(EmployeeServicesTest))]
public void DeterminePensionContribution10()
{
PexValue.Generated.Clear();
Employee employee;
DateTime s0 = new DateTime(647341024241516544L);
DateTime s1 = new DateTime(1L);
employee = EmployeeFactory.Create(2, "", "", s0, s1, 1983u, Contract.PartTime);
EmployeeServices employeeServices = new EmployeeServices();
this.DeterminePensionContribution(employeeServices, employee);
PexValue.Generated.Validate("BaseContribution", "80");
PexValue.Generated.Validate("SupplementaryContribution", "0");
}

[TestMethod]
[PexGeneratedBy(typeof(EmployeeServicesTest))]
public void DeterminePensionContribution11()
{
PexValue.Generated.Clear();
Employee employee;
DateTime s0 = new DateTime(633532870975488000L);
DateTime s1 = new DateTime(126226978751643648L);
employee = EmployeeFactory.Create(2, "", "", s0, s1, 1983u, Contract.FullTime);
EmployeeServices employeeServices = new EmployeeServices();
this.DeterminePensionContribution(employeeServices, employee);
PexValue.Generated.Validate("BaseContribution", "80");
PexValue.Generated.Validate("SupplementaryContribution", "15");
}

}


When you investigate the coverage results for Visual Studio and the output from Pex, you will see that both confirm the 100% coverage result.

Part of the Pex report , coverage section (click on picture for better view):



What about my "business" assumptions? Maybe it would be easier to incorporate them as pre-conditions in the code under test. For example Start date of the contract should be greater than 25/May/1968 in the setter method for Startdatecontract of our Employee class. Non-compliance would than result in an exception being thrown. how will pex cope with them?


Thanks for reading. As always, feel free to comment.

Best regards,

Alexander

10 comments:

Richard Majece said...

As for me, it will be useful for students to learn more about gender role essay. Here you can read writing advices ad try to get a high grade in college

Jim Rhodes said...

It's nice for me to find this post. Hope to see more from you. Bye!

Dakota Leest said...
This comment has been removed by the author.
Dakota Leest said...

In my opinion you can purchase term papers online. I know the essay writing service. There you can buy an article or essay on any topic. It is convenient.

Anonymous said...

The affiliate program is a typical thing in the present-day world. Though the competition is high, those organizations that have associate projects have a greater number of clients than the organizations that don't have ones. Paying the customer for the organization's advancement is an extraordinary showcasing device, which brings a ton of advantages for the two gatherings. Thus, in the event that you are an understudy that is searching for manuals disclosing how to bring in cash from home, I can guarantee you that participation with the web-based composing administration is an excellent thought. Being an affiliate for essays writing service implies getting great cash with no expenses paid.

Anonymous said...

Affiliate for essays writing service is a feature you can use at top-papers. Order essays and recommend this writing service to your friends to earn money online.

Education Tips said...

When there was no hope, I found Grade Miners
service. I had no enough time to write my own piece before due date but them completing my sample very fast. I will definitely recommend to my mates, my grade was one of the highest in the class!

Unknown said...

Android is the core technology that is used in almost all of the latest Smartphone’s and the leading Painters Newcastle and the new born companies are using them in their new phones. The mutual benefits that you show here, can equally hold true for the other models too.

Unknown said...

Laptop trend is going to decrease with the launch of the airBooks and tablets. The same advantage can get with these http://www.serinaerfjord.com easy to carry approaches. HP Envy laptop series were released recently with the thin look and less heating effect.

spacebar counter said...

blogfreely is a self-hosted, decentralized blogging platform for publishing beautiful, simple blogs.It lets you publish a single blog, or host a community of writers who can create multiple blogs under one account. You can also enable federation, which allows people in the fediverse to follow your blog, bookmark your posts, and share them with others.
Spacebar test