Sale!

Software Engineering 265 Assignment 2 solved

Original price was: $40.00.Current price is: $35.00. $29.75

Description

5/5 - (6 votes)

Objectives of this assignment
• Understand a problem description, along with the role used by sample input
and output for providing such a description.
• Use the Python programming language (specifically Python 3) to write a
second implementation of an file encoder to MTF, and a first implementation
of a decoder from MTF into text.
• Use Subversion Git to manage changes in your source code and annotate the
evolution of your solution with “messages” with committed changes.
• Test your code against the ten provided test cases.
Page 2 of 5
This assignment: coding.py
For this assignment you are to use the same Move-To-Front encoding scheme as
described in the first assignment but this time written in Python. The resulting code
will look very different from your solution in C and this is okay. (This is a not-sosubtle hint you should not even consider porting your C solution directly in Python.)
You must also write a decoder for a Move-To-Front (MTF) file—that is, your
solution will read through the contents of an MTF file in order to reconstruct the
actual text file represented by the encoding. The solution should check to ensure the
file given is indeed an MTF file (i.e., first four bytes correspond to the magic
numbers for our MTF format), and exit if the magic numbers are missing.
The same test cases used in Assignment #1 will be used in this assignment. There
are no extra test cases.
Both the encoder and decoder will be contained in the same Python script file. In
order to determine what functionality is to be used, we will take advantage of
Python statement obtaining to the name of the Unix command invoked for the
script. If we are in the directory currently holding coding.py, then the following two
commands (performed once):
$ ln -s coding.py text2mtf.py
$ ln -s coding.py mtf2text.py
will result two symbolic links (same as a “shortcut” in Windows or Mac) referring to
the same file. Within coding.py we will have an “if” statement to examine the name
of the command used to run the script. If the command is:
$ ./text2mtf.py tests/test02.txt
then Python will see that coding.py was used to invoke the script, and the code in
coding.py will do one thing. If the command is:
$ ./mtf2text.py tests/test03.mtf
then Python will see that mtf2text.py was used to invoke the script, and the code
in coding.py will do something different than above. (The appendix of this
document describes a skeleton script you can use to begin writing coding.py, and it
takes advantage of the use of symbolic links to coding.py.)
Page 3 of 5
Exercises for this assignment
1. Within your git repository ensure you have a subdirectory named a2. Ensure
all directories and program files you create are tracked by git. You need not
add the directory containing test files to your project unless you wish to do
so. Test files are available on the lab-machine filesystem in the directory and
are the same as those used for the first assignment.
2. Write your program. Amongst other tasks you will need to:
• obtain a filename argument from the command line;
• create a new filename based on the old file name (i.e., replace “.txt”
ending the input filename with “.mtf” ending the output filename, and vice
versa);
• read text input from a file, line by line, and the words within those lines
• read text char by char from a file
• write output to a file, char by char and word by word
• store, retrieve and locate words in a list
3. Do not use classes or regular expression in the assignment.
4. Use the test files to guide your implementation effort. Start with the simple
example in test 01 and move onto 02, 03, etc. in order. (You may want to
avoid test00 until you have significant functionality already completed.)
Refrain from writing the program all at once, and budget time to
anticipate when things go wrong! Use the Unix command cmp to compare
your MTF files and diff to compare text files.
5. For this assignment you can assume all test inputs will be well-formed (i.e.,
our teaching assistant will not test your submission for handling of input or
for arguments containing errors). Later assignments might specify errorhandling as part of their requirements.
6. Write two test scripts, i.e., Unix scripts that go through all of the ten provided
test cases (one for encoding, one for decoding) and reports which test cases
fail.
What you must submit
• A single Python script named coding.py within your subversion repository
containing a solution to Assignment #2.
• Two Unix scripts (i.e, one for testing encoding functionality, one for testing
decoding functionality).
Page 4 of 5
Evaluation
Our grading scheme is relatively simple.
• “A” grade: An exceptional submission demonstrating creativity and initiative.
The code within coding.py runs without any problems. Test scripts are
provided. The program is clearly written and is structured in a way that also
uses functions appropriate.
• “B” grade: A submission completing the requirements of the assignment. The
code within coding.py runs without any problems. Test scripts are
provided. The program is clearly written.
• “C” grade: A submission completing most of the requirements of the
assignment. The code within coding.py runs with some problems. Test
scripts might be missing.
• “D” grade: A serious attempt at completing requirements for the assignment.
The code within coding.py runs with quite a few problems. At least one or
two tests pass. Test scripts might be missing.
• “F” grade: Submission either represents very little work or cannot be
executed for testing.
Page 5 of 5
Appendix
Skeleton for coding.py
#!/usr/bin/env python3 # For use on ELW B238 machines
# -*- coding: utf-8 -*-
# See https://www.python.org/dev/peps/pep-0263/ about encoding
import os
import sys
def encode_main():
print(“In encode_main”)
def decode_main():
print(“In decode_main”)
command = os.path.basename(__file__)
if __name__ == “__main__” and command == “text2mtf.py”:
encode_main()
elif __name__ == “__main__” and command == “mtf2text.py”:
decode_main()