Practice question · Put in order
Order the tasks of building the word-frequency counter so that each one can be tested as soon as it is written.
- Write and test a function that splits a string into lower-case words
- Wire the three functions together into one pipeline
- Write an integration test that runs the pipeline on a small file with a known answer
- Write and test a function that returns the ten highest counts from that dictionary
- Write and test a function that turns a list of words into a word-to-count dictionary
Hints
- Each function consumes what the previous one produces, so it cannot be tested before that one exists.
- Integration testing is only possible once there is something integrated to test.
Show the answer
- Write and test a function that splits a string into lower-case words
- Write and test a function that turns a list of words into a word-to-count dictionary
- Write and test a function that returns the ten highest counts from that dictionary
- Wire the three functions together into one pipeline
- Write an integration test that runs the pipeline on a small file with a known answer
Why
Building along the direction of data flow means every function can be unit-tested the moment it is written, using real output from the stage before. The integration test comes last because it exercises the interfaces, which only exist once the pieces are wired together.
Practise Integrated Programming Synthesis
The app has 5 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Integrated Programming Synthesis
- A word-frequency counter needs to split text, normalise case, count occurrences and report the top results.…
- A word-frequency program is asked to handle a 50 GB file that will not fit in memory. Which part of the…
- Sort each part of the word-frequency program by whether it can be written as a pure function or must carry…
- Select every edge case the lesson says the word-frequency counter's tests should cover.