Giter Club home page Giter Club logo

unit_testing_capital_city_finder's Introduction

Unit Testing a Capital City Finder Program

Through this project I sought to deepen my experience in component testing and to discover Jest, a JavaScript testing framework.

Test Basis: Capital City Finder

The 'Capital City Finder' program accepts a state (country or region) as an argument and returns the corresponding capital city. The program must be extensive, covering every United Nations–⁠recognised country, in addition to many regions, e.g., the capital of the Dutch province of South Holland is Rotterdam.

Program Specification: Capital Finder Module

Unlike other programming languages, JavaScript cannot create associative arrays, however the same functionality may be achieved using objects. In this case, the object cityFinder is defined with an object literal of state–capital (property–value) pairs, eg. "Republic of the Congo": "Brazzaville". The following function accesses the cityFinder object and, should the argument match a property, returns the property's value:

function returnCapital(state) {
    return cityFinder[state];
}

Thus, supplying the input Malaysia returns the value Kuala Lumpur. The combination of the cityFinder object and the returnCapital(state) function may be thought of collectively as the capital finder module.

Unit Test Planning: How to Test the Program

To ensure the extensiveness of the capital finder module (i.e. app.js file) test data should cover a collection of geographically and culturally disparate states. This approach aknowledges the risk of a particular cultural bias, especially a pro-Occidental or a pro-Anglo-Saxon one, during development resulting in a disregard for dissimilar countries. For this reason, it is advantageous that each test condition concern one of the six inhabited continents: Africa, Asia, Europe, North America, South America and Oceania.

Jest is an open-source library that simplifies performing tests in JavaScript. In this project Jest is installed and the test script of package.json is set to "jest" so that Jest runs when npm test is entered in the command line. The statement module.exports = returnCapital exports the function to be tested from the app.js file. The function is then imported into the newly created app.test.js file via const returnCapital = require('./app'). The Jest method test('', () => {expect().toBe()}) verifies expected output against actual output for a given input.

Test Cases

Project Name: Capital City Finder
Created By: Ainsley
Creation Date: 21/01/20
Test Condition ID: Af
Test Condition Description: Verify that the program returns the correct capital city for a given African country or province.

Test Case ID Test Data Expected Outcome Actual Outcome Status
Af-01 "Liberia" "Monrovia" "Monrovia" Passed
Af-02 "Mozambique" "Maputo" "Maputo" Passed
Af-03 "Senegal" "Dakar" "Dakar" Passed

Test Condition ID: As
Test Condition Description: Verify that the program returns the correct capital city for a given Asian country or province.

Test Case ID Test Data Expected Outcome Actual Outcome Status
As-01 "Kyrgyzstan" "Bishkek" "Bishkek" Passed
As-02 "South Korea" "Seoul" "Seoul" Passed
As-03 "Taiwan" "Taipei" "Taipei" Passed

Test Condition ID: Eu
Test Condition Description: Verify that the program returns the correct capital city for a given European country or province.

Test Case ID Test Data Expected Outcome Actual Outcome Status
Eu-01 "Bosnia and Herzegovina" "Sarajevo" "Sarajevo" Passed
Eu-02 "Cyprus" "Nicosia" "Nicosia" Passed
Eu-03 "Lithuania" "Vilnius" "Vilnius" Passed

Test Condition ID: No
Test Condition Description: Verify that the program returns the correct capital city for a given North American country or province.

Test Case ID Test Data Expected Outcome Actual Outcome Status
No-01 "Cuba" "Havana" "Havana" Passed
No-02 "Jamaica" "Kingston" "Kingston" Passed
No-03 "Quebec" "Quebec City" "Quebec City" Passed

Test Condition ID: So
Test Condition Description: Verify that the program returns the correct capital city for a given South American country or province.

Test Case ID Test Data Expected Outcome Actual Outcome Status
So-01 "Guyana" "Georgetown" "Georgetown" Passed
So-02 "Paraguay" "Asunción" "Asunción" Passed
So-03 "Suriname" "Paramaribo" "Paramaribo" Passed

Test Condition ID: Oc
Test Condition Description: Verify that the program returns the correct capital city for a given Oceanian country or province.

Test Case ID Test Data Expected Outcome Actual Outcome Status
Oc-01 "Australia" "Canberra" "Canberra" Passed
Oc-02 "New Zealand" "Wellington" "Wellington" Passed
Oc-03 "Vanuatu" "Port Vila" "Port Vila" Passed

unit_testing_capital_city_finder's People

Contributors

ainsleycrawford avatar

Stargazers

Gulam Qasim avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.