Skip to content

Instantly share code, notes, and snippets.

@mauricioaniche
Created June 2, 2013 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauricioaniche/5694865 to your computer and use it in GitHub Desktop.
Save mauricioaniche/5694865 to your computer and use it in GitHub Desktop.
TDD study - Exercises
** Exercise 1 - Salary calculator **
The participant should implement a salary calculator. An employee contains a name,
an email, a base salary, and a position. According to his position, the calculation
rule is different:
- If he is a DEVELOPER, the employee should have a discount of 20% if his salary is
greater than or equals to 3000.00. The discount should be only 10% if salary is smaller
than that.
- If he is a DBA, the employee should have a discount of 25% if his salary is
greater than or equals to 2000.00. The discount should be 15% if salary is smaller
than that.
- If he is a TESTER, the employee should have a discount of 25% if his salary is
greater than or equals to 2000.00. The discount should be 15% if salary is smaller
than that.
- If he is a MANAGER, the employee should have a discount of 30% if his salary is
greater than or equals to 5000.00. The discount should be 20% if salary is smaller
than that.
Examples:
- DEVELOPER with salary=5000.00. Calculated salary: 4000.00
- MANAGER with salary=2500.00. Calculated salary: 2000.00
- TESTER with salary=550.00. Calculated salary: 467.50.
** Exercise 2 - Invoice generator **
The participant should implement a job responsible for the generation of invoices. This generator
creates the invoice based on a bill. A bill contains the name and address of the customer,
a description, and the amount. An invoice contains the customer's name, the amount, and the tax.
The amount of the invoice is the same of the bill. The tax is calculated based on the
following rules:
- If the description is "CONSULTANCY", the tax is 25%;
- If the description is "TRAINING", the tax is 15%;
- Any other description, 6%.
At the end of the generation process, the system should send the invoice by e-mail,
to the SAP external system, and persist it in the database. You can use the following
code to simulate the external systems:
class NotaFiscalDao {
public void salva(NotaFiscal nf) {
System.out.println("invoice persisted!");
}
}
class SAP {
public void envia(NotaFiscal nf) {
System.out.println("sap received!");
}
}
class Smtp {
public void envia(NotaFiscal nf) {
System.out.println("email sent!");
}
}
The participant is free to change the methods, received parameters or any other thing in the classes above.
** Exercise 3 - Bankslip processor **
The participant should implement a bankslip processor. The goal of the processor is to check all bankslips and,
in case that the sum of the amount of all bankslips is greater than the amount of the invoice, then this invoice
should be marked as paid.
An invoice contains a date, an amount e a customer's name. A bankslip contains a code, a date, and paid amount.
The processor, after receiving a collection of bankslips, should create a payment for each bankslip. The payment contains the total amount, the date, and the type of the payment (in this case, "BANKSLIP").
As said before, if the sum of all bankslips is greater than the amount of the invoice, it should be marked as paid.
Examples:
- Invoice=1500.00 with 3 bankslips=500.00, 400.00, 600.00. Invoice marked as paid, and 3 payments created.
- Invoice=1500.00 with 3 bankslips=1000.00, 500.00, 250.00. Invoice marked as paid, and 3 payments created.
- Invoice=2000.00 with 2 bankslips=500.00, 400.00. Invoice not marked as paid, and 2 payments created.
** Exercise 4 - Invoice filtering **
The participant should implement an invoice filter. An invoice contains a code, an amount, a date, and belongs to a customer. A customer contains a name, a date of inclusion, and a state.
Given a list of invoices, this filter should remove an invoice that matches one the following criteria:
- If the amount of the invoice is lesser than 2000.00.
- If the amount of the invoice is between 2000.00 and 2500.00, and the date is lesser than or equals to a month ago.
- If the amount of the invoice is between 2500.00 and 3000.00, and the date of the inclusion of the customer is lesser than or equals to 2 months ago.
- If the amount of the invoice is higher than 4000.00, and the state is "RS", "SC" or "PR".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment