Giter VIP home page Giter VIP logo

missingnumberfinder's Introduction

Summary

This repo explores how to use XUnit Theory tests with the InlineData attribute.

Problem

A given sequence of whole numbers all have the same delta (Δ), yet one number is missing. Find the missing number. For example:

Example 1: {1,2,4} Δ=1, Missing = 3
Example 2: {1,3,4} Δ=1, Missing = 2
Example 3: {2,6,8} Δ=2, Missing = 4
Example 4: {1,2,4,5} Δ=1, Missing = 3
Example 5: {10,20,40,50} Δ=10, Missing = 30
Example 6: {10,20,30,50} Δ=10, Missing = 40

Sequences of length 0, 1, or 2 are invalid. Malformed sequnces will not be passed in (all sequences are assumed to be legit)

Use of XUnit

This project makes use of XUnit Theory tests to allow multiple sequences to easily be tested. In each case, a sequence is passed as inline data, with the "missing" number being the last one. In the code below, the "real" sequence is:

{1, 2, 3, 4}

The theory tests allow different ways of expressing the missing number. For example:

[InlineData(1, 2, 4, 3)]

... represents the sequence {1,2,3,4}, but the "3" is missing. By placing the "3" at the end, the test Asserts the correct value was found.

Test cases end up looking like:

[Theory] // [item, item, item, MISSING NUMBER]
[InlineData(1, 2, 4, 3)]
[InlineData(1, 3, 4, 2)]
[InlineData(10, 12, 13, 11)]

This seems to provide a good balance between:

  • Data driven tests
  • The ability to put breakpoints on tests
  • Human test readability
  • Test maintainability

Other Testing Options

Other XUnit theory tests (ClassData, MemberData) were explored, but the "test noise" overwhelmed the clarity of the simpler solution.

missingnumberfinder's People

Contributors

cleemullins 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.