Tests, and building a program
1.[3p] Why does a hand written check helper compare with JSON.stringify rather than ===?
Why does a hand written check helper compare with JSON.stringify rather than ===?
2.[3p] What did Dijkstra's 1969 remark about testing say?
What did Dijkstra's 1969 remark about testing say?
3.[3p] Which of these cases are worth writing a test for?
Which of these cases are worth writing a test for?
Select all that apply
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.
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.
5.[2p] Number("4.35") * 100 does not give a whole number. What does Math.round(Number("4.35") * 100) give?
Number("4.35") * 100 does not give a whole number. What does Math.round(Number("4.35") * 100) give?
6.[3p] Put these steps of building a program by decomposition in order.
Put these steps of building a program by decomposition in order.
Move on to the next piece
Assemble the tested pieces into the finished program
Write the smallest piece that can be tested on its own
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.
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.
8.[3p] Match each function of the expenses program to its job.
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?
Why is largest([-5, -2]) a test worth writing?