Code Monkey home page Code Monkey logo

collectionstdd's Introduction

TDD Exercise: Most Recently Used List

Introduction

This is a practice exercise to develop your TDD skills. The source code is an example solution you can consult after attempting the exercise.

Instructions

Read the specification below, and develop implementation.

  1. If you do not have it already, install the NUnit 3 Test Adapater extension from the Tools>Extensions and Updates menu in Visual Studio.
  2. Create a class library project called MruListExercise.
  3. Install NUnit 3.x from the Package Manager Console (if not visible it is accessible from View>Other Windows) by entering install-package nunit
  4. Create a class MruListTests to hold your tests. Add the NUnit.Framework namespace to your using declarations and create an empty test decorated with the [Test] attribute. Check that you can run your test from the Test>Run>All Tests menu. Pin the Test Explorer window that should show the passing test. Note the Ctrl+R, A default extension to run all tests.
  5. Remember the laws of TDD:
  • First Law You may not write production code until you have written a failing unit test. (Run it to check it fails).
  • Second Law You may not write more of a unit test than is sufficient to fail, and not compiling is failing.
  • Third Law You may not write more production code than is sufficient to pass the currently failing test. (Run tests to check they all pass).

And bear in mind these guidelines:

  • Keep your code and tests clean - Red, Green, Refactor
  • One logical assert per test
  • Start with the degenerate test cases.
  • As the test gets more specific, the code gets more generic.

Specification

Develop a most-recently-used-list class to hold strings uniquely in Last-In-First-Out order such that:

  • A recently-used-list is initially empty.
  • The most recently added item is first, the least recently added item is last.
  • Items can be looked up by index, which counts from zero.
  • Items in the list are unique, so duplicate insertions are moved rather than added.
  • Optional extras
  • Null insertions (empty strings) are not allowed.
  • A bounded capacity can be specified, so there is an upper limit to the number of items contained, with the least recently added items dropped on overflow.

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.