4.9. Quality Calculation

In MQC, functions are used to calculate

4.9.1. Functions in MQC

There are two types of functions in MQC:

In both cases Mathematical functions as well as Logical functions and operators can be used to define a function.

In all functions, base and derived measures always must be defined in square brackets [ and ]!

4.9.1.1. Functions to calculate numerical values

These functions are used to calculate a number, e.g. a value between 0 and 1 as quality, or to combine the values of multiple similar data measures (via sum, avg, etc.) to compute derived measures.

The following examples depict how to define numerical functions, starting from the simplest case to more complex expressions.

[Model Decision Coverage.Ratio]

In this case the imported data measure is already a value between 0 and 1. It may be directly used to derive the corresponding quality property value.

[TestCount.Passed] / [TestCount.Total]

Such expressions are mainly used to compare a value against an expected value. The closer the value of TestCount.Passed is to the TestCount.Total, the better the quality.

(1.0 * [TestCount.Succeeded] +
 0.2 * [TestCount.Failed] +
 0.0 * [TestCount.Errors] +
 0.0 * [TestCount.Inconclusive])
/ [TestCount.Total]

Combining similar measures like the amount of different test results, may lead to a more detailed representation of the reality. Factors may be used to increase or reduce the impact of a certain measure. In the above example a factor of 0.2 is used for the number of failed test cases to differentiate between these tests and the not executed ones.

[TestCount.Total] == 0 ? 0 : [TestCount.Passed] / [TestCount.Total]

[GuidelineCount.Passed] + log(1 + [FindingCount.Passed], 2)

The above examples show more complex expressions using inline if statements respectively mathematical functions like log(x, y).

4.9.1.2. Functions to evaluate conditional expressions

The result of a conditional function is either true or false. This type of functions is used to define Conditions.

The simplest case of such a conditional function is shown by the following example.

True

A more complex example uses different base measures (possibly from different data sources) to evaluate if the result of the condition is true or false.

(([Statement Coverage.Ratio] >= 0.8 and
  [TestCount.Failed] = 0 and
  [TestCount.Error] = 0) or
 ([MC/DC Coverage.Ratio] >= 0.8 and
  [TestCount.Failed] = 0 and
  [TestCount.Error] = 0))

4.9.2. Mathematical functions

Apart from the four basic arithmetic operations (+, -, * and /), the following functions can be used:

  • Abs(x):

    Returns the absolute (positive) value of x

  • Cbrt(x):

    Returns the cube root of x

  • Ceil(x):

    Returns x rounded up to its nearest integer

  • Cos(x):

    Returns the cosine (a value between -1 and 1) of the angle x (given in radians)

  • Exp(x):

    Returns the value of e to the power of x

  • Floor(x):

    Returns x rounded down to its nearest integer

  • Log(x, y):

    Returns the logarithm of x with base y (if no y is given, the base is e)

  • Max():

    Returns the highest value in a list of arguments

  • Min():

    Returns the lowest value in a list of arguments

  • Pow(x, y):

    Returns the value of x to the power of y

  • Round(x):

    Returns x rounded to its nearest integer

  • Sign(x):

    Returns if x is negative, null or positive

  • Sin(x):

    Returns the sine (a value between -1 and 1) of the angle x (given in radians)

  • Sqrt(x):

    Returns the square root of x

  • Tan(x):

    Returns the tangent of x

  • Trunc(x):

    Returns the integer part of x

4.9.3. Logical functions and operators

The following statements resp. operators can be used:

  • Inline if

    To define conditional expressions to be used e.g. for step functions.

    [OpenIssues.Total] = 0
        ? 1
        : [OpenIssues.Total] <= 10
              ? 0.5
              : [OpenIssues.Total] <= 100
                    ? 0.2
                    : 0
    
  • And

    Connects two or more expressions and returns only true if all expressions return true. Can be used in inline if statements as well as to define bin conditions.

  • Or

    Connects two or more expressions and returns true if at least one of the expressions returns true. Can be used in inline if statements as well as to define bin conditions.