Why one line was rejected, or the empty string when it was fine.
(original: ReaderLine, incoming: string, index: number)
| 192 | |
| 193 | /** Why one line was rejected, or the empty string when it was fine. */ |
| 194 | function lineRefusal(original: ReaderLine, incoming: string, index: number): string { |
| 195 | const where = `sentence ${index + 1}`; |
| 196 | if (incoming.trim().length === 0) { |
| 197 | return `${where} came back empty`; |
| 198 | } |
| 199 | if (incoming.length > lengthCeiling(original.text)) { |
| 200 | return `${where} came back ${incoming.length} characters long, over the ceiling of ` |
| 201 | + `${lengthCeiling(original.text)} for a sentence of ${original.text.length}`; |
| 202 | } |
| 203 | const got = factsOf(incoming); |
| 204 | const want = original.facts; |
| 205 | for (let at = 0; at < Math.max(want.length, got.length); at += 1) { |
| 206 | if (want[at] === got[at]) { |
| 207 | continue; |
| 208 | } |
| 209 | if (want[at] === undefined) { |
| 210 | return `${where} added "${got[at]}", which is not in the sentence it was given`; |
| 211 | } |
| 212 | if (got[at] === undefined) { |
| 213 | return `${where} dropped "${want[at]}"`; |
| 214 | } |
| 215 | return `${where} says "${got[at]}" where the built sentence says "${want[at]}"`; |
| 216 | } |
| 217 | return ''; |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Put a model answer back onto the level's sentences, or refuse with a reason. |
no test coverage detected