From 01baac0607560a26dc9f7f2350f04400afb997bf Mon Sep 17 00:00:00 2001 From: jo2-holdsworth <jack2.holdsworth@live.uwe.ac.uk> Date: Wed, 5 Apr 2023 15:33:42 +0100 Subject: [PATCH] boilerplate --- README.md | 11 ++++++----- assert_tests.py | 7 +++++++ inserter.py | 7 ++++++- main.py | 11 +++++++++++ morse.py | 15 ++++++++++++++- morseunit.py | 10 +++++++++- runtime.py | 7 +++++++ 7 files changed, 60 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 2554708..fa2ebb9 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 9c50d27..a7a787e 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 7d8590d..23d9ae2 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 9eea7ab..0d429e5 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 bcc2529..b4b5259 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 a02124b..074e6de 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 6253b70..5c7147c 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() -- GitLab