Home Libraries Author Links

Dset Test
[Dset: Associative Set and Map Containers]

Collaboration diagram for Dset Test:

Detailed Description

Demonstration of the usage and tests of the implementation of the abstract set, multiset, map and multimap types modelling associative containers for objects of configurable element types.


Files

file  dsettst.c
 Implementation of a console program demonstrating the usage and testing the implementation of abstract set, multiset, map and multimap types modelling associative containers for objects of configurable element types.

Modules

 Abstract Set Type Example
 intStmSet is an example of an abstract set type with int elements and the element comparison function elemCmp().
 Abstract Multiset Type Example
 intStmMultiSet is an example of an abstract multiset type with int elements and the element comparison function elemCmp().
 Abstract Map Type Example
 NrStmMap is an example of an abstract map type with int both as key type and as mapped type and the key comparison function keyCmp().
 Abstract Multmiap Type Example
 MultiNrStmMultiMap is an example of an abstract multimap type with int both as key type and as mapped type and the key comparison function keyCmp().

Defines

#define dsetAssert(cond)
 Terminate the program if a condition is violated.

Functions

static void dsetPrintf (const char *format,...)
 Print formatted on stdout and/or an an additional stream.
static void dsetShowf (const char *format,...)
 Print formatted on stdout and reset the cursor.
static int randomInt (int minval, int maxval)
 Random number generation.
int main (int argc, char **argv)
 Main function implementing the command dsettst.
static int elemCmp (const int *pEl1, const int *pEl2)
 Element comparison function for the abstract container types intStmSet and intStmMultiSet.
static int keyCmp (int key1, int key2)
 Key comparison function for the abstract container types NrStmMap and MultiNrStmMultiMap.

Variables

static const char * man []
 Man page.
static StmBool silent = StmFalse
 Silent flag.
static FILE * os = NULL
 Output file stream.


Define Documentation

#define dsetAssert ( cond   ) 

Value:

