Question: C programming Parking Manager. Write a unit test for allocVehicle() Remember: Make use of the assert() function when writing unit tests. It accepts a single

C programming Parking Manager.

Write a unit test for allocVehicle()

Remember:

Make use of the assert() function when writing unit tests. It accepts a single Boolean expression as an argument and will halt execution of the program if the expression evaluates to false. If the expres- sion evaluates to true, program execution continues as normal. assert() is best used for testing purposes and should be used sparingly in production code. You must import the C library assert.h to use assertions.

******************************************************************************************************************

/* Vehicle parking program */

//Parking Manager//

#include

#include

#include

#define CAR 1

#define TRUCK 2

#define SUV 3

/* to store vehicle number, and its

row-col position in an array */

struct vehicle

{

int num ;

int row ;

int col ;

int type ;

} ;

int parkinfo[6][10] ; //number of vehicle parked

int vehcount ; // total vehicle parked

int carcount ; // total cars

int truckcount ; /* total trucks */

int suvcount ; /* total suv*/

void display( ) ;

void changecol ( struct vehicle * ) ; // no need

struct vehicle * allocVehicle( int, int, int, int ) ;

void deallocVehicle ( struct vehicle * ) ; //int deallocVehicle(vehicle* v);

void getfreerowcol ( int, int * ) ;

void getrcbyinfo ( int, int, int * ) ;

void show( ) ;

/* decrements the col. number by one

this fun. is called when the data is

shifted one place to left */

void changecol ( struct vehicle *v )

{

v -> col = v -> col - 1 ;

}

/* adds a data of vehicle */

struct vehicle* allocVehicle ( int t, int num, int row, int col )

{

struct vehicle *v ;

v = ( struct vehicle * ) malloc ( sizeof ( struct vehicle ) ) ;

v -> type = t ;

v -> row = row ;

v -> col = col ;

if ( t == CAR )

carcount++ ;

else if(t == TRUCK)

truckcount++ ;

else

suvcount++ ;

vehcount++ ;

parkinfo[row][col] = num ;

return v ;

}

/* deletes the data of the specified

car from the array, if found */

void deallocVehicle( struct vehicle *v )

{

int c ;

for ( c = v -> col ; c < 9 ; c++ )

parkinfo[v -> row][c] = parkinfo[v -> row][c+1] ;

parkinfo[v -> row][c] = 0 ;

if ( v -> type == CAR )

carcount-- ;

else if ( v -> type == TRUCK)

truckcount-- ;

else

suvcount-- ;

vehcount-- ;

}

/* get the row-col position for the vehicle to be parked */

void getfreerowcol ( int type, int *arr )

{

int r, c, fromrow = 0, torow = 2 ;

if ( type == TRUCK )

{

fromrow += 2 ;

torow += 2 ;

}

if(type == SUV)

{

fromrow += 4 ;

torow += 4 ;

}

for ( r = fromrow ; r < torow ; r++ )

{

for ( c = 0 ; c < 10 ; c++ )

{

if ( parkinfo[r][c] == 0 )

{

arr[0] = r ;

arr[1] = c ;

return ;

}

}

}

if ( r == 2 || r == 4 )

{

arr[0] = -1 ;

arr[1] = -1 ;

}

}

/* get the row-col position for the vehicle with specified number */

void getrcbyinfo ( int type, int num, int *arr )

{

int r, c, fromrow = 0, torow = 2 ;

if ( type == TRUCK )

{

fromrow += 2 ;

torow += 2 ;

}

if(type == SUV)

{

fromrow += 4 ;

torow += 4 ;

}

for ( r = fromrow ; r < torow ; r++ )

{

for ( c = 0 ; c < 10 ; c++ )

{

if ( parkinfo[r][c] == num )

{

arr[0] = r ;

arr[1] = c ;

return ;

}

}

}

if ( r == 2 || r == 4 )

{

arr[0] = -1 ;

arr[1] = -1 ;

}

}

/* displays list of vehicles parked */

void display( )

{

int r, c ;

printf ( "\xdb\xdb Cars => " ) ;

for ( r = 0 ; r < 5 ; r++ )

{

if ( r == 2 )

printf ( "\xdb\xdbTrucks => " ) ;

if ( r == 4)

printf( "\xdb\xdbSUVs => ");

for ( c = 0 ; c < 10 ; c++ )

printf ( "%d\t", parkinfo[r][c] ) ;

printf ( " " ) ;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!