### Question:
Payslip { public double getNet() { final double ltbg = Math.max(Math.min(sal, 20000.0) - 5000, 0.0); final double mtbg = Math.max(Math.min(sal, 40000) - 20000, 0.0); final double utbg = Math.max(sal - 40000, 0.0); return sal - (ltbg * 0.1 + mtbg * 0.2 + utbg * 0.4); } Payslip(final double slry); double getNet();  }### Answer:
@Test public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { Payslip payslip = new Payslip(5000); assertEquals(5000, payslip.getNet(), 1e-6); }
@Test public void taxOnAmountInLowerTaxBracketExcludesTaxFreeLimit() { final Payslip payslip = new Payslip(10000); assertEquals(9500, payslip.getNet(), 1e-6); final Payslip payslip2 = new Payslip(20000); assertEquals(18500, payslip2.getNet(), 1e-6); }
@Test public void taxOnAmountInMiddleTaxBracketIsSumOfLowerTaxBracketAmountAndAdditionalMiddleTaxBracketAmount() { final Payslip payslip = new Payslip(25000); assertEquals(22500, payslip.getNet(), 1e-6); final Payslip payslip2 = new Payslip(40000); assertEquals(34500, payslip2.getNet(), 1e-6); }
@Test public void taxOnAmountInUpperTaxBracketIsSumOfLowerTaxBracketAmountAndMiddleTaxBracketAmountAndAdditionalUpperTaxBracketAmount() { final Payslip payslip = new Payslip(50000); assertEquals(40500, payslip.getNet(), 1e-6); final Payslip payslip2 = new Payslip(60000); assertEquals(46500, payslip2.getNet(), 1e-6); }