📄 payrolltest.cpp
字号:
t.Execute();
Date payDate(11,30,2001);
PaydayTransaction pt(payDate);
pt.Execute();
ValidatePaycheck(pt, empId, payDate, 1000.00);
}
void PayrollTest::ValidatePaycheck(PaydayTransaction& pt,
int empid,
const Date& payDate,
double pay)
{
Paycheck* pc = pt.GetPaycheck(empid);
assert(pc);
assert(pc->GetPayPeriodEndDate() == payDate);
assertEquals(pay, pc->GetGrossPay(), .001);
assert("Hold" == pc->GetField("Disposition"));
assertEquals(0.0, pc->GetDeductions(), .001);
assertEquals(pay, pc->GetNetPay(), .001);
}
void PayrollTest::TestPaySingleSalariedEmployeeOnWrongDate()
{
cerr << "TestPaySingleSalariedEmployeeWrongDate" << endl;
int empId = 1;
AddSalariedEmployee t(empId, "Bob", "Home", 1000.00);
t.Execute();
Date payDate(11,29,2001);
PaydayTransaction pt(payDate);
pt.Execute();
Paycheck* pc = pt.GetPaycheck(empId);
assert(pc == 0);
}
void PayrollTest::TestPayMultipleSalariedEmployees()
{
cerr << "TestPayMultipleSalariedEmployees" << endl;
AddSalariedEmployee t1(1, "Bob", "Home", 1000.00);
AddSalariedEmployee t2(2, "Bill", "Home", 2000.00);
AddSalariedEmployee t3(3, "Barry", "Home", 3000.00);
t1.Execute();
t2.Execute();
t3.Execute();
Date payDate(11,30,2001);
PaydayTransaction pt(payDate);
pt.Execute();
assertEquals(3L, pt.GetPaycheckCount());
ValidatePaycheck(pt, 1, payDate, 1000.00);
ValidatePaycheck(pt, 2, payDate, 2000.00);
ValidatePaycheck(pt, 3, payDate, 3000.00);
}
void PayrollTest::TestPaySingleHourlyEmployeeNoTimeCards()
{
cerr << "TestPaySingleHourlyEmployeeNoTimeCards" << endl;
int empId = 2;
AddHourlyEmployee t(empId, "Bill", "Home", 15.25);
t.Execute();
Date payDate(11,9,2001); // Friday
PaydayTransaction pt(payDate);
pt.Execute();
ValidatePaycheck(pt, empId, payDate, 0.0);
}
void PayrollTest::TestPaySingleHourlyEmployeeOneTimeCard()
{
cerr << "TestPaySingleHourlyEmployeeOneTimeCard" << endl;
int empId = 2;
AddHourlyEmployee t(empId, "Bill", "Home", 15.25);
t.Execute();
Date payDate(11,9,2001); // Friday
TimeCardTransaction tc(payDate, 2.0, empId);
tc.Execute();
PaydayTransaction pt(payDate);
pt.Execute();
ValidatePaycheck(pt, empId, payDate, 30.5);
}
void PayrollTest::TestPaySingleHourlyEmployeeOvertimeOneTimeCard()
{
cerr << "TestPaySingleHourlyEmployeeOvertimeOneTimeCard" << endl;
int empId = 2;
AddHourlyEmployee t(empId, "Bill", "Home", 15.25);
t.Execute();
Date payDate(11,9,2001); // Friday
TimeCardTransaction tc(payDate, 9.0, empId);
tc.Execute();
PaydayTransaction pt(payDate);
pt.Execute();
ValidatePaycheck(pt, empId, payDate, (8 + 1.5) * 15.25);
}
void PayrollTest::TestPaySingleHourlyEmployeeOnWrongDate()
{
cerr << "TestPaySingleHourlyEmployeeOnWrongDate" << endl;
int empId = 2;
AddHourlyEmployee t(empId, "Bill", "Home", 15.25);
t.Execute();
Date payDate(11,8,2001); // Thursday
TimeCardTransaction tc(payDate, 9.0, empId);
tc.Execute();
PaydayTransaction pt(payDate);
pt.Execute();
Paycheck* pc = pt.GetPaycheck(empId);
assert(pc == 0);
}
void PayrollTest::TestPaySingleHourlyEmployeeTwoTimeCards()
{
cerr << "TestPaySingleHourlyEmployeeTwoTimeCards" << endl;
int empId = 2;
AddHourlyEmployee t(empId, "Bill", "Home", 15.25);
t.Execute();
Date payDate(11,9,2001); // Friday
TimeCardTransaction tc(payDate, 2.0, empId);
tc.Execute();
TimeCardTransaction tc2(Date(11,8,2001), 5.0, empId);
tc2.Execute();
PaydayTransaction pt(payDate);
pt.Execute();
ValidatePaycheck(pt, empId, payDate, 7*15.25);
}
void PayrollTest::TestPaySingleHourlyEmployeeWithTimeCardsSpanningTwoPayPeriods()
{
cerr << "TestPaySingleHourlyEmployeeWithTimeCardsSpanningTwoPayPeriods" << endl;
int empId = 2;
AddHourlyEmployee t(empId, "Bill", "Home", 15.25);
t.Execute();
Date payDate(11,9,2001); // Friday
Date dateInPreviousPayPeriod(11,2,2001);
TimeCardTransaction tc(payDate, 2.0, empId);
tc.Execute();
TimeCardTransaction tc2(dateInPreviousPayPeriod, 5.0, empId);
tc2.Execute();
PaydayTransaction pt(payDate);
pt.Execute();
ValidatePaycheck(pt, empId, payDate, 2*15.25);
}
void PayrollTest::TestPaySingleCommissionedEmployeeNoSalesReceipts()
{
cerr << "TestPaySingleCommissionedEmployeeNoSalesReceipts" << endl;
int empId = 3;
AddCommissionedEmployee t(empId, "Lance", "Home", 2500, 3.2);
t.Execute();
Date payDate(11,9,2001); // Friday
PaydayTransaction pt(payDate);
pt.Execute();
ValidatePaycheck(pt, empId, payDate, 2500.00);
}
void PayrollTest::TestPaySingleCommissionedEmployeeOneSalesReceipt()
{
cerr << "TestPaySingleCOmmissionedEmployeeOneSalesReciept" << endl;
int empId = 3;
AddCommissionedEmployee t(empId, "Lance", "Home", 2500, .032);
t.Execute();
Date payDate(11,9,2001); // Friday
SalesReceiptTransaction srt(payDate, 13000.00, empId);
srt.Execute();
PaydayTransaction pt(payDate);
pt.Execute();
ValidatePaycheck(pt, empId, payDate, 2500.00 + .032 * 13000);
}
void PayrollTest::TestPaySingleCommissionedEmployeeTwoSalesReceipts()
{
cerr << "TestPaySingleCommissionedEmployeeTwoSalesReceipts" << endl;
int empId = 3;
AddCommissionedEmployee t(empId, "Lance", "Home", 2500, .032);
t.Execute();
Date payDate(11,9,2001); // Biweekly Friday
SalesReceiptTransaction srt(payDate, 13000.00, empId);
srt.Execute();
SalesReceiptTransaction srt2(Date(11,8,2001), 24000, empId);
srt2.Execute();
PaydayTransaction pt(payDate);
pt.Execute();
ValidatePaycheck(pt, empId, payDate, 2500.00 + .032 * 13000 + .032 * 24000);
}
void PayrollTest::TestPaySingleCommissionedEmployeeWrongDate()
{
cerr << "TestPaySingleCommissionedEmployeeWrongDate" << endl;
int empId = 3;
AddCommissionedEmployee t(empId, "Lance", "Home", 2500, .032);
t.Execute();
Date payDate(11,16,2001); // Wrong Friday
SalesReceiptTransaction srt(payDate, 13000.00, empId);
srt.Execute();
SalesReceiptTransaction srt2(Date(11,15,2001), 24000, empId);
srt2.Execute();
PaydayTransaction pt(payDate);
pt.Execute();
Paycheck* pc = pt.GetPaycheck(empId);
assert(pc == 0);
}
void PayrollTest::TestPaySingleCommissionedEmployeeSpanMultiplePayPeriods()
{
cerr << "TestPaySingleCommissionedEmployeeSpanMultiplePayPeriods" << endl;
int empId = 3;
AddCommissionedEmployee t(empId, "Lance", "Home", 2500, .032);
t.Execute();
Date earlyDate(11,9,2001); // Previous pay period
Date payDate(11,23,2001); // Biweekly Friday
Date lateDate(12,7,2001); // Next pay period.
SalesReceiptTransaction srt(payDate, 13000.00, empId);
srt.Execute();
SalesReceiptTransaction srt2(earlyDate, 24000, empId);
srt2.Execute();
SalesReceiptTransaction srt3(lateDate, 15000, empId);
srt3.Execute();
PaydayTransaction pt(payDate);
pt.Execute();
ValidatePaycheck(pt, empId, payDate, 2500.00 + .032 * 13000);
}
void PayrollTest::TestSalariedUnionMemberDues()
{
cerr << "TestSalariedUnionMemberDues" << endl;
int empId = 1;
AddSalariedEmployee t(empId, "Bob", "Home", 1000.00);
t.Execute();
int memberId = 7734;
ChangeMemberTransaction cmt(empId, memberId, 9.42);
cmt.Execute();
Date payDate(11,30,2001);
int fridays = 5; // Fridays in Nov, 2001.
PaydayTransaction pt(payDate);
pt.Execute();
Paycheck* pc = pt.GetPaycheck(empId);
assert(pc);
assert(pc->GetPayPeriodEndDate() == payDate);
assertEquals(1000.00, pc->GetGrossPay(), .001);
assert("Hold" == pc->GetField("Disposition"));
assertEquals(fridays*9.42, pc->GetDeductions(), .001);
assertEquals(1000.0 - (fridays * 9.42), pc->GetNetPay(), .001);
}
void PayrollTest::TestHourlyUnionMemberDues()
{
cerr << "TestHourlyUnionMemberDues" << endl;
int empId = 1;
AddHourlyEmployee t(empId, "Bill", "Home", 15.24);
t.Execute();
int memberId = 7734;
ChangeMemberTransaction cmt(empId, memberId, 9.42);
cmt.Execute();
Date payDate(11,9,2001);
TimeCardTransaction tct(payDate, 8.0, empId);
tct.Execute();
PaydayTransaction pt(payDate);
pt.Execute();
Paycheck* pc = pt.GetPaycheck(empId);
assert(pc);
assert(pc->GetPayPeriodEndDate() == payDate);
assertEquals(8*15.24, pc->GetGrossPay(), .001);
assert("Hold" == pc->GetField("Disposition"));
assertEquals(9.42, pc->GetDeductions(), .001);
assertEquals((8*15.24)-9.42, pc->GetNetPay(), .001);
}
void PayrollTest::TestCommissionedUnionMemberDues()
{
cerr << "TestCommissionedUnionMemberDues" << endl;
int empId = 3;
AddCommissionedEmployee t(empId, "Lance", "Home", 2500, .032);
t.Execute();
int memberId = 7734;
ChangeMemberTransaction cmt(empId, memberId, 9.42);
cmt.Execute();
Date payDate(11,9,2001);
PaydayTransaction pt(payDate);
pt.Execute();
Paycheck* pc = pt.GetPaycheck(empId);
assert(pc);
assert(pc->GetPayPeriodEndDate() == payDate);
assertEquals(2500.00, pc->GetGrossPay(), .001);
assert("Hold" == pc->GetField("Disposition"));
assertEquals(2*9.42, pc->GetDeductions(), .001);
assertEquals(2500.0 - (2 * 9.42), pc->GetNetPay(), .001);
}
void PayrollTest::TestHourlyUnionMemberServiceCharge()
{
cerr << "TestHourlyUnionMemberServiceCharge" << endl;
int empId = 1;
AddHourlyEmployee t(empId, "Bill", "Home", 15.24);
t.Execute();
int memberId = 7734;
ChangeMemberTransaction cmt(empId, memberId, 9.42);
cmt.Execute();
Date payDate(11,9,2001);
ServiceChargeTransaction sct(memberId, payDate, 19.42);
sct.Execute();
TimeCardTransaction tct(payDate, 8.0, empId);
tct.Execute();
PaydayTransaction pt(payDate);
pt.Execute();
Paycheck* pc = pt.GetPaycheck(empId);
assert(pc);
assert(pc->GetPayPeriodEndDate() == payDate);
assertEquals(8*15.24, pc->GetGrossPay(), .001);
assert("Hold" == pc->GetField("Disposition"));
assertEquals(9.42 + 19.42, pc->GetDeductions(), .001);
assertEquals((8*15.24)-(9.42 + 19.42), pc->GetNetPay(), .001);
}
void PayrollTest::TestServiceChargesSpanningMultiplePayPeriods()
{
cerr << "TestServiceChargesSpanningMultiplePayPeriods" << endl;
int empId = 1;
AddHourlyEmployee t(empId, "Bill", "Home", 15.24);
t.Execute();
int memberId = 7734;
ChangeMemberTransaction cmt(empId, memberId, 9.42);
cmt.Execute();
Date earlyDate(11,2,2001); // previous Friday
Date payDate(11,9,2001);
Date lateDate(11,16,2001); // next Friday
ServiceChargeTransaction sct(memberId, payDate, 19.42);
sct.Execute();
ServiceChargeTransaction sctEarly(memberId, earlyDate, 100.00);
sctEarly.Execute();
ServiceChargeTransaction sctLate(memberId, lateDate, 200.00);
sctLate.Execute();
TimeCardTransaction tct(payDate, 8.0, empId);
tct.Execute();
PaydayTransaction pt(payDate);
pt.Execute();
Paycheck* pc = pt.GetPaycheck(empId);
assert(pc);
assert(pc->GetPayPeriodEndDate() == payDate);
assertEquals(8*15.24, pc->GetGrossPay(), .001);
assert("Hold" == pc->GetField("Disposition"));
assertEquals(9.42 + 19.42, pc->GetDeductions(), .001);
assertEquals((8*15.24)-(9.42 + 19.42), pc->GetNetPay(), .001);
}
//------------------------------------------
template <class T>
TestCaller<T>* makeTestCaller(char* name, void (T::*f)() )
{
return new TestCaller<T>(name, f);
}
#define ADDTEST(NAME) testSuite->addTest (makeTestCaller("NAME", &PayrollTest::NAME));
Test *PayrollTest::suite ()
{
TestSuite *testSuite = new TestSuite ("PayrollTest");
ADDTEST(TestAddSalariedEmployee);
ADDTEST(TestAddHourlyEmployee);
ADDTEST(TestAddCommissionedEmployee);
ADDTEST(TestDeleteEmployee);
ADDTEST(TestTimeCardTransaction);
ADDTEST(TestBadTimeCardTransaction);
ADDTEST(TestSalesReceiptTransaction);
ADDTEST(TestBadSalesReceiptTransaction);
ADDTEST(TestAddServiceCharge);
ADDTEST(TestChangeNameTransaction);
ADDTEST(TestChangeAddressTransaction);
ADDTEST(TestChangeHourlyTransaction);
ADDTEST(TestChangeSalariedTransaction);
ADDTEST(TestChangeCommissionedTransaction);
ADDTEST(TestChangeMailTransaction);
ADDTEST(TestChangeDirectTransaction);
ADDTEST(TestChangeHoldTransaction);
ADDTEST(TestChangeMemberTransaction);
ADDTEST(TestChangeUnaffiliatedTransaction);
ADDTEST(TestPaySingleSalariedEmployee);
ADDTEST(TestPaySingleSalariedEmployeeOnWrongDate);
ADDTEST(TestPayMultipleSalariedEmployees);
ADDTEST(TestPaySingleHourlyEmployeeNoTimeCards);
ADDTEST(TestPaySingleHourlyEmployeeOneTimeCard);
ADDTEST(TestPaySingleHourlyEmployeeOvertimeOneTimeCard);
ADDTEST(TestPaySingleHourlyEmployeeOnWrongDate);
ADDTEST(TestPaySingleHourlyEmployeeTwoTimeCards);
ADDTEST(TestPaySingleHourlyEmployeeWithTimeCardsSpanningTwoPayPeriods);
ADDTEST(TestPaySingleCommissionedEmployeeNoSalesReceipts);
ADDTEST(TestPaySingleCommissionedEmployeeOneSalesReceipt);
ADDTEST(TestPaySingleCommissionedEmployeeTwoSalesReceipts);
ADDTEST(TestPaySingleCommissionedEmployeeWrongDate);
ADDTEST(TestPaySingleCommissionedEmployeeSpanMultiplePayPeriods);
ADDTEST(TestSalariedUnionMemberDues);
ADDTEST(TestHourlyUnionMemberDues);
ADDTEST(TestCommissionedUnionMemberDues);
ADDTEST(TestHourlyUnionMemberServiceCharge);
ADDTEST(TestServiceChargesSpanningMultiplePayPeriods);
return testSuite;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -