1
1
Fork 0

Updated answer placeholders for exercises in 'Preventing Failure'

This commit is contained in:
Svetlana Isakova 2020-10-20 16:57:48 +02:00
parent 29e1e4fb1a
commit 1831266105
3 changed files with 46 additions and 35 deletions

View File

@ -3,8 +3,24 @@ files:
- name: src/Task.kt
visible: true
placeholders:
- offset: 1086
length: 829
placeholder_text: TODO()
- offset: 1272
length: 18
placeholder_text: println("Database Problem $e")
- offset: 1436
length: 70
placeholder_text: |-
catch (e: NetworkFail) {
println("Network Problem $e")
return Failed
} catch (e: DBWriteFail) {
println("Database Write Failed $e")
return Failed
}
- offset: 1603
length: 18
placeholder_text: println("Network Close Failed $e")
- offset: 1856
length: 18
placeholder_text: println("Database Problem $e")
- name: test/Tests.kt
visible: false

View File

@ -8,7 +8,7 @@ enum class Level {
Trace, Debug, Info, Warn, Error
}
var debugLevel = Error
var debugLevel: Level = Error
class Logger(fileName: String) {
val logFile = DataFile(fileName).reset()
@ -21,6 +21,8 @@ class Logger(fileName: String) {
fun info(msg: String) = log(Info, msg)
fun warn(msg: String) = log(Warn, msg)
fun error(msg: String) = log(Error, msg)
// Added for basic testing:
fun report(msg: String) {
trace(msg)
debug(msg)

View File

@ -3,38 +3,31 @@ files:
- name: src/Task.kt
visible: true
placeholders:
- offset: 107
- offset: 161
length: 31
placeholder_text: // import loggingExercise3.Level.*
- offset: 140
length: 679
placeholder_text: // TODO
- offset: 834
length: 553
placeholder_text: '// TODO: add values'
- offset: 305
length: 154
placeholder_text: |-
/*
Level.values().toList().forEach {
debugLevel = it
logger.report("debugLevel($debugLevel)")
}
logger.logFile.readText().trimIndent() eq
"""
Trace: debugLevel(Trace)
Debug: debugLevel(Trace)
Info: debugLevel(Trace)
Warn: debugLevel(Trace)
Error: debugLevel(Trace)
Debug: debugLevel(Debug)
Info: debugLevel(Debug)
Warn: debugLevel(Debug)
Error: debugLevel(Debug)
Info: debugLevel(Info)
Warn: debugLevel(Info)
Error: debugLevel(Info)
Warn: debugLevel(Warn)
Error: debugLevel(Warn)
Error: debugLevel(Error)
"""
*/
private fun log(type: String, msg: String) =
logFile.appendText("$type: $msg\n")
- offset: 487
length: 15
placeholder_text: log("Trace", msg)
- offset: 530
length: 15
placeholder_text: log("Debug", msg)
- offset: 572
length: 14
placeholder_text: log("Info", msg)
- offset: 613
length: 14
placeholder_text: log("Warn", msg)
- offset: 655
length: 15
placeholder_text: log("Error", msg)
- offset: 220
length: 5
placeholder_text: TODO()
- name: test/Tests.kt
visible: false