Domain-to-range ratio

From HandWiki
The domain-to-range ratio (DRR) is a ratio which describes how the number of outputs corresponds to the number of inputs of a given logical function or software component. The domain-to-range ratio is a mathematical ratio of cardinality between the set of the function's possible inputs (the domain) and the set of possible outputs (the range).[1][2] For a function defined on a domain, [math]\displaystyle{ D }[/math], and a range, [math]\displaystyle{ R }[/math], the domain-to-range ratio is given as:[math]\displaystyle{ DRR=\frac{|D|}{|R|} }[/math]It can be used to measure the risk of missing potential errors when testing the range of outputs alone.[3]

Example

Consider the function isEven() below, which checks the parity of an unsigned short number [math]\displaystyle{ x }[/math], any value between [math]\displaystyle{ 0 }[/math] and [math]\displaystyle{ 65,536 }[/math], and yields a boolean value which corresponds to whether [math]\displaystyle{ x }[/math] is even or odd. This solution takes advantage of the fact that integer division in programming typically rounds towards zero.

bool isEven(unsigned short x) {
    return (x / 2) == ((x + 3)/2 - 1);
}

Because [math]\displaystyle{ x }[/math] can be any value from [math]\displaystyle{ 0 }[/math] to [math]\displaystyle{ 65,535 }[/math], the function's domain has a cardinality of [math]\displaystyle{ 65,536 }[/math]. The function yields [math]\displaystyle{ 0 }[/math], if [math]\displaystyle{ x }[/math] is even, or [math]\displaystyle{ 1 }[/math], if [math]\displaystyle{ x }[/math] is odd. This is expressed as the range [math]\displaystyle{ \{0;1\} }[/math], which has a cardinality of [math]\displaystyle{ 2 }[/math]. Therefore, the domain-to-range ratio of isEven() is given by:[math]\displaystyle{ DRR={65,536 \over 2} = 32,768 }[/math]Here, the domain-to-range ratio indicates that this function would require a comparatively large number of tests to find errors. If a test program attempts every possible value of [math]\displaystyle{ x }[/math] in order from [math]\displaystyle{ 0 }[/math] to [math]\displaystyle{ 65,535 }[/math], the program would have to perform [math]\displaystyle{ 32,768 }[/math] tests for each of the two possible outputs in order to find errors or edge cases. Because errors in functions with a high domain-to-range ratio are difficult to identify via manual testing or methods which reduce the number of tested inputs, such as orthogonal array testing or all-pairs testing, more computationally complex techniques may be used, such as fuzzing or static program analysis, to find errors.


References

  1. Voas, J.M.; Miller, K.W. (March 1993). "Semantic metrics for software testability" (in en). Journal of Systems and Software 20 (3): 207–216. doi:10.1016/0164-1212(93)90064-5. 
  2. Woodward, Martin R.; Al-Khanjari, Zuhoor A. (5 September 2000). Testability, fault size and the domain-to-range ratio: An eternal triangle. ACM SIGSOFT. pp. 168–172. doi:10.1145/347324.349016. ISBN 978-1-58113-266-3. 
  3. Tarlinder, Alexander. Developer testing : building quality into software. ISBN 0-13-429106-9. OCLC 992888632. http://worldcat.org/oclc/992888632.