Sei sulla pagina 1di 3

ECSE607 SOFTWARE QUALITY: COURSEWORK 1 Due: 1st February 2012 Due: 5th March 2012 Topic: testing Value:

25% of overall module mark Submission: + Send an emailed .pdf copy before midnight of deadline. + Hand-in a stapled A4 (no covers) paper copy via the School Registry Coursework Box asap afterwards. QUESTION 1 Provide test plans, test data, expected results and actual results (if appropriate) for the following: 1a) The Unix 'cmp' program (use the Unix man facility for details) You can ignore the [skip] options. [25 marks] 1b) cw1Code [20 marks]

This program is held as a Solaris executable on this intranet page, and can also be found on Solaris on the URL: /ecs/www/intranet/staff/colin/ECSE607/Coursework/cw1Code Here is a summary of the program: // Gives the average of upto 10 numbers from an input file // each line contains one number only Notes: + This program is still under development and may not behave as intended. + The code is an executable object file and so will appear as gibberish on your browser. It will not run on your own laptop + To test the code; copy it to your UoW Solaris area, check that the permissions are correct (use chmod, if necessary) and run it from the prompt line: ./cw1Code

QUESTION 2 Provide a UNIX-style manual entry for cw1Code

[10 marks]

QUESTION 3

[20 marks]

Briefly outline the Test Driven Development (TDD) approach to software development. Discuss one example where you might use TDD and one example where it is not appropriate. You must clearly acknowledge your sources.

QUESTION 4

[25 marks]

Comment on the code quality of the following program to compare two versions of bubble sort. Your discussion should cover Coding Standards and other quality style criteria such as cohesion, coupling and complexity. Indicate clearly the lines of code to which you are referring. Note: the code is syntactically correct and meets its specification. Do not blackbox test or rewrite it. However, where appropriate, suggest quality improvements.

// Bubble Sort Test program: written by Colin Myers #include <iostream> // iostream library linkage using namespace std; // using correct namespace const int MAX = 80; int bsort(char [], int); int fsort(char [], int); char line1[80]; char line2[80]; // constant // function prototype // function prototype // line storage

int main() { cout << "Enter line to sort: "; cin >> line1; strcpy (line2, line1); int L = strlen(line1); // length if (L < 2) cout << "already sorted\n"; else { bsort(line1, L); fsort(line2, L); } } int bsort(char line[], int SIZE) { // vanilla version if (SIZE < 2) { cout << "already sorted\n"; return SIZE; } int k = 1; // comparison count for (int icounter=SIZE-1;icounter>0;icounter--) { k++; // add 1 to k for (int j=0;j<icounter;j++) { k++; if (line[j]>line[j+1]) { // swap char temp = line[j]; line[j] = line[j+1]; line[j+1] = temp; } } } cout << "vanilla version: " << k << "\n"; return k; } int fsort(char line[], int SIZE)

{// optimized version with flag if (SIZE < 2) { cout << "already sorted\n"; return SIZE; } int k = 1; // comparison count for (int i=SIZE-1;i>0;i--) { k++; /* increment k */ bool nomoreSwaps = true; // assume this line sorted for (int j = 0; j < i; j++) { k++; if (line[j] > line[j+1]) { // swap char temp = line[j]; line[j] = line[j+1]; line[j+1] = temp; nomoreSwaps = false; // this line wasnt sorted } } k++; /* increment k */ if (nomoreSwaps) { cout << "optimized version, quick exit: " << k << "\n"; return k; } } cout << "optimized version, no benefits: " << k << endl; return k; }

Potrebbero piacerti anche