> For the complete documentation index, see [llms.txt](https://practical-testing.gitbook.io/home/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://practical-testing.gitbook.io/home/techniques/elementary-comparison.md).

# Elementary Comparison

### Quick Summary

* Elementary Comparison (EC) is similar to a [Decision Table (DT)](/home/techniques/decision-tables-and-trees.md) with binary values (Truth Table).
* Use to:
  * Check the effect of each individual condition
  * Get a **compact alternative** to a Truth Table.

### AND / OR operators

Condition combinations may be combined using logical AND or OR.

> Example 1: A rule is true if ONE of the conditions is true. This implies OR.\
> (`0/1` are easier to distinguish visually and are therefore used instead of `Y/N` )
>
> \
> \|  0   0 |         |  0  |
>
> \|  0   1  |    →  |  1  |
>
> \|  1   0  |         |  1  |
>
> \|  0   1  |         |  1  |\
> \
> \
> Example 2: A rule is true only if ALL conditions are true. This implies AND.\
> \
> Notice two things:
>
> * The tables grows exponentially just like a DT: 2<sup>3</sup>= 8 (2 values to the power of 3 conditions)
> * Only ONE compound condition results in the rule being true (last one: `| 1 1 1 |=  | 1 |`)
>
> \
> \
> \|  0   0   0  |          |  0  |\
> \|  0   0   1   |          |  0  |\
> \|  0   1   0   |          |  0  |\
> \|  0   1   1    |    →   |  0  |\
> \|  1   0   0   |          |  0  |\
> \|  1   0   1    |          |  0  |\
> \|  1   1    0   |          |  0  |\
> \|  1   1    1    |          |  1   |

Example 2 above illustrates that as long as ONE condition is false, the result remains the same. So instead of exhaustive testing (all 8 combinations), we may **reduce** the number to 4 rules:

* `| 1 1 1 |` - the only scenario with a positive outcome
* `| 0 1 1 |` ,  `| 1 0 1 |`, `| 1 1 0 |` - where ANY ONE false condition negates the outcome. These tests check the effect of **each individual condition**.

{% hint style="warning" %}
The above allows for reducing the testing effort as part of a calculated risk. There is still a risk that the software logic was written in such a way that e.g. `| 0 0 1 |` causes a bug.
{% endhint %}

### Full DT vs. ET

#### ✅ Full Decision Table (All 8 Combinations)

This covers **all possible combinations** of 3 binary conditions (2³ = 8 rules).

<table><thead><tr><th width="112.727294921875" align="center">Rule</th><th width="116" align="center">Age ≥ 18</th><th width="120.81817626953125" align="center">Employed?</th><th align="center">Credit Score ≥ 700</th><th align="center">Decision</th></tr></thead><tbody><tr><td align="center">1</td><td align="center">Y</td><td align="center">Y</td><td align="center">Y</td><td align="center">Approve</td></tr><tr><td align="center">2</td><td align="center">Y</td><td align="center">Y</td><td align="center">N 🔴</td><td align="center">Reject</td></tr><tr><td align="center">3</td><td align="center">Y</td><td align="center">N 🔴</td><td align="center">Y</td><td align="center">Reject</td></tr><tr><td align="center">4</td><td align="center">Y</td><td align="center">N</td><td align="center">N</td><td align="center">Reject</td></tr><tr><td align="center">5</td><td align="center">N🔴</td><td align="center">Y</td><td align="center">Y</td><td align="center">Reject</td></tr><tr><td align="center">6</td><td align="center">N</td><td align="center">Y</td><td align="center">N</td><td align="center">Reject</td></tr><tr><td align="center">7</td><td align="center">N</td><td align="center">N</td><td align="center">Y</td><td align="center">Reject</td></tr><tr><td align="center">8</td><td align="center">N</td><td align="center">N</td><td align="center">N</td><td align="center">Reject</td></tr></tbody></table>

✂️ Reduced ET Table (Just 4 Rules)\
We pick Rule 1, which leads to the `Approve` decision, and Rules with 🔴 - where a single `N` condition negates the outcome.

<table><thead><tr><th width="112.727294921875" align="center">Rule</th><th width="116" align="center">Age ≥ 18</th><th width="120.81817626953125" align="center">Employed?</th><th align="center">Credit Score ≥ 700</th><th align="center">Decision</th></tr></thead><tbody><tr><td align="center">1</td><td align="center">Y</td><td align="center">Y</td><td align="center">Y</td><td align="center">Approve</td></tr><tr><td align="center">2</td><td align="center">Y</td><td align="center">Y</td><td align="center">N🔴</td><td align="center">Reject</td></tr><tr><td align="center">3</td><td align="center">Y</td><td align="center">N🔴</td><td align="center">Y</td><td align="center">Reject</td></tr><tr><td align="center">4</td><td align="center">N🔴</td><td align="center">Y</td><td align="center">Y</td><td align="center">Reject</td></tr></tbody></table>
