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.
In the
My expressions
test module you created previously, create a new test case:Place your cell pointer on a line somewhere below the existing set of action lines (but before the
FINAL
section, if any).Click Create New Test Case on the toolbar.
A test case line similar to the following is inserted.
In the second column of the new line, assign the test case an ID of
TC 02
(if not already set to that value).Press
Tab
to advance to the next column, and provide a description for your test case, suchasnumeric ops
.
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.
Add two more action lines, to create and set two local variables:
name value local variable x 4 local variable y # 20 + 10 * 5
注意: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.ヒント: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 theUp
andDown
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 pressingCtrl + Space
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:
- Click Execute on the toolbar.
The Execute Test dialog box appears.
In the Test Modules panel, expand the tree.
Ensure that only the check box for test caseTC 02is selected.
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.