@@ -68,10 +68,24 @@ public void testP2() {
6868 }
6969
7070 /**
71- * Test method for {@link GroupElement#p3(Curve, FieldElement, FieldElement, FieldElement, FieldElement, boolean )}.
71+ * Test method for {@link GroupElement#p3(Curve, FieldElement, FieldElement, FieldElement, FieldElement)}.
7272 */
7373 @ Test
7474 public void testP3 () {
75+ final GroupElement t = GroupElement .p3 (curve , ZERO , ONE , ONE , ZERO );
76+ assertThat (t .curve , is (equalTo (curve )));
77+ assertThat (t .repr , is (GroupElement .Representation .P3 ));
78+ assertThat (t .X , is (ZERO ));
79+ assertThat (t .Y , is (ONE ));
80+ assertThat (t .Z , is (ONE ));
81+ assertThat (t .T , is (ZERO ));
82+ }
83+
84+ /**
85+ * Test method for {@link GroupElement#p3(Curve, FieldElement, FieldElement, FieldElement, FieldElement, boolean)}.
86+ */
87+ @ Test
88+ public void testP3WithExplicitFlag () {
7589 final GroupElement t = GroupElement .p3 (curve , ZERO , ONE , ONE , ZERO , false );
7690 assertThat (t .curve , is (equalTo (curve )));
7791 assertThat (t .repr , is (GroupElement .Representation .P3 ));
@@ -124,10 +138,24 @@ public void testCached() {
124138 }
125139
126140 /**
127- * Test method for {@link GroupElement#GroupElement(Curve, GroupElement.Representation, FieldElement, FieldElement, FieldElement, FieldElement, boolean )}.
141+ * Test method for {@link GroupElement#GroupElement(Curve, GroupElement.Representation, FieldElement, FieldElement, FieldElement, FieldElement)}.
128142 */
129143 @ Test
130144 public void testGroupElementCurveRepresentationFieldElementFieldElementFieldElementFieldElement () {
145+ final GroupElement t = new GroupElement (curve , GroupElement .Representation .P3 , ZERO , ONE , ONE , ZERO );
146+ assertThat (t .curve , is (equalTo (curve )));
147+ assertThat (t .repr , is (GroupElement .Representation .P3 ));
148+ assertThat (t .X , is (ZERO ));
149+ assertThat (t .Y , is (ONE ));
150+ assertThat (t .Z , is (ONE ));
151+ assertThat (t .T , is (ZERO ));
152+ }
153+
154+ /**
155+ * Test method for {@link GroupElement#GroupElement(Curve, GroupElement.Representation, FieldElement, FieldElement, FieldElement, FieldElement, boolean)}.
156+ */
157+ @ Test
158+ public void testGroupElementCurveRepresentationFieldElementFieldElementFieldElementFieldElementWithExplicitFlag () {
131159 final GroupElement t = new GroupElement (curve , GroupElement .Representation .P3 , ZERO , ONE , ONE , ZERO , false );
132160 assertThat (t .curve , is (equalTo (curve )));
133161 assertThat (t .repr , is (GroupElement .Representation .P3 ));
@@ -157,7 +185,7 @@ public void testToAndFromByteArray() {
157185 @ Test
158186 public void testGroupElementByteArray () {
159187 final GroupElement t = new GroupElement (curve , BYTES_PKR );
160- final GroupElement s = GroupElement .p3 (curve , PKR [0 ], PKR [1 ], ONE , PKR [0 ].multiply (PKR [1 ]), false );
188+ final GroupElement s = GroupElement .p3 (curve , PKR [0 ], PKR [1 ], ONE , PKR [0 ].multiply (PKR [1 ]));
161189 assertThat (t , is (equalTo (s )));
162190 }
163191
@@ -391,6 +419,29 @@ public void toP3ReturnsExpectedResultIfGroupElementHasP3Representation() {
391419 }
392420 }
393421
422+ @ Test
423+ public void toP3PrecomputeDoubleReturnsExpectedResultIfGroupElementHasP1P1Representation () {
424+ for (int i =0 ; i <10 ; i ++) {
425+ // Arrange:
426+ final GroupElement g = MathUtils .toRepresentation (MathUtils .getRandomGroupElement (), GroupElement .Representation .P1P1 );
427+
428+ // Act:
429+ final GroupElement h1 = g .toP3PrecomputeDouble ();
430+ final GroupElement h2 = MathUtils .toRepresentation (g , GroupElement .Representation .P3PrecomputedDouble );
431+
432+ // Assert:
433+ Assert .assertThat (h1 , IsEqual .equalTo (h2 ));
434+ Assert .assertThat (h1 .getRepresentation (), IsEqual .equalTo (GroupElement .Representation .P3 ));
435+ Assert .assertThat (h1 .getX (), IsEqual .equalTo (g .getX ().multiply (g .getT ())));
436+ Assert .assertThat (h1 .getY (), IsEqual .equalTo (g .getY ().multiply (g .getZ ())));
437+ Assert .assertThat (h1 .getZ (), IsEqual .equalTo (g .getZ ().multiply (g .getT ())));
438+ Assert .assertThat (h1 .getT (), IsEqual .equalTo (g .getX ().multiply (g .getY ())));
439+ Assert .assertThat (h1 .precmp , IsNull .nullValue ());
440+ Assert .assertThat (h1 .dblPrecmp , IsNull .notNullValue ());
441+ Assert .assertThat (h1 .dblPrecmp , IsEqual .equalTo (h2 .dblPrecmp ));
442+ }
443+ }
444+
394445 @ Test (expected = IllegalArgumentException .class )
395446 public void toCachedThrowsIfGroupElementHasP2Representation () {
396447 // Arrange:
@@ -529,7 +580,7 @@ public void dblReturnsExpectedResult() {
529580
530581 @ Test
531582 public void addingNeutralGroupElementDoesNotChangeGroupElement () {
532- final GroupElement neutral = GroupElement .p3 (curve , curve .getField ().ZERO , curve .getField ().ONE , curve .getField ().ONE , curve .getField ().ZERO , false );
583+ final GroupElement neutral = GroupElement .p3 (curve , curve .getField ().ZERO , curve .getField ().ONE , curve .getField ().ONE , curve .getField ().ZERO );
533584 for (int i =0 ; i <1000 ; i ++) {
534585 // Arrange:
535586 final GroupElement g = MathUtils .getRandomGroupElement ();
0 commit comments