-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_Morse_code.py
More file actions
69 lines (55 loc) · 3.51 KB
/
Test_Morse_code.py
File metadata and controls
69 lines (55 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import unittest
from Morse_code import encrypt, decrypt
import unittest
class TestMorseCode(unittest.TestCase):
def test_encrypt(self):
"""
Test the encrypt function with various inputs.
Standard inputs:
- Test with "HELLO", "WORLD", "SOS", and "123".
Edge cases and special characters:
- Test with empty input, multiple words, special characters not in the Morse code dictionary, and alphanumeric characters.
Additional test cases:
- Test with multiple words, all letters, all letters contd., and mix of uppercase, lowercase, and spaces.
"""
# Standard inputs
self.assertEqual(encrypt("HELLO"), '.... . .-.. .-.. ---')
self.assertEqual(encrypt("WORLD"), '.-- --- .-. .-.. -..')
self.assertEqual(encrypt("SOS"), '... --- ...')
self.assertEqual(encrypt("123"), '.---- ..--- ...--')
# Edge cases and special characters
self.assertEqual(encrypt(""), "") # Empty input
self.assertEqual(encrypt("TEST TEST"), '- . ... -/- . ... -') # Multiple words
self.assertEqual(encrypt("@#$"), "") # Special characters not in the Morse code dictionary
self.assertEqual(encrypt("TEST123"), '- . ... - .---- ..--- ...--') # Alphanumeric characters
# Additional test cases
self.assertEqual(encrypt("HELLO WORLD"), '.... . .-.. .-.. ---/.-- --- .-. .-.. -..') # Multiple words
self.assertEqual(encrypt("A B C D E F G H I J K L M"), '.-/-.../-.-./-.././..-./--./..../../.---/-.-/.-../--') # All letters
self.assertEqual(encrypt("N O P Q R S T U V W X Y Z"), '-./---/.--./--.-/.-./.../-/..-/...-/.--/-..-/-.--/--..') # All letters contd.
self.assertEqual(encrypt("TESTING Morse Code"), '- . ... - .. -. --./-- --- .-. ... ./-.-. --- -.. .') # Mix of uppercase, lowercase, and spaces
def test_decrypt(self):
"""
Test the decrypt function with various inputs.
Standard inputs:
- Test with ".... . .-.. .-.. ---", ".-- --- .-. .-.. -..", "... --- ...", and ".---- ..--- ...--".
Edge cases and special characters:
- Test with empty input, multiple words, and alphanumeric characters.
Additional test cases:
- Test with multiple words, all letters, all letters contd., and mix of uppercase, lowercase, and spaces.
"""
# Standard inputs
self.assertEqual(decrypt('.... . .-.. .-.. ---'), "HELLO")
self.assertEqual(decrypt('.-- --- .-. .-.. -..'), "WORLD")
self.assertEqual(decrypt('... --- ...'), "SOS")
self.assertEqual(decrypt('.---- ..--- ...--'), "123")
# Edge cases and special characters
self.assertEqual(decrypt(''), "") # Empty input
self.assertEqual(decrypt('- . ... - / - . ... -'), "TEST TEST") # Multiple words
self.assertEqual(decrypt('.---- ..--- ...--'), "123") # Alphanumeric characters
# Additional test cases
self.assertEqual(decrypt('.... . .-.. .-.. --- / .-- --- .-. .-.. -..'), "HELLO WORLD") # Multiple words
self.assertEqual(decrypt('.-/-.../-.-./-.././..-./--./..../../.---/-.-/.-../--'), "A B C D E F G H I J K L M") # All letters
self.assertEqual(decrypt('-./---/.--./--.-/.-./.../-/..-/...-/.--/-..-/-.--/--..'), "N O P Q R S T U V W X Y Z") # All letters contd.
self.assertEqual(decrypt('- . ... - .. -. --./-- --- .-. ... ./-.-. --- -.. .'), "TESTING MORSE CODE") # Mix of uppercase, lowercase, and spaces
if __name__ == "__main__":
unittest.main()