FieldElementFp extends FieldElement implements Serializable { @Override public FieldElement add(FieldElement f) { BigInteger tmp = this.getData().add(f.getData()); tmp = tmp.mod(this.getModulus()); return new FieldElementFp(tmp, this.getModulus()); } FieldElementFp(BigInteger data, BigInteger modulus); private  FieldElementFp(); @Override FieldElement add(FieldElement f); @Override FieldElement mult(FieldElement f); @Override FieldElement addInv(); @Override FieldElement multInv();  }
@Test public void testAdd() { FieldElementFp tmp = (FieldElementFp) e1.add(e2); FieldElementFp result = new FieldElementFp(new BigInteger("81"), modulus); assertEquals(result, tmp); tmp = (FieldElementFp) e1.add(e3); result = new FieldElementFp(new BigInteger("25"), modulus); assertEquals(result, tmp); result = new FieldElementFp(new BigInteger("138"), modulus); assertEquals(result, tmp); }
@Test public void testEquals() { assertNotEquals(e1, e2); assertEquals(e1, e1); BigInteger e1Data = e1.getData(); FieldElementFp e1_ = new FieldElementFp(e1Data, modulus); assertEquals(e1, e1_); e1_ = new FieldElementFp(e1Data, modulus.add(BigInteger.ONE)); assertNotEquals(e1, e1_); e1_ = new FieldElementFp(e1Data.add(BigInteger.ONE), modulus); assertNotEquals(e1, e1_); e1_ = new FieldElementFp(e1Data.add(BigInteger.ONE), modulus.add(BigInteger.ONE)); assertNotEquals(e1, e1_); }