@Test public void squareAndDoubleReturnsCorrectResult() { for (int i=0; i<1000; i++) { // Arrange: final FieldElement f1 = getRandomFieldElement(); final BigInteger b1 = toBigInteger(f1); // Act: final FieldElement f2 = f1.squareAndDouble(); final BigInteger b2 = toBigInteger(f2).mod(getQ()); // Assert: Assert.assertThat(b2, IsEqual.equalTo(b1.multiply(b1).multiply(new BigInteger("2")).mod(getQ()))); } }
@Test public void subtractReturnsCorrectResult() { for (int i=0; i<1000; i++) { // Arrange: final FieldElement f1 = getRandomFieldElement(); final FieldElement f2 = getRandomFieldElement(); final BigInteger b1 = toBigInteger(f1); final BigInteger b2 = toBigInteger(f2); // Act: final FieldElement f3 = f1.subtract(f2); final BigInteger b3 = toBigInteger(f3).mod(getQ()); // Assert: Assert.assertThat(b3, IsEqual.equalTo(b1.subtract(b2).mod(getQ()))); } }
@Test public void addReturnsCorrectResult() { for (int i=0; i<1000; i++) { // Arrange: final FieldElement f1 = getRandomFieldElement(); final FieldElement f2 = getRandomFieldElement(); final BigInteger b1 = toBigInteger(f1); final BigInteger b2 = toBigInteger(f2); // Act: final FieldElement f3 = f1.add(f2); final BigInteger b3 = toBigInteger(f3).mod(getQ()); // Assert: Assert.assertThat(b3, IsEqual.equalTo(b1.add(b2).mod(getQ()))); } }
@Test public void negateReturnsCorrectResult() { for (int i=0; i<1000; i++) { // Arrange: final FieldElement f1 = getRandomFieldElement(); final BigInteger b1 = toBigInteger(f1); // Act: final FieldElement f2 = f1.negate(); final BigInteger b2 = toBigInteger(f2).mod(getQ()); // Assert: Assert.assertThat(b2, IsEqual.equalTo(b1.negate().mod(getQ()))); } }
@Test public void multiplyReturnsCorrectResult() { for (int i=0; i<1000; i++) { // Arrange: final FieldElement f1 = getRandomFieldElement(); final FieldElement f2 = getRandomFieldElement(); final BigInteger b1 = toBigInteger(f1); final BigInteger b2 = toBigInteger(f2); // Act: final FieldElement f3 = f1.multiply(f2); final BigInteger b3 = toBigInteger(f3).mod(getQ()); // Assert: Assert.assertThat(b3, IsEqual.equalTo(b1.multiply(b2).mod(getQ()))); } }
@Test public void squareReturnsCorrectResult() { for (int i=0; i<1000; i++) { // Arrange: final FieldElement f1 = getRandomFieldElement(); final BigInteger b1 = toBigInteger(f1); // Act: final FieldElement f2 = f1.square(); final BigInteger b2 = toBigInteger(f2).mod(getQ()); // Assert: Assert.assertThat(b2, IsEqual.equalTo(b1.multiply(b1).mod(getQ()))); } }
@Test public void pow22523ReturnsCorrectResult() { for (int i=0; i<1000; i++) { // Arrange: final FieldElement f1 = getRandomFieldElement(); final BigInteger b1 = toBigInteger(f1); // Act: final FieldElement f2 = f1.pow22523(); final BigInteger b2 = toBigInteger(f2).mod(getQ()); // Assert: Assert.assertThat(b2, IsEqual.equalTo(b1.modPow(BigInteger.ONE.shiftLeft(252).subtract(new BigInteger("3")), getQ()))); } }
@Test public void invertReturnsCorrectResult() { for (int i=0; i<1000; i++) { // Arrange: final FieldElement f1 = getRandomFieldElement(); final BigInteger b1 = toBigInteger(f1); // Act: final FieldElement f2 = f1.invert(); final BigInteger b2 = toBigInteger(f2).mod(getQ()); // Assert: Assert.assertThat(b2, IsEqual.equalTo(b1.modInverse(getQ()))); } }