diff --git a/README.md b/README.md index 25547088d1c0c74d9fa1a8db68d82bfd81d6d1f3..fa2ebb90ec9f0a16b65ab0a14c8ce4edca77b12e 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,12 @@ - [License](#license) ## Description - -Morse code :: Worksheet(2 part 1)\ -This is a rep for only worksheet 2 part 1. Worksheet 2 part 2 can be found here [IOT - Worksheet 2 part 2 ](https://gitlab.uwe.ac.uk/jo2-holdsworth/iot-worksheet-2-part-2) - - +Worksheet(2 part 2) +-This worksheet explores using binary trees to encode and decode morse. +**This is a rep for only worksheet 2 part 1.** +* [IOT - Worksheet 2 part 1 ](https://gitlab.uwe.ac.uk/jo2-holdsworth/iot-worksheet-2-part-1) **you are here** +* [IOT - Worksheet 2 part 2 ](https://gitlab.uwe.ac.uk/jo2-holdsworth/iot-worksheet-2-part-2) can be found here +* [IOT - Worksheet 3](https://gitlab.uwe.ac.uk/jo2-holdsworth/iot-worksheet-3) can be found here ### Task 1: Getting to know morse code * *The CSCT cloud server has a port open on 10105 which contains a morse encoder and decoder. We are required to connect to the service and test its functionality*. * To connect to the port on the csct server we need to be able to access the port. Todo this we can port ford the port via VS Code. Using the command `Ctrl + Shift + P` we can bring up the command wind and open ports:  if we then add the port 10105  should be able to access that port on our local machine using a browser to access `localhost:10105` as we can see it has worked and we can now connect to the 10105 port on the csct cloud server:  diff --git a/assert_tests.py b/assert_tests.py index 9c50d2798ce9836a68d953792cdfd8f335a9b0bd..a7a787eaa3a42651c2720edd68853b20a2b9ca7b 100644 --- a/assert_tests.py +++ b/assert_tests.py @@ -1,4 +1,11 @@ +# ============== +# File: assert_tests.py +# By: Jack Holdsworth - 20023933 +# Use: Using the assert function to test morse.py +# Written on: Python 3.8 +# ============== import morse + def test_encode_us(): assert morse.encode('us') == '..- ...', "Should be ..- ..." diff --git a/inserter.py b/inserter.py index 7d8590dc2f8bad36537f2c8190750767dbc3d392..23d9ae2ddce92e2a7ff21a0b885adf32757b9697 100644 --- a/inserter.py +++ b/inserter.py @@ -1,6 +1,11 @@ +# ============== +# File: inserter.py +# By: Jack Holdsworth - 20023933 +# Use: A program to add new values to a binary heap string +# Written on: Python 3.8 +# ============== tree = "-ETIANMSURWDKGOHVF*L*PJBXCYZQ**54*3***2**+****16=/*****7***8*90" - def decode(string): #decoder to check correct position global tree diff --git a/main.py b/main.py index 9eea7ab3931b655a486bd914868be549c2f1b240..0d429e527ccd91f965cc9fc607532eb31b8fead9 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,20 @@ +# ============== +# File: main.py +# By: Jack Holdsworth - 20023933 +# Use: Task 2, a program to test morse +# Written on: Python 3.8 +# ============== import morse if __name__ == "__main__": + print("=== Task 2 by Jack H ===") + print(f"Encode ('Task 2 by Jack H'): {morse.encode('Task 2 by Jack H')}") + print(f"Decode ('- .- ... -.- ..--- -... -.-- .--- .- -.-. -.- ....): {morse.decode('- .- ... -.- ..--- -... -.-- .--- .- -.-. -.- ....')}") + e = morse.encode('us') print('%s' % e) d = morse.decode(e) assert morse.encode('us') == '..- ...', f"Should be: '..- ...', got {morse.decode('..- ...')}" assert morse.decode('..- ...') == 'US', f"Should be: 'us', got {morse.decode('..- ...')} " + print("========================") \ No newline at end of file diff --git a/morse.py b/morse.py index bcc2529dedb1b2d22bd97b0ca60670782bc974f2..b4b5259e99569dd1c0627ef0022410b5caaa24c9 100644 --- a/morse.py +++ b/morse.py @@ -1,3 +1,10 @@ +# ============== +# File: morse.py +# By: Jack Holdsworth - 20023933 +# Use: A binary tree, encoder and decoder +# Written on: Python 3.8 +# ============== + class node: def __init__(self, value, left=None, right=None): self.value = value # Contains itself value @@ -142,4 +149,10 @@ def encode(value): def decode(value): # the decoder tree = initTree() - return tree.words(value) \ No newline at end of file + return tree.words(value) + +if __name__ == '__main__': + print("=== Task 2 by Jack H ===") + print(f"Encode ('Task 2 by Jack H'): {encode('Task 2 by Jack H')}") + print(f"Decode ('- .- ... -.- ..--- -... -.-- .--- .- -.-. -.- ....): {decode('- .- ... -.- ..--- -... -.-- .--- .- -.-. -.- ....')}") + print("========================") \ No newline at end of file diff --git a/morseunit.py b/morseunit.py index a02124bb01c1a4d2df5f8c5b84409e3e8c220b84..074e6de6e60c3e2f20b5983bb9c637de366fc3a4 100644 --- a/morseunit.py +++ b/morseunit.py @@ -1,3 +1,10 @@ +# ============== +# File: morseunit.py +# By: Jack Holdsworth - 20023933 +# Use: Task 3, unittest on morse +# Written on: Python 3.8 +# ============== + import unittest import morse class TestMorse(unittest.TestCase): @@ -48,4 +55,5 @@ class TestMorse(unittest.TestCase): self.assertEqual( morse.decode('---...'), ':') if __name__ == '__main__': - unittest.main() \ No newline at end of file + print("=== Task 3 by Jack H ===") + unittest.main() diff --git a/runtime.py b/runtime.py index 6253b70546bed9387bfb6c83ff96754c1cb174ce..5c7147cc5195d64e5559290a818c9eb912a63fb8 100644 --- a/runtime.py +++ b/runtime.py @@ -1,3 +1,10 @@ +# ============== +# File: runtime.py +# By: Jack Holdsworth - 20023933 +# Use: A simple file to test run time. +# Written on: Python 3.8 +# ============== + import time import morse start = time.time()