if (! (cond))                                                                  \
{                                                                              \
    if (!silent) printf ("line %d: '" #cond "' failed\n", __LINE__);           \
    exit (__LINE__);                                                           \
}                                                                              \
Terminate the program if a condition is violated.

Parameters:
[in] cond The boolean condition to verify.
Effects:
If cond is satisfied, the macro does nothing. Else, if the silent flag is StmFalse, a diagnostic message indicating the line number of the error and cond is printed on stdout. Finally the program is aborted with that line number as exit code.
Examples:
dsettst.c.

Definition at line 158 of file dsettst.c.

Referenced by randomInt().


Function Documentation

static void dsetPrintf ( const char *  format,
  ... 
) [static]

Print formatted on stdout and/or an an additional stream.

Parameters:
[in] format Format string as in printf.
Effects:
The function formats its arguments according to format and the other arguments as the standard function printf does and prints that formatted output to stdout unless the silent flag is StmTrue and to the additional stream os unless it is NULL.
Examples:
dsettst.c.

Definition at line 714 of file dsettst.c.

static void dsetShowf ( const char *  format,
  ... 
) [static]

Print formatted on stdout and reset the cursor.

Parameters:
[in] format Format string as in printf.
Effects:
Unless the silent flag is StmTrue, the function formats its arguments according to format and the other arguments as the standard function printf does, prints that formatted output to stdout and resets the cursor to its initial position.
Examples:
dsettst.c.

Definition at line 726 of file dsettst.c.

static int randomInt ( int  minval,
int  maxval 
) [static]

Random number generation.

Parameters:
[in] minval Minimal result value.
[in] maxval Maximal result value.
Requires:
           minval <= maxval
Returns:
A pseudo-random number n in the range
                     minval <= n <= maxval
Examples:
dsettst.c.

Definition at line 742 of file dsettst.c.

int main ( int  argc,
char **  argv 
)

Main function implementing the command dsettst.

Parameters:
[in] argc Argument count.
[in] argv Pointer to an array of argc argument strings followed by an additional NULL array element.
Returns:
0, if no error occurred.

1, if the command was used erroneously.

2, if one of the command line options --help or --versionn has been used.

On error the number of the program file line where the command failed.

Main function implementing the command dsettst.

Main function implementing the command cuglify.

Parameters:
[in] argc Argument count.
[in] argv Pointer to an array of argc argument strings followed by an additional NULL array element (only used internally).
Returns:
0, if no error occurred.

1, if an error occurred.

Definition at line 87 of file namedconditiontest.c.

static int elemCmp ( const int *  pEl1,
const int *  pEl2 
) [static]

Element comparison function for the abstract container types intStmSet and intStmMultiSet.

Parameters:
[in] pEl1 Pointer to the left int object to be compared.
[in] pEl2 Pointer to the right int object to be compared.
Requires:
Both pEl1 and pEl2 must not be NULL.
Returns:
-1, if the left int object is less than the right one.

0, if the left int object is equal to the right one.

1, if the left int object is greater than the right one.

Examples:
dsettst.c.

Definition at line 702 of file dsettst.c.

static int keyCmp ( int  key1,
int  key2 
) [static]

Key comparison function for the abstract container types NrStmMap and MultiNrStmMultiMap.

Parameters:
[in] key1 Left int object to be compared.
[in] key2 Right int object to be compared.
Returns:
-1, if the left int object is less than the right one.

0, if the left int object is equal to the right one.

1, if the left int object is greater than the right one.

Examples:
dsettst.c.

Definition at line 708 of file dsettst.c.

Referenced by elemCmp().


Variable Documentation

const char* man[] [static]

Initial value:

{
"NAME                                                                         ",
"       dsettst - sample for usage and test of abstract set and map types     ",
"                                                                             ",
"SYNOPSIS                                                                     ",
"       dsettst [--silent] [--append]                                         ",
"               [--output=<file>] [--count=<number>] [--tests=<number>]       ",
"       dsettst --help [<option-name>...]                                     ",
"       dsettst --version                                                     ",
"                                                                             ",
"DESCRIPTION                                                                  ",
"       The command creates an object of each of the abstract container types "
"       set, multiset, map and multimap, fills it with random values and      "
"       finally deletes some of these values in random order.                 ",
"       During the fill and delete operations some consistency checks for the "
"       container objects are performed.                                      ",
"                                                                             ",
"OPTIONS                                                                      ",
"       --help                                                                ",
"       -h     If no argument <option-name> follows, print the command man    "
"              page on standard output, else the description of the options   "
"              <option-name> and exit with exit code 2.  The arguments        "
"              <option-name> shall be stated without leading '-' or '--'.     ",
"                                                                             ",
"       --version                                                             ",
"       -V     Print version info on standard output and exit with exit code  "
"              2.                                                             ",
"                                                                             ",
"       --silent                                                              ",
"       -s     Suppress all messages on stdout.                               ",
"                                                                             ",
"       --append                                                              ",
"       -a     If output is redirected to a file (see option --output),       "
"              instead of deleting the file, if it exists already, append to  "
"              it.                                                            ",
"                                                                             ",
"       --output=<file>                                                       ",
"       -o <file>                                                             ",
"              Generate the output additionally to stdout in <file>.  By      "
"              default, no additional output is generated.                    ",
"                                                                             ",
"       --count=<number>                                                      ",
"       -c <number>                                                           ",
"              Fill the abstract container objects with 2*<number> values and "
"              then delete <number> values.  By default <number> is 1000.     ",
"                                                                             ",
"       --tests=<number>                                                      ",
"       -t <number>                                                           ",
"              Do the tests <number> times.  By default <number> is 1.        "
}
Man page.

The string array man is formatted by the functions defined in Format and Print Manual Page Text.

Definition at line 85 of file dsettst.c.

StmBool silent = StmFalse [static]

Silent flag.

If the flag is StmTrue, no output on stdout is generated. The default value is StmFalse.

Examples:
dsettst.c.

Definition at line 236 of file dsettst.c.

Referenced by dsetPrintf(), and dsetShowf().

FILE* os = NULL [static]

Output file stream.

If not NULL, a pointer to the FILE object on which additional output is generated. The default value is NULL.

Examples:
dsettst.c.

Definition at line 244 of file dsettst.c.

Referenced by dsetPrintf().


© Copyright Tom Michaelis 2002-2007

Distributed under the SysToMath Software License (See the accompanying file license.txt or a copy at www.SysToMath.com).