Mr. Cluey : Special Topics : Associative Arrays


Implementing Associative Arrays

Richard Weth
Senior QA Engineer
Thru-Put Technologies
http://www.thru-put.com
richardw@thru-put.com

I apologize for my web server - it isn't under my direct control, so I cannot ensure that it displays 4Test source files in a friendly manner. A Zipped version of the files referenced in this article is available. -- Mr Cluey

{Note: The "*.inc" and "*.t" files have had the ".txt" extension added to them so that they should display in the new versions of MSIE and Netscape - KZ]

I have no idea if this has been done before on the forum so let me apologize in advance if this is redundant, or the wrong place for this enclosure. I noted that QAP thusfar does not seem to have a Dictionary Class .. or what is often referred to as an associative array.

Where unlike a regular array, Data values (of anytype) can be associated with a key of a particular string.

This is very much like a regular assignment like:

integer phil = 10

.. except it is done in an object. The key (such as phil) could then be Associated with it's value (10) - like

  dict_obj['phil'] = 10 .. //sort of

This is much easier on the user than a regular array index. Additionally this class has serialization ability, which is a fancy way of saying it can be stored to or initialized from a flat file. The only limitation in this area is that there is a current buffer limitation of something like 32KB in QAP 4.2 and 64KB in QAP 4.3 and beyond for the function FileWriteValue. That means that at present the biggest data value that could be STORED to a file for a particular key is 32KB or 64KB depending on your release.

Anyway if you come from a programming background or language where you have Dictionaries or Associative arrays (and I guess you know who you are) you will find this very helpful. We employ this structure here to do things like

  1. Set environment variables without the main script pollution of an include file. By declaring a Global variable like so:
    window Dictionary env_dict
    

    Library routines, main script functions etc can access data without Globally declaring it in the main script. By Classifying large amounts of data the natural class encapsulation can be leveraged.

  2. This is very helpful in writing data driven tests with the benefits of point #1 and having data separate from test scripts
  3. This structure can be used in many very helpful algorithms like work Lists, and other loop logic.
  4. The author thinks it's neat!

Anyway I have a department of 5 QA Engineers that employ this Class on a daily basis for something like 7 Months now. You can with a high degree of probability/confidence store hundreds .. to a few thousands of key/value associations in Class Object. I encourage anyone who may benefit from this class to try it, I bet you will find it helpful and hopefully fun.

Here is the class itself in it's own include file: dict.inc

Here is a writup of it's member functions (methods) and member variable (somewhat incomplete): dictionary.doc

Finally here is an example of it's use dicttest.t .. beware if you run this it will store the following dictiony FILES on your cdrive:

If you want to change the path simply change this statement in the script:

[ ] //Please change this to your own preferred drive letter + directory
[ ] STRING WP = "c:\"

My apologies to mime mail recipients or people who cannot handle enclosures.

Finally if you do use this class please do so without restriction .. EXCEPT I require you to keep the comment in the dict.inc file:

[ ] // Copyright 1997 by Thru-Put Technologies, All Rights Reserved.
[ ] // Written by  Richard Weth

Especially the part where it says == // Written by Richard Weth :-)

I can only hope some small segment of the QAP populous enjoys/uses this. Perhaps if this is useful enough Segue may decide to:

  1. Make this an internal Class with QAP (maybee??)
  2. Increase the buffer limitation on FileWriteValue .. since there shouldn't be any limit on it in the first place!!!

Mr. Cluey : Special Topics : Associative Arrays

Return to ATS Automated Testing Resources Page