Skip to content

Commit aec3404

Browse files
authored
Create test_quantum_communication.py
1 parent 997b608 commit aec3404

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import unittest
2+
from satellite_node_network.quantum_communication import QuantumCommunication
3+
4+
class TestQuantumCommunication(unittest.TestCase):
5+
def setUp(self):
6+
"""Set up a QuantumCommunication instance for testing."""
7+
self.quantum_comm = QuantumCommunication(node_id="Node1")
8+
9+
def test_generate_quantum_key(self):
10+
"""Test the generation of a quantum key."""
11+
key_length = 128
12+
quantum_key = self.quantum_comm.generate_quantum_key(length=key_length)
13+
self.assertEqual(len(quantum_key), key_length)
14+
self.assertTrue(all(bit in '01' for bit in quantum_key)) # Ensure the key is binary
15+
16+
def test_encode_message(self):
17+
"""Test encoding a message using a quantum key."""
18+
message = "10101010"
19+
quantum_key = "11001100"
20+
encoded_message = self.quantum_comm.encode_message(message, quantum_key)
21+
22+
# Check that the encoded message is correct
23+
expected_encoded = ''.join(str(int(m) ^ int(k)) for m, k in zip(message, quantum_key))
24+
self.assertEqual(encoded_message, expected_encoded)
25+
26+
def test_decode_message(self):
27+
"""Test decoding an encoded message using a quantum key."""
28+
message = "10101010"
29+
quantum_key = "11001100"
30+
encoded_message = self.quantum_comm.encode_message(message, quantum_key)
31+
32+
decoded_message = self.quantum_comm.decode_message(encoded_message, quantum_key)
33+
34+
# Check that the decoded message matches the original message
35+
self.assertEqual(decoded_message, message)
36+
37+
def test_secure_communication(self):
38+
"""Test secure communication between nodes."""
39+
other_node = "Node2"
40+
message = "10101010"
41+
42+
with self.assertLogs(level='INFO') as log:
43+
response = self.quantum_comm.secure_communication(other_node, message)
44+
self.assertIn(f"Node {self.quantum_comm.node_id} initiating secure communication with Node {other_node}.", log.output[0])
45+
self.assertIn(f"Encoded message sent to {other_node}: ", log.output[1]) # Check that the log contains the encoded message
46+
47+
if __name__ == "__main__":
48+
unittest.main()

0 commit comments

Comments
 (0)