Starting from:

$25

COMP2160 - Assignment 3 - Programming practices - Solved

Objectives
Question 1: Container
Question 2: Black-box testing
Submitting your assignment
Evaluation
Description
In assignment 3 we’re going to apply what we’ve learned about interfaces, testing, and multi-file compilation.

Notes
Read the entire assignment document before starting.
Your programs must run correctly both with assertions enabled and disabled (when compiled with and without the -DNDEBUG option).
Please be sure to follow the programming standards; not doing so will result in a loss of marks.
Remember to complete the Honesty Declaration Checklist (you will not receive scores for your assignments until the checklist is completed).
All submitted assignments will be scanned with automated software to monitor for academic integrity violations.
Your assignment code must be handed in electronically. See the Submitting your assignment section below for more information.
Late assignments are not accepted. The due date is enforced electronically.
Objectives
Designing interfaces and building implementations.
Multi-file compilation.
Testing.
Question 1: Container
For question 1, you’re going to write an interface for an abstract data type (a “Container”), and you’re going to provide an implementation of that ADT with a linked list.

The interface
First, you should build an interface for the container ADT. Your container will store strings (as char*).

We’ll give you the names of the functions below, but you must write complete prototypes for your interface. Choosing the return types and parameter types is your responsibility.

Your interface should contain the minimal amount of information required for someone to use your implementation in their code.

Functions
Your interface should be implemented as container.h with the following function names:

Creating and destroying:
createContainer (Create a new instance of the container)
destroyContainer (Destroy the container and its contents)
Manipulation:
insert (Insert an item into the container)
delete (Remove the specified item from the container, only one if there are multiple)
clear (Remove all items from the container)
Iterating and searching:
firstItem (Start iterating over items in the container)
nextItem (Continue iterating over items in the container)
contains (Does the container contain this item?)
size (how many items are in the container?)
The implementation
Once you’ve got an interface, create an implementation for the container by implementing a linked list of strings. Your implementation should define the data structure, and implement all of the functions declared as prototypes in the interface.

Your linked list implementation must apply the principles of design by contract. In particular, you should be implementing a function invariant on the linked list.

Your implementation should be implemented as container.c.

The tests
Finally, you should build an automated test suite for your container implementation.

Your test suite should be implemented in a file called main.c, and you should be sure to test all functions in the file with both general case and edge case test data.

Tests should be organized appropriately into their own functions.

Your test suite should report:

Progress: a statement about what the test is testing (i.e., “searching for X”)
Success: a statement about whether or not the test succeeded (i.e., “FAILED: expected to find X, but could not find it.” or “SUCCESS: expected to find X and found it.”)
Summary: a summary of the number of tests run, the number of tests passed, and the number of tests failed.
You should refer back to the Levenshtein implementation in Assignment 1 to get an idea of what a testing suite that matches this description looks like.

Building
Your solution for question 1 must include a Makefile. The grader should only have to type the command make in your directory to build your assignment.

Question 2: Black-box testing
You have been provided with an implementation of a set ADT developed by a third-party. The implementation consists of a header file set.h that defines the interface and a compiled object file with the implementation.

Your job is to verify that the third-party developer is not a terrible programmer (hint: they aren’t terrible, they’re really terrible).

You should implement a complete test suite for the set ADT and provide a report (in a Markdown-formatted README file) explaining what is broken with the implementation of the set that this really, really terrible programmer has given to you.

You should use the testing suite you built in question 1 as a basis for the testing suite you build here.

The first set
You have been provided with one implementation of the set by a competent programmer. The implementation is in a file called set.o that has been compiled on aviary (Linux). The first implementation that you’re being provided with is 100% correct – none of the functions in this file are implemented incorrectly, there are no bugs in this implementation.

The tests
Your job is to write a complete test suite for the implementation of a set.

Your test suite should be implemented in a file called main.c, and you should be sure to test all functions in the file with both general case and edge case test data. Also note that there’s a function called validateMemUse() that can be used to verify that all instances of Set that were created have been destroyed – your test suite should use this function to check for memory leaks.

Tests should be organized appropriately into their own functions.

Your test suite should report:

Progress: a statement about what the test is testing (i.e., “searching for X”)
Success: a statement about whether or not the test succeeded (i.e., “FAILED: expected to find X, but could not find it.” or “SUCCESS: expected to find X and found it.”)
Summary: a summary of the number of tests run, the number of tests passed, and the number of tests failed.
For the set implementation that’s provided above, all of the tests you write will pass.

The other sets
Closer to the due date, we will provide you with 5 more implementations of a set that implement the same interface. You will use the test suite that you wrote for the correct implementation of a set to determine what (if anything) is wrong with each of the set implementations that you’re provided with.

You must write a brief analysis for each file in a file called README.md. README.md should be a Markdown-formatted file (use headings!).

While the code we will provide to you is buggy, it will not crash. If you receive any error messages (segmentation fault, abort, bus error), the crash is happening in your code. When this happens, your strategy should be to re-read the comments in the set interface to better understand what each function does/requires. If you still can’t figure out why your tests are crashing, you should pull out your debugger and debug your code.


Warnings
The code you write should compile with clang
-Wall without any warnings. A 1 point penalty will be applied to your score (before multiplication) for each warning that is emitted by the compiler.

Question 1
  Level
Criteria
0
·    No submission for Q1 is made, or

·    The submitted code does not compile on aviary.cs.umanitoba.ca with the expected compilation commands.

make
1
·    Code is submitted for the problem, and the code compiles.

·    The compiled code crashes, does not run, or does not complete in a reasonable amount of time (< 5 seconds).

·    The C code is of high quality, following the standards described in the programming standards document.
2
·    The criteria for 1 is met.

·    The interface (.h file) is complete.

·    The interface contains the minimal amount of information needed to use the implementation.
3
·    The criteria for 2 is met.

·    The creation and destruction functions are defined in the implementation.

·    DbC principles are applied to the creation and destruction function implementations.

·    Tests have been written that adequately test the creation and destruction functions.
4
·    The criteria for 3 is met.

·    The manipulation functions are defined in the implementation.

·    DbC principles are applied to the manipulation functions.

·    Tests have been written that adequately test the manipulation functions.
5
·    The criteria for 4 is met.

·    The iterating and searching functions are defined in the implementation.

·    DbC principles have been applied to the iterating and searching function implementations.

·    Tests have been written that adequately test the iterating and searching functions.
Question 2
Test suite
  Level
Criteria
0

More products