Class BinaryOperationTest

java.lang.Object
org.checkerframework.dataflow.expression.BinaryOperationTest

public class BinaryOperationTest extends Object
Tests that BinaryOperation.equals(Object) and BinaryOperation.hashCode() stay consistent with each other (see the contract of Object.hashCode()), in particular for commutative operators, where equals considers a OP b and b OP a equal.
  • Constructor Details

    • BinaryOperationTest

      public BinaryOperationTest()
  • Method Details

    • setUp

      public void setUp()
      Builds a minimal ProcessingEnvironment (following the same approach as AnnotationBuilderTest) so that a real TypeMirror is available for the operands and result type of the BinaryOperations under test.
    • commutativeEqualsIsOrderIndependent

      public void commutativeEqualsIsOrderIndependent()
      Checks that equals considers 1 + 2 and 2 + 1 equal.
    • commutativeHashCodeIsOrderIndependent

      public void commutativeHashCodeIsOrderIndependent()
      Checks that hashCode agrees with equals: since 1 + 2 and 2 + 1 are equal, they must hash identically. This is the contract violation reported in issue #1653.
    • nonCommutativeEqualsIsOrderSensitive

      public void nonCommutativeEqualsIsOrderSensitive()
      Checks that equals distinguishes 1 - 2 from 2 - 1.
    • nonCommutativeHashCodeIsOrderSensitive

      public void nonCommutativeHashCodeIsOrderSensitive()
      Checks that hashCode remains order-sensitive for a non-commutative operator, i.e. that the fix for commutative operators did not make hashCode order-independent in general.