Practical Unit Testing

Image for post
Image for post
Image by 3D Animation Production Company from Pixabay

Updated Version

Scenario

const map1 = new Map();
map1.set(0,'alpha');
map1.set(1,'beta');
map1.set(2,'gamma');
map1.set(3,'omega');
map1.set(4,'theta');

If we delete the entry with index 2 the remaining indexes are [3,4] . We want a function that calculates this result and we want unit tests for it.

Approach

Notice that the way we documented our function makes it easy to unit test it.

Here’s the unit test. Note that we are testing edge conditions:

Related Concepts

Brought to You By Firefly Semantics

Founder of Firefly Semantics Corporation

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store