Git Product home page Git Product logo

Comments (3)

Claudenw avatar Claudenw commented on June 1, 2024

Thanks for the comment. I will add a few tests of this simple type.

from junit-contracts.

Claudenw avatar Claudenw commented on June 1, 2024

I expanded and documented the test cases to use them as examples of how to implement the tests. Please review the documentation link at the bottom of the initial page and the associated code to see if this covers your need. List and the various implementations become very complicated very quickly and were more test code than I cared to write since I would not be using it in any project at this time.

from junit-contracts.

jbrains avatar jbrains commented on June 1, 2024

I understand. I find abstract examples like this (A, B, C, D) difficult to understand, so my eyes glaze over when I see them. Others might find them useful.

To use List as an example doesn't require complete contract coverage. A few examples like these would give people the idea:

class EmptyListContract:
  list = createEmptyList(); // abstract
  testIsEmpty:
    assertTrue(list.isEmpty())
    assertEquals(0, list.size())

  testIteratorHasNoElements
    assertFalse(list.iterator().hasNext());
    try {
      list.iterator().next();
      fail("How did you get a next element?!");
    }
    catch (NoSuchElementException expected) {}

  testCannotGetElement:
    try {
      list.get(0);
      fail("How did you get the first element of an empty list?!");
    }
    catch (IndexOutOfBoundsException expected) {}

  testToArray:
    assertArraysEquals(new Object[0], list.toArray(new Object[0]));

That would be enough for people to get the idea, I think.

from junit-contracts.

Related Issues (11)

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.