Skip to content
Snippets Groups Projects
Commit 01baac06 authored by jo2-holdsworth's avatar jo2-holdsworth
Browse files

boilerplate

parent 60a2a880
No related branches found
No related tags found
No related merge requests found
......@@ -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: ![image](src/screenshot1.PNG) if we then add the port 10105 ![image](src/screenshot2.PNG) 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: ![image](src/screenshot3.PNG)
......
# ==============
# 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 ..- ..."
......
# ==============
# 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
......
# ==============
# 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
# ==============
# 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
......@@ -143,3 +150,9 @@ def decode(value):
# the decoder
tree = initTree()
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
# ==============
# 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__':
print("=== Task 3 by Jack H ===")
unittest.main()
# ==============
# 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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment