@@ -12,27 +12,29 @@ public class DiffieHellmanTest {
12
12
13
13
// Test for public value calculation using instance methods
14
14
@ 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 ) {
17
17
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
19
19
}
20
20
21
21
// Test for shared secret calculation using instance methods
22
22
@ 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 ) {
25
25
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
27
27
}
28
28
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 ));
32
33
}
33
34
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 ));
37
39
}
38
40
}
0 commit comments