Functions on List

This page provides an extract of frequently used functions using list.

Function Input Types Return Type Description
$AT(list1, index1) List, Integer Element Returns the element at index1 index in list1 list.

Example: $AT("The" $+ "black" $+ "cat", 2) returns "black".

$ATPUT(list1, index, elt) List, Integer, Element List Replaces the element of index position in list1 by elt.

Example: $AT("The" $+ "black" $+ "cat", 2, "white") returns "The white cat".

$CNT(list1) List Integer Returns the number of elements in list1 list.

Example: $CNT("The" $+ "black" $+ "cat") returns 3.

$FIRST(list1) List Element Returns the first element of list1 list.

Example:$FIRST("The" $+ "black" $+ "cat") returns "The".

$INDEX(list1, elt) List, Element Integer Returns the index of the first occurrence of elt element within list1 list.

Example: $INDEX("The" $+ "black" $+ "cat", "cat") returns 3.

$LAST(list1) List Element Returns the last element of list1 list.

Example: $LAST("The" $+ "black" $+ "cat") returns "cat".

$NO(list1) List Boolean Returns TRUE if list1 is empty.

Example: $NO("The" $+ "black" $+ "cat")

returns FALSE.
$REV(list1) List List Returns the inverse of list1 list.

Example: $REV("The" $+ "black" $+ "cat") returns "cat" $+ "black" $+ "The".

$SOME(list1) List Boolean Returns TRUE if list1 is not empty.

Example: $SOME("The" $+ "black" $+ "cat") returns TRUE.

$SUB(list1, startIndex, endIndex) List, Integer, Integer List Returns a list beginning at startIndex index and ending at endIndex index.

Example: $SUB("The" $+ "black" $+ "cat", 1, 2) returns ("The" $+ "black").

$TAIL(list1) List List Returns the list without the first element.

Example: $TAIL("The" $+ "black" $+ "cat") returns "black" $+ "cat".

Examples

Prerequisite: reqSpec is an element of Requirement Specification class and req is of Requirement class.

  • To test if the number of requirements is bigger or equal to 2.

    $CNT(reqSpec.getAllRequirements) >= 2

  • To test if some requirements are named Criticality.

    $SOME(reqSpec.getAllRequirements[req.name="Criticality"])