Code Monkey home page Code Monkey logo

compareverifier's Introduction

Build Status License

CompareVerifier

CompareVerifier is a pure Java library that can be used in Junit tests to verify that classes implementing Comparable interfaces are defined correctly.

By default verification includes:

  • compareTo being consistent with equals
  • compareTo failing on a null argument
  • satisfying sgn(a.compareTo(b)) == -sgn(b.compareTo(a))
  • satisfying sgn(a.compareTo(c)) == sgn(b.compareTo(c)) => sgn(a.compareTo(b)) == 0
  • satisfying sgn(a.compareTo(b)) > 0 && sgn(b.compareTo(c)) > 0 => sgn(a.compareTo(c)) > 0

Usage

    final VerificationInstancesCreator<BigDecimal> lesserCreator =
            VerificationInstancesCreators.from(
                new BigDecimal("0.0"), // smaller then the objects returned by
                new BigDecimal("1.0"), // both equal creator and greater creator
                new BigDecimal("2.0")
            );
    final VerificationInstancesCreator<BigDecimal> equalCreator =
            VerificationInstancesCreators.from(
                new BigDecimal("42.0"),
                new BigDecimal("42.0")
            );
    final VerificationInstancesCreator<BigDecimal> greaterCreator =
            VerificationInstancesCreators.from(
                new BigDecimal("101.0"), // larger then the objects returned by
                new BigDecimal("202.0"), // both equal creator and lesser creator
                new BigDecimal("303.0")
	    );
    
    ComparableVerifier
        .<Foo>forInstances(lesserCreator, equalCreator, greaterCreator)
	.verify();    

Where:

  • lessInstancesCreator creates instance of the class implementing Comparable that are less then instances created by equalInstancesCreator
  • equalInstancesCreator creates instances that should be equal to each other, they should be greater then those created by lessInstancesCreator and less then those created by greaterInstancesCreator
  • greaterInstancesCreator creates instances that should be greater then those created by the two other creators

It's possible to disable one or more of the default verification checks by using set of "suppress" methods.

    ComparableVerifier
        .<Foo>forInstances(lesserCreator, equalCreator, greaterCreator)
        .suppressConsistentWithEquals(true)
        .suppressExceptionOnCompareToNull(true)
        .verify(); 

Download

You can use this library in conjunction with JUnit 4.12. There are two ways of getting the library:

To configure your project with JITPACK you need to in your build.gradle file at the end of repositories section add this line:

	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

Add ComparatorVerifier to the list of your test dependencies:

	dependencies {
	        testImplementation 'com.github.artificialrevelations:CompareVerifier:master-SNAPSHOT'
	}

TODO

  • detailed usage examples

compareverifier's People

Contributors

ajoz avatar alexzhukovich avatar andrzejjozwiak-tomtom avatar

Watchers

James Cloos 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.