[SOLVED] COMPSCI_2ME3 - Assignment 1

30.00 $

Category:

Description

5/5 - (1 vote)

 Introduction

The purpose of Part 1 of this software design exercise is to write Python modules that matches the natural language specification provided. In Part 2 you will critique the design, based partially on your experience working with a portion of one of your classmate’s implementations. Part 2 will also include answering questions related to the course con-

tent.

All of your code, except for your test driver (Step 3), should be documented using doxygen. All of your reports should be written using LATEX. Your code should follow the given specification. In particular, you should not add public methods that are not specified and you should not change the number or order of parameters for methods or change the types of the returned values.

Please remember to commit to GitLab frequently. A portion of your grade will be based on you demonstrating a reasonable commit history. Frequent small commits are a good habit to form, and this practice might save you if something goes wrong with your local machine. As mentioned at the end of the assignment, you will build additional confidence in your implementation if you test it on mills.

Part 1

In this part of the assignment you will implement two modules in Python, each in a separate file. You will also write a Python file for your test driver.

Step 1

Write a module in Python that implements an Abstract Data Type (ADT) for complex numbers (ComplexT). The code should be in a file named complex adt.py. The module will define several methods (access programs) as defined below. To find the necessary mathematics, please refer to the Wikipedia page on complex numbers.

  • A constructor (ComplexT) that takes two floats x and y as input and creates a ComplexT x is the real part of the complex number and y is the imaginary part. See the Notes at the end of the assignment specification about implementing constructors in Python.
  • A getter named real that returns the real part (x) of the complex number z = x+yi.
  • A getter named imag that returns the imaginary part (y) of the complex number z = x + yi.
  • A getter named get r that returns the absolute value (or modulus or magnitude) of the complex number z = x + yi.
  • A getter named get phi that returns the argument (or phase) of the complex number z = x + yi. The phase should be returned in radians. See the Notes at the end of the assignment specification about assumptions and exceptions.
  • A method named equal that takes an argument of ComplexT and returns a Boolean. The result is True if the argument and the current object are equal and False otherwise. See the Notes at the end of the assignment specification for details on the optional step of including a “magic” method for equality.
  • A method named conj that takes no argument and returns a ComplexT. The result is the complex conjugate of the current object.
  • A method named add that takes an argument of ComplexT and returns a ComplexT object that adds the argument to the current object.
  • A method named sub that takes an argument of ComplexT and returns a ComplexT object that subtracts the argument from the current object.
  • A method named mult that takes an argument of ComplexT and returns a ComplexT object that multiplies the argument and the current object.
  • A method named recip that takes no argument and returns a ComplexT. The result is the reciprocal of the current object.
  • A method named div that takes an argument of ComplexT and returns a ComplexT object that divides the current object by the argument.
  • A method named sqrt that takes no argument and returns a ComplexT. The result is the positive square root of the current object.

Step 2

Write a second Python module, named triangle adt.py, that implements an ADT for triangles (TriangleT). The module will define several methods (access programs) as defined below:

  • A constructor (TriangleT) that takes three arguments, each of type integer, and constructs an object of type TriangleT. The arguments are the lengths of the sides of the triangle.
  • A getter named get sides that return a tuple of three integers, where each integer is the length of one side of the triangle.
  • A method named equal that takes one argument of type TriangleT and returns

True if the current TriangleT is equal to the argument. Otherwise False is returned.

  • A method named perim that takes no arguments and returns an integer representing the perimeter of the current TriangleT.
  • A method named area that takes no arguments and returns a float representing the area of the current TriangleT.
  • A method named is valid that takes no arguments and returns a Boolean. The returned value is True if the three sides in the current TriangleT form a valid triangle. Otherwise False is returned.
  • A method named tri type that takes no arguments and returns a TriType. TriType is an element of the set {equilat, isosceles, scalene, right}. The elements of TriType correspond to the triangle types equilateral, isosceles, scalene and right angle. The class TriType should be defined in the triangle adt.py Details on how to define an enumerated type are given in the Notes section at the end of the assignment specification.

Step 3

Write a third module that tests the first and second modules. It should be a Python file named test driver.py. Your initial git repo contains a Makefile (provided for you) with a rule test that runs your test driver source with the Python interpreter. Each function should be tested as completely as you are able. A specific number of tests is not prescribed, nor is an approach for devising test cases. At this point you should use your intuition and best judgement of the tests that will build confidence in the correctness of your implementation. (Throughout the course we will return the question of testing and potentially be adding to and refining your intuition.) Please note for yourself the rationale for test case selection and the results of testing. You will need this information when writing your report in Step 7. The requirements for testing are deliberately vague; at this time, we are most interested in your ideas and intuition for how to build and execute your test suite.

Your test driver should be as automated. A test case consists of an expected answer and a calculated answer. You should write code to compare your calculated results to the expected results. A test case passes when they match. Otherwise the test fails. Please avoid manual tests where the output is simply printed to the screen, with the expectation that a human user will check it. A manual approach like this is simply not maintainable over time. To get you started, some sample tests are given in test expt, along with a make rule (make expt) for running the sample tests.

You are not required to use a unit testing framework, but you are welcome to use pytest.

Step 4

Test the supplied Makefile rule for doc. This rule should compile your documentation into an html and LATEX version. Your documentation should be generated to the A1 folder. Along with the supplied Makefile, a doxygen configuration file (docConfig) is also given in your initial repo.