178 X testResult = func.apply(test, right.test);
179 X baselineResult = func.apply(baseline, right.baseline);
180 return new TestPair(testResult, baselineResult);
181 }
182
183 public
184 <U extends IntegerModuloP, V>
185 void apply(TriConsumer<T, U, V> func, TestPair<U> right, V argV) {
186 func.accept(test, right.test, argV);
187 func.accept(baseline, right.baseline, argV);
188 }
189
190 public
191 <R extends IntegerModuloP>
192 void applyAndCheckArray(BiFunction<T, R, byte[]> func,
193 TestPair<R> right) {
194 byte[] testResult = func.apply(test, right.test);
195 byte[] baselineResult = func.apply(baseline, right.baseline);
196 if (!Arrays.equals(testResult, baselineResult)) {
197 throw new RuntimeException("Array values do not match: "
198 + byteArrayToHexString(testResult) + " != "
199 + byteArrayToHexString(baselineResult));
200 }
201 }
202
203 }
204
205 static String byteArrayToHexString(byte[] arr) {
206 StringBuilder result = new StringBuilder();
207 for (int i = 0; i < arr.length; ++i) {
208 byte curVal = arr[i];
209 result.append(Character.forDigit(curVal >> 4 & 0xF, 16));
210 result.append(Character.forDigit(curVal & 0xF, 16));
211 }
212 return result.toString();
213 }
214
215 static TestPair<IntegerModuloP>
216 applyAndCheck(ElemFunction func, TestPair<MutableIntegerModuloP> left,
217 TestPair<IntegerModuloP> right) {
218
219 TestPair<IntegerModuloP> result = left.apply(func, right);
220 result.assertEqual();
221 left.assertEqual();
222 right.assertEqual();
223
224 return result;
225 }
226
227 static void
228 setAndCheck(ElemSetFunction func, TestPair<MutableIntegerModuloP> left,
229 TestPair<IntegerModuloP> right, byte[] argV) {
230
231 left.apply(func, right, argV);
232 left.assertEqual();
233 right.assertEqual();
234 }
|
178 X testResult = func.apply(test, right.test);
179 X baselineResult = func.apply(baseline, right.baseline);
180 return new TestPair(testResult, baselineResult);
181 }
182
183 public
184 <U extends IntegerModuloP, V>
185 void apply(TriConsumer<T, U, V> func, TestPair<U> right, V argV) {
186 func.accept(test, right.test, argV);
187 func.accept(baseline, right.baseline, argV);
188 }
189
190 public
191 <R extends IntegerModuloP>
192 void applyAndCheckArray(BiFunction<T, R, byte[]> func,
193 TestPair<R> right) {
194 byte[] testResult = func.apply(test, right.test);
195 byte[] baselineResult = func.apply(baseline, right.baseline);
196 if (!Arrays.equals(testResult, baselineResult)) {
197 throw new RuntimeException("Array values do not match: "
198 + Hex.encoder().encode(testResult) + " != "
199 + Hex.encoder().encode(baselineResult));
200 }
201 }
202
203 }
204
205 static TestPair<IntegerModuloP>
206 applyAndCheck(ElemFunction func, TestPair<MutableIntegerModuloP> left,
207 TestPair<IntegerModuloP> right) {
208
209 TestPair<IntegerModuloP> result = left.apply(func, right);
210 result.assertEqual();
211 left.assertEqual();
212 right.assertEqual();
213
214 return result;
215 }
216
217 static void
218 setAndCheck(ElemSetFunction func, TestPair<MutableIntegerModuloP> left,
219 TestPair<IntegerModuloP> right, byte[] argV) {
220
221 left.apply(func, right, argV);
222 left.assertEqual();
223 right.assertEqual();
224 }
|