1
1
Fork 0

Edited "Preventing Failure" and "Power Tools" sections

Files containing only a newline at the end of the file indicate that I have reviewed that task and didn't need to change anything. The file now has a new timestamp indicating it has been reviewed.
This commit is contained in:
Bruce Eckel 2020-10-12 04:11:53 -06:00
parent f24424b4e1
commit ec9381a33c
45 changed files with 143 additions and 144 deletions

View File

@ -2,7 +2,7 @@
Create a generic interface called `Items` with a single function `next()` that
returns an object of the generic type, or `null`. Make `Items` usable for
[SAM conversions](#sam-conversions).
SAM conversions.
Create a generic function called `itemIter()` that takes a `vararg items` of
the type parameter and returns an `Items` object produced with a SAM
@ -13,6 +13,6 @@ and increments `index`. When there are no more `items`, `next()` returns
The code in `main()` tests your solution.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -11,6 +11,6 @@ Define a member function `add()` that takes a generic `item` argument, creates
a `DecoratedCrate` with it and adds the result to the `ArrayList`. The code in
`main()` tests your solution.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -5,6 +5,6 @@ that implements both `InCrate` and `OutCrate`. The code in `main()` tests your
solution by upcasting from `Crate<Grape>` to `OutCrate<Can>` and from
`Crate<Can>` to `InCrate<Grape>`.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -19,6 +19,6 @@ The code in `main()` tests your functions against the standard library
versions. Notice that `buildList()` and `buildMap()` infer their generic
parameters.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -10,6 +10,6 @@ user can provide a `Sandwich` receiver that may or may not be already toasted.
The starter code and the code in `main()` tests your functions.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -4,6 +4,6 @@ The starter code contains definitions for `class Cleanser` and `class
SprayCleanser`. Write the functions `cleanser()` and `sprayCleanser()` so the
code in `main()` works correctly.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -28,4 +28,4 @@ Finish the initialization for `turbines`, then add
`fun generator(number: Int): Generator` which checks to make sure `number`
is in range, then returns the desired generator. Finally, add a `status()`
member function that uses `forEach` to show the status of each generator in the
`PowerPlant`. The code in `main()` tests your solution.
`PowerPlant`. The code in `main()` tests your solution.

View File

@ -8,6 +8,6 @@ Create a `lateinit` `car` at file scope, and a `lateinit` `truck` inside
`main()`. Initialize `car` inside `main()`, giving it an electric motor,
then initialize `truck`, giving it a combustion engine.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -10,6 +10,6 @@ If `A` is the library someone else has created and that you are consuming,
`lazy` initialization can be a convenient way to configure its `lateinit`
properties.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -2,6 +2,6 @@
Modify `PropertyOptions.kt` so that "Compute 4" appears in the trace.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -7,6 +7,6 @@ name>.<property name>": `s1` and `s2` in `Outer`, and `si` in `Inner`. The
initializers produce "Hi" for `s1`, "Hello $s1" for `s2`, and "Howdy $s2" for
`si`. The starter code in `main()` tests your solution.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -19,6 +19,6 @@ In `main()`, add a lazily-initialized `val a` that traces its initialization
as above and then produces an `A` object. The remainder of `main()` is starter
code that tests your solution.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -15,6 +15,6 @@ object but `current` automatically stays within `range`.
Make any necessary modifications so the starter code in `main()` produces the
exercise output shown.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -16,6 +16,6 @@ such that if `++` tries to go past `Moe`, it wraps around to `Eeny`, and if
`--` tries to go below `Eeny`, it wraps around to `Moe`. The starter code
in `main()` will check your work.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -20,6 +20,6 @@ Add a `toString()` that produces `list` separated by commas.
The starter code in `main()` tests `Repository` and shows you how the error
messages should appear.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -7,10 +7,10 @@ default value of `false`. In `main()`, create three `var`s: `d` of type `Double`
for `notNull()`.
Using `capture` from `atomictest`, try reading from `d`, `s` and `f` before
they are initialized and validate the output using `atomictest.eq`. Then set
they are initialized. Validate the output using `atomictest.eq`. Then set
`d` to `1.1`, `s` to `"yes"` and `f` to `Flag(true)` and use `eq` to verify
that they all take on the new values.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -14,6 +14,6 @@ class Product(nm: String = "<0>", id: Int = -1) {
And that the starter code in `main()` successfully executes.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -4,6 +4,6 @@ Create a `class PositiveInt(i: Int)` containing a property `var n` such that
any value assigned to `n` can only be greater than zero. The starter code in
`main()` will test your solution.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -3,6 +3,6 @@
Convert `Configuration.kt` to use a `Map` instead of a file. The starter code
in `main()` tests your new `Configuration` class.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -4,6 +4,6 @@ Starting with `Add.kt`, add a `setValue()` extension function to `Sum` that
assigns its `value` argument to `a` in `Add` (change `Add` to make this work).
The starter code in `main()` tests your solution.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -20,6 +20,6 @@ class Holders {
The starter code in `main()` will test your solution.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -11,6 +11,6 @@ results of `add()`, `subtract()`, and `multiply()`. Use `eq` to check the
result. Duplicate this functionality creating `result2` using `let` and
`result3` using `with`.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -17,6 +17,6 @@ end of that block, chain to a `run` block, then an `apply` block and an `also`
block, performing the same operations in each block. Use `trace` to verify the
output.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -7,6 +7,6 @@ subtract()` and after closing the scope, call `calc()`. Use `eq` to check that
the result is 77. The return value from the `run()` scope is `z + add()`; use
`eq` to check that the result is 1077.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -13,6 +13,6 @@ element and every other one, ignoring the elements in between.
The starter code in `main()` tests your work.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -20,6 +20,6 @@ and 8 removed. Display the list with the element 10 removed. Use the
The starter code in `main()` tests your work.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -19,6 +19,6 @@ for using the object as a key in a `Map` and an element in a `Set`. As this
exercise shows, you should be very reluctant to allow the values used in the
`compareTo()` calculation to vary.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -18,6 +18,6 @@ custom error message for `require()`. If the `require()` succeeds, return `d`.
The starter code in `main()` tests `f()` and `g()`.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -9,6 +9,6 @@ new functions as:
The starter code in `main()` tests `fn()` and `gn()`.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -1,8 +1,7 @@
## Check Instructions (#3)
This exercise further explores ranges, introduced in [Looping &
Ranges](#looping-and-ranges), and shows how they can be used with check
instructions.
This exercise further explores ranges, introduced in the atom Looping & Ranges,
and shows how they can be used with check instructions.
Create a class `Level` with two constructor arguments: `val range: IntRange`,
and `private var level: Int`. `level` has a default argument that is the
@ -18,6 +17,6 @@ that `new` is within `range` and then assigns `new` to `level`.
`Level` is tested by the starter code in `main()`.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -51,6 +51,6 @@ expected output for `trace`.
Consider the complexity of the resulting code, and evaluate which exceptions
could be replaced with ordinary non-exceptional code.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -32,6 +32,6 @@ can be significantly more complicated.
2. The concept of recovery assumes that there's a *way* you can recover from a
failed function call. Often, however, this is simply not true.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -38,6 +38,6 @@ network connection isn't particularly problematic.
Again, notice how rapidly things get complicated when attempting to recover
from all possible failures.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -1,7 +1,7 @@
## Logging (#1)
The starter code includes `class Level`, which is the solution of Exercise 3
from [Check Instructions].
from the Check Instructions atom.
Create a class called `Pipe` that takes `val level: Level` as a constructor
parameter. Give this parameter a default argument with a range `0..10`.
@ -19,6 +19,6 @@ Create a member function `checkLevel()` that uses a `when` expression. When
The log message for each call is just "Level " followed by the matched value.
The starter code in `main()` tests your solution.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -1,7 +1,7 @@
## Logging (#2)
Starting with the solution from Exercise 3 in [Exception
Handling](#exception-handling), use `AtomicLog.kt` to log exceptions into the
Starting with the solution from Exercise 3 from the Exception
Handling atom, use `AtomicLog.kt` to log exceptions into the
`Logger` file `"LoggingSoln1.txt"`. You will need to modify `transact()`:
- Add a call to `Logger`s `error()` function before any exception is thrown
@ -13,6 +13,6 @@ Handling](#exception-handling), use `AtomicLog.kt` to log exceptions into the
you can to log to `error()` and fail, rather than having multiple `catch`
clauses.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -7,6 +7,6 @@ called `debugLevel` at file scope, initialized to `Error`. Inside your new
log(thisLevel: Level, msg: String)`. This will require small modifications to
some other functions. The code in `main()` tests your solution.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -8,6 +8,6 @@ to call for `File`). Use `useLines()` to read the file and display it with
`println()`, then use `forEachLine()` to read the file and display it with
`println()`. The starter code in `main()` tests `writeAndRead()`.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -5,6 +5,6 @@ Create your own `AutoCloseable` class called `Cleanup`, containing `f()`, `g()`,
and `"close()"`, respectively. In `main()`, create a `Cleanup` object and call
`f()`, `g()` and `h()` via `use()`.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -20,6 +20,6 @@ Define a function `verifyClose(opt: Option)`. `verifyClose()` creates a
`main()` tests your code.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -4,10 +4,10 @@ Create an exception class called `Failure` that takes a `msg: String` parameter
and passes it to the base-class constructor. Write a function `fail(msg:
String)` that passes `msg` to `trace()`, and then throws a `Failure`.
Now write your own versions of `require()` and `check()` (from [Check
Instructions](#check-instructions)) that use `fail()`. The starter code in
`main()` tests your functions.
Now write your own versions of `require()` and `check()` (from the Check
Instructions atom) that use `fail()`. The starter code in `main()` tests your
functions.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -10,6 +10,6 @@ Modify Exercise 1 by creating an `object Log` that contains a `private` mutable
In `fail()`, add the `msg` to `Log` before throwing `Failure`. The starter
code in `main()` tests your work.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -7,6 +7,6 @@ it to `true`. Define `fun debug(test: Boolean)` so that it always calls
discover the format of the `trace()` message), but only performs the `debug()`
activity if `_debug` is `true`. The starter code in `main()` tests your work.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -5,6 +5,6 @@ using the code in `main()` as inspiration. Create two test functions named
"train travel" and "bus travel" and use `assertEquals()` from `kotlin.test` to
compare the expected output to the actual output.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -5,6 +5,6 @@ type of `Computer`, and use the default test function names created by IntelliJ
IDEA. Use `assertEquals()` from `kotlin.test` to compare the expected output to
the actual output.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>

View File

@ -14,6 +14,6 @@ infix fun <T> T.aeq(actual: T) =
To use `aeq`: *expectedValue* `aeq` *actualValue*.
<sub> This task doesn't contain the automatic tests,
it's always marked as "Correct" on "Check".
Please compare your solution with the provided one! </sub>
<sub> This task doesn't contain automatic tests,
so it's always marked as "Correct" when you run "Check".
Please compare your solution with the one provided! </sub>