|
| 1 | +package com.thealgorithms.ciphers; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.*; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | + |
| 6 | +public class ElGamalCipherTest { |
| 7 | + |
| 8 | + @Test |
| 9 | + void testEncryptThenDecrypt_returnsOriginal() { |
| 10 | + ElGamalCipher elg = new ElGamalCipher(); |
| 11 | + |
| 12 | + String original = "HelloElGamal123"; |
| 13 | + String encrypted = elg.encrypt(original); |
| 14 | + assertNotNull(encrypted); |
| 15 | + |
| 16 | + String decrypted = elg.decrypt(encrypted); |
| 17 | + assertEquals(original, decrypted); |
| 18 | + } |
| 19 | + |
| 20 | + @Test |
| 21 | + void testEncryptedIsDifferentFromOriginal() { |
| 22 | + ElGamalCipher elg = new ElGamalCipher(); |
| 23 | + String encrypted = elg.encrypt("TestData"); |
| 24 | + assertNotEquals("TestData", encrypted); |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + void testEmptyString() { |
| 29 | + ElGamalCipher elg = new ElGamalCipher(); |
| 30 | + String encrypted = elg.encrypt(""); |
| 31 | + String decrypted = elg.decrypt(encrypted); |
| 32 | + assertEquals("", decrypted); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + void testNullInputs() { |
| 37 | + ElGamalCipher elg = new ElGamalCipher(); |
| 38 | + assertThrows(IllegalArgumentException.class, () -> elg.encrypt(null)); |
| 39 | + assertThrows(IllegalArgumentException.class, () -> elg.decrypt(null)); |
| 40 | + } |
| 41 | +} |
0 commit comments