Skip to content

Commit 40274c2

Browse files
authored
Update DiffieHellmanTest.java
1 parent d1a9080 commit 40274c2

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/test/java/com/thealgorithms/ciphers/DiffieHellmanTest.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,29 @@ public class DiffieHellmanTest {
1212

1313
// Test for public value calculation using instance methods
1414
@ParameterizedTest
15-
@MethodSource("providePublicKeyData")
16-
public void testCalculatePublicValue(BigInteger base, BigInteger secret, BigInteger prime, BigInteger expected) {
15+
@MethodSource("provideTestData")
16+
public void testCalculatePublicValue(BigInteger base, BigInteger secret, BigInteger prime, BigInteger publicExpected, BigInteger sharedExpected) {
1717
DiffieHellman dh = new DiffieHellman(base, secret, prime); // Create an instance of DiffieHellman
18-
assertEquals(expected, dh.calculatePublicValue()); // Call instance method
18+
assertEquals(publicExpected, dh.calculatePublicValue()); // Call instance method
1919
}
2020

2121
// Test for shared secret calculation using instance methods
2222
@ParameterizedTest
23-
@MethodSource("provideSharedSecretData")
24-
public void testCalculateSharedSecret(BigInteger base, BigInteger secret, BigInteger prime, BigInteger otherPublicValue, BigInteger expected) {
23+
@MethodSource("provideTestData")
24+
public void testCalculateSharedSecret(BigInteger base, BigInteger secret, BigInteger prime, BigInteger publicExpected, BigInteger sharedExpected) {
2525
DiffieHellman dh = new DiffieHellman(base, secret, prime); // Create an instance of DiffieHellman
26-
assertEquals(expected, dh.calculateSharedSecret(otherPublicValue)); // Call instance method
26+
assertEquals(sharedExpected, dh.calculateSharedSecret(publicExpected)); // Call instance method
2727
}
2828

29-
// Provide test data for public key calculation
30-
private static Stream<Arguments> providePublicKeyData() {
31-
return Stream.of(Arguments.of(BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(23), BigInteger.valueOf(8)), Arguments.of(BigInteger.valueOf(2), BigInteger.valueOf(5), BigInteger.valueOf(13), BigInteger.valueOf(6)));
29+
// Provide test data for both public key and shared secret calculation
30+
private static Stream<Arguments> provideTestData() {
31+
return Stream.of(
32+
createTestArgs(5, 6, 23, 8, 13), createTestArgs(2, 5, 13, 6, 2));
3233
}
3334

34-
// Provide test data for shared secret calculation
35-
private static Stream<Arguments> provideSharedSecretData() {
36-
return Stream.of(Arguments.of(BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(23), BigInteger.valueOf(8), BigInteger.valueOf(13)), Arguments.of(BigInteger.valueOf(2), BigInteger.valueOf(5), BigInteger.valueOf(13), BigInteger.valueOf(6), BigInteger.valueOf(2)));
35+
// Helper method for arguments
36+
private static Arguments createTestArgs(long base, long secret, long prime, long publicExpected, long sharedExpected) {
37+
return Arguments.of(
38+
BigInteger.valueOf(base), BigInteger.valueOf(secret), BigInteger.valueOf(prime), BigInteger.valueOf(publicExpected), BigInteger.valueOf(sharedExpected));
3739
}
3840
}

0 commit comments

Comments
 (0)