America's golden age
In 2020, Cameron Esposito wins the US presidential election, sweeping to victory on a platform of side mullets and jean jackets. President Esposito and First Human Rhea Butcher raise the country to new standards of peace, dignity, and prosperity.
Among President Esposito's many achievements is a complete overhaul of the tax system. If you pretend to have extra income to impress people, that's taxable now. The economic boost you get from being attractive, that's taxable. Lying to your mother can earn you a tax penalty. Feeling guilty about something you didn't do is recognized as a legitimate life expense.
Confused tax prep company I&S Pyramid creates an Excel workbook to help people with form 1041.6.llama, the new individual income tax return. Unfortunately, grumpy I&S programmer Ronald Dump is so angered by America's new golden age that he does a lousy job.
Lily and Klaus agree to clean up Dump's mess. Let's watch them test and debug the program.
We need to start with the new tax code. This is the thing that Lily and Klaus are trying to match.
The rerevised tax code
The new system is different. Tax deductions have been replaced with tax credits, and… well, here's a picture of the worksheet, and the new rules.
The Code, So Pay Attention
Wages: 80% of the first $50,000 is taxable, 100% of the rest is taxable.
Investment income: 100% is taxable.
Imaginary extra income (the difference between your real income and what you tell your cousins at the family reunion): 40% of the first $100,000 plus 70% of the rest is taxable.
Beauty benefit (the economic edge attractive people have): 150% is taxable, because the rest of us are jealous.
$1,000 tax credit for each human dependent, up to four. No credit for additional dependents.
$1,300 tax credit if you have one dog, $3,000 if you have two, with no credit for additional dogs.
$50 tax credit for the first cat, with no additional credit for more cats.
50% credit for educational expenses.
10% credit for jean jacket expenses.
40% credit for charitable donations. Unless you told your mother that you donated more than you did, in which case there is no credit.
Line 32 will indicate whether you owe us, or we owe you.
Taxable income is taxed according to the following table:
Taxable income | Rate |
---|---|
Under 20,000 | 0% |
20,000 to 50,000 | 18% |
50,001 to 100,000 | 22% |
Above 100,000 | 28% |
Lily and Klaus
Lily and Klaus get Dump's workbook, and a copy of the tax code. The program is about 140 lines, several times longer than anything we've seen so far in this course. Their job is to test the workbook, and fix any bugs.
For now, we'll assume that users don't make mistakes when they type in data. This is unrealistic, of course. We'll add input validation later.
Let's watch Lily and Klaus at work. They're using fake accents today. I don't know why.
Ve can't test every combination of inputs. It vould take hours.
Klaus doesn't just start testing. He's thinking about it. How to do a thorough test in a reasonable time.
Bu' what?
Hmm… let's loook at the firs' bi' o' code. Maybe get ideas, lad. The income stoof.
Och, lad, I have a notion. Check oot this code:
Then…
Let me show ya. Poot in wages, an' noothin' else, an' click Run.
Lily, du bist wunderbar!
Ja, I suppose I do. I vill try to be better.
Zo, ve type in der nummers, und zee vat happens.
Aber, vhat nummers do ve type in?
Vait! I know! Ve look at ze rool in ze tax code. Type in ze numbers that test ze rule. Here is vun.
Wages: 80% of the first $50,000 is taxable, 100% of the rest is taxable.
Zo, ve type in nummer less than 50 000, und nummer more than 50 000. Check vith calculator.
But dinna forget the edge cases. Like 50,000.
Wages: 80% of the first $50,000 is taxable, 100% of the rest is taxable.
Vould be easy for programming mistake ven income is exactly 50 000.
They now have a testing strategy that makes sense for this program. There's a lot of data, but each piece of data is handled by a simple rule. (That's quite common in business programming.) They decide to test rule by rule. Including edge cases is a Good Thing. Klaus is right: it's easy to make programming mistakes when dealing with edge cases.
Hier ist der code.
Is taxable vages correct?
Lily presses F8 a few times, stepping through each line of code.
The input (incomeWages
) was right at the breakpoint, but taxableWages
is wrong at the current line. So the bug is somewhere between them.
taxableWages = 40000 '50000 * 0.8
Let's change…
taxableWages = 40000 '50000 * 0.8
… to…
taxableWages = incomeWages * 0.8
Lily,
Lily,
Über alles…
♪
Summary
Lily and Klaus looked at the code they were working with, and chose a testing and debugging strategy suited to that program. They tested one piece of data at a time. They compared the output that should have shown with what did show. When they found an error, they used breakpoints to track down the cause.