コード例 #1
0
  @Test
  public void hashCodesAreEqualForEquivalentObjects() {
    // Arrange:
    final GroupElement g1 = MathUtils.getRandomGroupElement();
    final GroupElement g2 = MathUtils.toRepresentation(g1, GroupElement.Representation.P2);
    final GroupElement g3 = MathUtils.toRepresentation(g1, GroupElement.Representation.P1P1);
    final GroupElement g4 = MathUtils.getRandomGroupElement();

    // Assert
    Assert.assertThat(g2.hashCode(), IsEqual.equalTo(g1.hashCode()));
    Assert.assertThat(g3.hashCode(), IsEqual.equalTo(g1.hashCode()));
    Assert.assertThat(g1.hashCode(), IsNot.not(IsEqual.equalTo(g4.hashCode())));
    Assert.assertThat(g2.hashCode(), IsNot.not(IsEqual.equalTo(g4.hashCode())));
    Assert.assertThat(g3.hashCode(), IsNot.not(IsEqual.equalTo(g4.hashCode())));
  }
コード例 #2
0
  @Test
  public void equalsOnlyReturnsTrueForEquivalentObjects() {
    // Arrange:
    final GroupElement g1 = MathUtils.getRandomGroupElement();
    final GroupElement g2 = MathUtils.toRepresentation(g1, GroupElement.Representation.P2);
    final GroupElement g3 = MathUtils.toRepresentation(g1, GroupElement.Representation.CACHED);
    final GroupElement g4 = MathUtils.toRepresentation(g1, GroupElement.Representation.P1P1);
    final GroupElement g5 = MathUtils.getRandomGroupElement();

    // Assert
    Assert.assertThat(g2, IsEqual.equalTo(g1));
    Assert.assertThat(g3, IsEqual.equalTo(g1));
    Assert.assertThat(g1, IsEqual.equalTo(g4));
    Assert.assertThat(g1, IsNot.not(IsEqual.equalTo(g5)));
    Assert.assertThat(g2, IsNot.not(IsEqual.equalTo(g5)));
    Assert.assertThat(g3, IsNot.not(IsEqual.equalTo(g5)));
    Assert.assertThat(g5, IsNot.not(IsEqual.equalTo(g4)));
  }