public void calculatePayslip() { String stringPayslipPeriod = "Dec 2015"; uint annualSalary = 18000; uint superRate = 8; decimal expectedGrossIncome = 1500; decimal expectedIncomeTax = 0.00M; uint expectedNetIncome = 1500; uint expectedSuper = 120; Calculator calc = new Calculator(stringPayslipPeriod, annualSalary, superRate); uint grossIncome = calc.getGrossIncome(); decimal netIncome = calc.getNetIncome(); decimal incomeTax = calc.getIncomeTax(); decimal super = calc.getSuper(); // this will appear in the output of the testes, // we could as well use log4net for that with the // console setup Console.WriteLine("grossIncome = {0}", grossIncome); Console.WriteLine("netIncome = {0}", netIncome); Console.WriteLine("incomeTax = {0}", incomeTax); Console.WriteLine("super = {0}", super); Assert.AreEqual(expectedGrossIncome, grossIncome); Assert.AreEqual(expectedNetIncome, netIncome); Assert.AreEqual(expectedIncomeTax, incomeTax); Assert.AreEqual(expectedSuper, super); Console.WriteLine("test passed ok"); }
// here we should test all the tax ranges and boundaries conditions // for example the tax rate changes at 18000 dollarts, we should // test for 17999, 18000, 18001 and 18002 dollars salary. // However, even after $18000, the tax is still 0, till the salary // is 18231. Then the tax will be 12 dollars per year, so in the payslip // we can read 1 dollar/month public void calculateIncomeTaxTest() { String stringPayslipPeriod = "Dec 2015"; uint annualSalary = 17999; uint superRate = 8; decimal expectedIncomeTax = 0; Calculator calc = new Calculator(stringPayslipPeriod, annualSalary, superRate); decimal incomeTax = calc.getIncomeTax(); Console.WriteLine("annualSalary = {0} expected incomeTax = {1}, actual incomeTax = {2}", annualSalary, expectedIncomeTax, incomeTax); Assert.AreEqual(expectedIncomeTax, incomeTax); // this is the limit for which tax is 0 stringPayslipPeriod = "Dec 2015"; annualSalary = 18000; superRate = 8; expectedIncomeTax = 0; calc = new Calculator(stringPayslipPeriod, annualSalary, superRate); incomeTax = calc.getIncomeTax(); Console.WriteLine("annualSalary = {0} expected incomeTax = {1}, actual incomeTax = {2}", annualSalary, expectedIncomeTax, incomeTax); Assert.AreEqual(expectedIncomeTax, incomeTax); // this is over the limit of 0 tax // however up to 18231, the employee still doesn't pay // anything, after 18231, the tax is one dollar // so we can test the limit where the tax is 1 dollar. stringPayslipPeriod = "Dec 2015"; annualSalary = 18231; superRate = 8; expectedIncomeTax = 0; calc = new Calculator(stringPayslipPeriod, annualSalary, superRate); incomeTax = calc.getIncomeTax(); Console.WriteLine("annualSalary = {0} expected incomeTax = {1}, actual incomeTax = {2}", annualSalary, expectedIncomeTax, incomeTax); Assert.AreEqual(expectedIncomeTax, incomeTax); stringPayslipPeriod = "Dec 2015"; annualSalary = 18232; superRate = 8; expectedIncomeTax = 1; calc = new Calculator(stringPayslipPeriod, annualSalary, superRate); incomeTax = calc.getIncomeTax(); Console.WriteLine("annualSalary = {0} expected incomeTax = {1}, actual incomeTax = {2}", annualSalary, expectedIncomeTax, incomeTax); Assert.AreEqual(expectedIncomeTax, incomeTax); Console.WriteLine("test passed ok"); }
private Payslip calculateThePaySlip() { Payslip payslip = new Payslip(); //set the user details, say header of the payslip payslip.stringFirstName = this.stringFirstName; payslip.stringLastName = this.stringLastName; payslip.stringPayslipPeriod = this.dateTimePickerPaysleepPeriod.Value.ToString("MMM yyyy"); // set the calculated values // this is mm yyyy // we should get the number of days after the start date of employment // here we assume the employee has been working the full month // and we don't check the employment start date Calculator calculator = new Calculator(stringPayslipPeriod, uintAnnualSalary, uintSuperRate); payslip.decimalGrossIncome = calculator.getGrossIncome(); payslip.decimalIncomeTax = calculator.getIncomeTax(); payslip.decimalNetIncome = calculator.getNetIncome(); payslip.decimalSuper = calculator.getSuper(); // ready for display return payslip; }