This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Docs

CS 412 Reference documents

1 - Lab and Homework Guidelines

Purpose

This document presents a roadmap for software development for CS 412. If you have not already done so, read the IDE setup document to configure Python and VSCode for this class.

File Requirements

For each Python file submitted (unless stated otherwise),your code must contain a:

  • a main function that acts the same way that main would in Java
  • code at the bottom of the .py file that checks to see if this is the file that was directly invoked (i.e., \textit{python myfile.py}) and if so, it calls the main function.

An example of this is illustrated below.

"""
    name:  Your name(s) here

            Honor Code and Acknowledgments:

            This work complies with the JMU Honor Code.
            - I used this stack overflow answer as an example 
              https://stackoverflow.com/q/19798480
  
           Comments here on your code and submission
"""

# All modules for CS 412 must include a main method that allows it
# to imported and invoked from other python scripts
def main():
    # your code here
    pass

if __name__ == "__main__":
    main()

Input/Output:

Unless stated otherwise, IO will be performed via stdin and stdout. For small inputs, manual input using copy/paste into the terminal is OK. For larger inputs, use UNIX shell redirection ($<$, $>$).

For labs and programs later in the course, normal file IO may be used as well.

Testing your Program

For most assignments, a small test case will be provided to illustrate the expected input and output formats and show the basic function of the algorithm.
These test cases are NOT intended to be exhaustive or to serve as comprehensive unit tests.

Testing with supplied files

Specific input and output example files are typically provided. These files allow you to perform a basic assessment of the correctness of your code.
You can run these files using the UNIX shell’s file redirection features and then use a diff tool (Meld is a good one: see \url{https://meldmerge.org/} and it seems to be directly integrated into VS code \url{https://marketplace.visualstudio.com/items?itemName=danielroedl.meld-diff} to review any differences between the expected output and your program’s output.

python cs412_lab0_a.py < lab0_t0_in.txt > lab0_t0_out.txt
diff lab0_t0_out.txt and lab0_t0_exp.txt

Testing with UnitTest Files

Unittest is a utility similar to JUnit (which you may have used in CS159/CS240) and from time to time this type of test structure will also be provided (typically when you must augment and create your own test cases). The unittest files for this course include specific Gradescope decorators which require you to install a package into your venv using pip, which can be accomplished with the following command:

# set your current Python venv 
source $HOME/pythonlibs/cs412_venv/bin/activate 
pip install gradescope-utils 

Run the unittest file directly. An example is provided below:

python -m unittest lab0_unittest_student.py