A message arrives from the outpost next door. Their crew has shared a set of tested procedures called Greenhouse Helpers.
"It has a procedure that changes temperatures into a chart," Comet says. "We would not have to write it."
Wren reads the notes that came with it. "There is a license file too. We should read that before we use anything."
Then Comet has another idea. "We test checkPlant with numbers we pick. What if we let Beacon pick?"
Nova hovers over the list of test values. "Would you like a hint?" she asks.
"A random number helper can surprise you with values you would never think to choose."
In our story, Greenhouse Helpers is a set of procedures another crew wrote and tested.
Using existing correct algorithms as building blocks saves development time and testing.
You still need to know what each procedure does. Thanks to procedural abstraction, you do not need to know how.
You must also acknowledge code that came from someone else, including where it came from or who wrote it.
RANDOM(a, b) returns a random whole number from a to b, including both. Each result is equally likely.
For example, RANDOM(1, 3) could return 1, 2 or 3.
Using random numbers means each run of a program may give a different result.
REPEAT 5 TIMES
{
testLevel ← RANDOM(0, 100)
DISPLAY(testLevel)
DISPLAY(checkPlant(testLevel))
} | Statement | True or false? |
|---|---|
| RANDOM(0, 100) can return 0. | ? |
| RANDOM(0, 100) can return 100. | ? |
| Random test values replace the need to test the edge values you choose on purpose. | ? |
| You should acknowledge code that came from another source. | ? |
Sharp thinking. Tomorrow is Impact Friday: licenses, credit and sharing fairly.