Performing numeric operations

Your action arguments may contain numeric operations, such as addition and division. Such operations can operate on both numeric literals as well as variables.

  1. In the My expressions test module you created previously, create a new test case:

    1. Place your cell pointer on a line somewhere below the existing set of action lines (but before the FINAL section, if any).

    2. Click Create New Test Case on the toolbar.

      A test case line similar to the following is inserted.

    3. In the second column of the new line, assign the test case an ID of TC 02(if not already set to that value).

    4. Press Tab to advance to the next column, and provide a description for your test case, such asnumeric ops.

  2. Add the following two report action lines to your test case:

    
                text
    report      # 20 + 10 * 5
    report      # (20 + 10) * 5
    

    If you are familiar with operator precedence, you know that these two expressions are evaluated differently. In the first action line, the multiplication is performed first, then the addition. The second expression makes use of parentheses to force the addition to be performed first.

  3. Add two more action lines, to create and set two local variables:

    
                       name         value
    local variable     x            4
    local variable     y            # 20 + 10 * 5
    

    Notes: 
    A variable may be set to a numeric value as well as a string, with no need to explicitly declare the variable’s data type. Also notice that the value argument in a local variable action line can hold an expression as well as a constant.

    Tip: 
    During an editing session, entering the # symbol in an empty argument cell triggers an autocomplete pop-up window containing a list of variables thought to be within scope at that position in the action lines. Use the Up and Down arrow keys to select one, should you need it inserted at that point. You can bring back the pop-up list at any further point in the expression by pressing Ctrl + Space

  4. Finally, add a report action line:

    
                  text
    report        # x * y
    

    In this case, the expression involved consists of an operation on variables, rather than constants.

Your test case should now resemble this:



5. Execute Test Case 02 of your test.

With your test displayed in the editor, do the following:

  1. Click Execute on the toolbar.

The Execute Test dialog box appears.

  1. In the Test Modules panel, expand the tree.

  2. Ensure that only the check box for test caseTC 02is selected.

  3. Click Execute.

The status bar (at the bottom left of the TestArchitect window) indicates the stages of the test as it progresses.

As expected, the expressions in rows 32 and 33 yield different results, due to a differing order of operations. Line 40 displays the result of an expression involving variables.


Copyright © 2023 LogiGear Corporation. All rights reserved. LogiGear is a registered trademark, and Action Based Testing and TestArchitect are trademarks of LogiGear Corporation. All other trademarks contained herein are the property of their respective owners.

LogiGear Corporation

1730 S. Amphlett Blvd. Suite 200, San Mateo, CA 94402

Tel: +1(800) 322-0333