Sign in

Libre University uses your GitHub account. Signing in is only needed to sit a final test, so the score is kept on your profile.

Tests, and building a program

1.[3p]

Why does a hand written check helper compare with JSON.stringify rather than ===?

Correct
The answer is: `===` on two arrays or objects with identical contents is false, since it compares identity rather than value
The answer is: `===` on two arrays or objects with identical contents is false, since it compares identity rather than value
The answer is: `===` on two arrays or objects with identical contents is false, since it compares identity rather than value

2.[3p]

What did Dijkstra's 1969 remark about testing say?

Correct
The answer is: Testing can show the presence of bugs, but never their absence
The answer is: Testing can show the presence of bugs, but never their absence
The answer is: Testing can show the presence of bugs, but never their absence

3.[3p]

Which of these cases are worth writing a test for?

Select all that apply

Correct
Correct
Correct
Correct
The answer is: Empty input, A single element, Input the function is expected to reject, The exact case that produced a bug you have just fixed

4.[2p]

What is the name for a test written from a bug you have just fixed, so that it cannot come back unnoticed? Write one word.

CorrectNot quite: regression

5.[2p]

Number("4.35") * 100 does not give a whole number. What does Math.round(Number("4.35") * 100) give?

CorrectNot quite: 435

6.[3p]

Put these steps of building a program by decomposition in order.

  1. Move on to the next piece

  2. Assemble the tested pieces into the finished program

  3. Write the smallest piece that can be tested on its own

  4. Write the tests that pin down what that piece does

Show the answer

b, c, d, a

7.[2p]

A new test should be seen to fail before the code that makes it pass is written, because a test that has never failed might not be exercising the behaviour at all.

Correct
The answer is: True

8.[3p]

Match each function of the expenses program to its job.

  • parseAmount

  • parseLine

  • parseAll

  • totalsByCategory

  • formatPence

  • groups the records and sums each group

  • turns whole pence back into a printable string

  • splits the text, drops blank lines, and parses the rest

  • validates the shape of one line and returns a record

  • turns a text amount into whole pence

Show the answer

parseAmount: turns a text amount into whole pence parseLine: validates the shape of one line and returns a record parseAll: splits the text, drops blank lines, and parses the rest totalsByCategory: groups the records and sums each group formatPence: turns whole pence back into a printable string

9.[3p]

Why is largest([-5, -2]) a test worth writing?

Correct
The answer is: It catches the common bug of starting the accumulator at 0 rather than at the first element
The answer is: It catches the common bug of starting the accumulator at 0 rather than at the first element
The answer is: It catches the common bug of starting the accumulator at 0 rather than at the first element