Skip to content

Commit

Permalink
feat: update testing exercises' solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
anitvam committed Nov 11, 2023
1 parent f4a8cd4 commit bd6e2df
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions java/testing/junit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Consider the *Banking* domain of previous labs: `AccountHolder`s, `BankAccount`s, and their implementations.

1. Look at the class `TestSimpleBankAccount` that test `SimpleBankAccount` implementation.
2. Write tests described in class `TestStrictBankAccount` that test `StrictBankAccount`.
1. Look at the class `TestSimpleBankAccount` that tests `SimpleBankAccount` implementation.
2. Write tests described in class `TestStrictBankAccount` that tests `StrictBankAccount`.

Notes: Consult the [JavaDoc of JUnit 5](https://junit.org/junit5/docs/5.0.1/api/org/junit/jupiter/api/package-summary.html)
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void chargeManagementFees(final int id) {
this.balance -= SimpleBankAccount.MANAGEMENT_FEE;
resetTransactions();
} else {
throw new IllegalArgumentException("ID not corresponding: cannot charge management fees.");
throw new IllegalArgumentException("ID not corresponding: cannot charge management fees");
}
}

Expand Down Expand Up @@ -77,7 +77,7 @@ private void transactionOp(final int id, final double amount) {
this.balance += amount;
this.incrementTransactions();
} else {
throw new IllegalArgumentException("ID not corresponding: cannot perform transaction.");
throw new IllegalArgumentException("ID not corresponding: cannot perform transaction");
}
}
}
7 changes: 6 additions & 1 deletion java/testing/tdd-deathnote/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ Use the *Test-Driven Development (TDD)* methodology to develop the following.

1. Observe the `DeathNote` interface, understand how it is supposed to work
2. Create an implementation of `DeathNote` in which each method throws an Exception
2. Write a test for the class (the test will fail and that is okay) that:
3. Write a test for the `DeathNote` implementation (the test will fail and that is okay) testing that:
1. Rule number 0 and negative rules do not exist in the DeathNote rules.
2. No rule is empty or null in the DeathNote rules.
3. The human whose name is written in the DeathNote will eventually die.
4. Only if the cause of death is written within the next 40 milliseconds of writing the person's name, it will happen.
5. Only if the cause of death is written within the next 6 seconds and 40 milliseconds of writing the death's details, it will happen.

**Important notes**:
* the current time measured as seconds since the Unix epoch is available as `System.currentTimeMillis()`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.unibo.tdd;
package it.unibo.deathnote.api;

import java.util.List;

Expand All @@ -23,7 +23,7 @@ public interface DeathNote {
""",
"""
After writing the cause of death, details of the death should be written in the next 6
minutes and 40 seconds.
seconds and 40 milliseconds.
""",
"""
The human who touches the Death Note can recognize the image and voice of its original
Expand Down Expand Up @@ -83,8 +83,8 @@ public interface DeathNote {

/**
* The human whose name is written in this DeathNote will die.
*
* @param name the name of the human to kill
* @throws NullPointerException if the given name is null.
*/
void writeName(String name);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package it.unibo.tdd;
package it.unibo.deathnote.impl;

import it.unibo.deathnote.api.DeathNote;

import java.util.LinkedHashMap;
import java.util.Map;
Expand All @@ -24,8 +26,6 @@ public void writeName(String name) {
deaths.put(name, new Death());
}



@Override
public boolean writeDeathCause(final String cause) {
return updateDeath(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package it.unibo.tdd;
package it.unibo.deathnote;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.List;
import it.unibo.deathnote.api.DeathNote;
import it.unibo.deathnote.impl.DeathNoteImplementation;

import static it.unibo.tdd.DeathNote.RULES;
import static it.unibo.deathnote.api.DeathNote.RULES;
import static java.lang.Thread.sleep;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.*;

class TestDeathNote {

Expand Down

0 comments on commit bd6e2df

Please sign in to comment.