Skip to content

Commit

Permalink
Duck Pond Removal Service
Browse files Browse the repository at this point in the history
  • Loading branch information
laboon committed Sep 4, 2015
1 parent 699c178 commit 786755d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
8 changes: 4 additions & 4 deletions text/40_unit_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ public double getSquareRoot(double val) {

Assuming no floating-point rounding errors or errors of that nature, the square root of 25 will always be 5, no matter what global variables are set, no matter what time or date it is, no matter what. There are also no side effects from calling a square root function; it's not as though a window pops up every time your system calculates a square root.

An example of an impure function would be printing out statistics from global variables, or any method which outputs something to the console or screen, or depends upon variables that are not specifically passed in. In general, if you see a method with a void return, it's probably impure---a pure function with a void return type would be absolutely useless, since the returned value is its only way of communicating with the rest of the program. Here is an example of an impure function:
An example of an impure function would be printing out statistics from global variables, or any method which outputs something to the console or screen, or depends upon variables that are not specifically passed in. In general, if you see a method with a void return, it's probably impure---a pure function with a void return type would be absolutely useless, since the returned value is its only way of communicating with the rest of the program. Here is an example of an impure function, which allows users to go to a cat cafe (that is, a place where you can drink coffee and pet cats):

```java
public void haveFunAtDuckPond(DuckPond duckPond) {
System.out.println("Having fun at the duck pond");
duckPond.haveFun();
public void goToCatCafe(CatCafe catCafe) {
System.out.println("Petting cats at a Cat Cafe!");
catCafe.haveFun();
}
```

Expand Down
11 changes: 4 additions & 7 deletions text/41_advanced_unit_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,12 @@ Now when the `mockedDogFood` object has its `.eat()` method called, it will retu

## Mocks and Verification

"Yes, yes, this is all fine," I can hear you saying, "but you didn't answer the original question! We are still dependent on asserting on a value that is returned from a method, and thus won't be able to test methods without a return value!" Remember the method that we wanted to test from earlier in the chapter:
"Yes, yes, this is all fine," I can hear you saying, "but you didn't answer the original question! We are still dependent on asserting on a value that is returned from a method, and thus won't be able to test methods without a return value!" Remember the impure method `goToCatCafe` that we wanted to test from in the last chapter:

```java
public class Person {

public void haveFunAtDuckPond(DuckPond duckPond) {
duckPond.haveFun();
}

public void goToCatCafe(CatCafe catCafe) {
System.out.println("Petting cats at a Cat Cafe!");
catCafe.haveFun();
}
```

Expand Down

0 comments on commit 786755d

Please sign in to comment.