# 04 — Conformance: the UCUM functional tests {#conformance}

## 1. The measure {#conformance-measure}

The library's conformance to UCUM is measured by the **UCUM functional tests**, the file
`UcumFunctionalTests.xml` of [Ucum-java](https://github.com/FHIR/Ucum-java), maintained by
Grahame Grieve. The file says of itself that an implementation passing every case may
declare conformance to it, and that one could then reasonably claim compliance with UCUM.

The file is vendored unmodified as `test/conformance/UcumFunctionalTests.xml`, with its
source, commit and Ucum-java's licence in `test/conformance/NOTICE`. A test holds its
SHA-256, so an edit fails. It is test input only and is not in the published package.

It has 573 cases in five sections, all of case-sensitive codes:

| Section | Cases | A case | Checked with |
|---|---|---|---|
| validation | 529 | a string, and whether it is a code | `Ucum.parse/1` |
| display name | 9 | a code and its name | `Ucum.name/1` |
| conversion | 30 | a value, two codes and the outcome | `Ucum.convert/3` |
| multiplication | 2 | two quantities and their product | `Ucum.multiply/2` |
| division | 3 | two quantities and their quotient | `Ucum.divide/2` |

`mix test` runs one test per case. A case is known by its section and its id, as
`validation/1-105`; the file repeats an id here and there, and a second bearer is
`validation/k=1=010#2`.

```test:conformance-file
the vendored file is Ucum-java's byte for byte, and holds its five sections with the cases counted here, each under a key of its own
```

```test:conformance-cases
every case of the file is a test: it passes, or it is listed as pending
```

## 2. How an outcome is compared {#conformance-outcome}

A **multiplication** or **division** case passes when the library's answer, converted to
the file's code, is the file's value, compared as a conversion's outcome is. The file
says so itself: the answer "doesn't have to be the same" as its own, but "must convert to
the stated value". It writes the unity as an empty code, which is read here as `1`.

A **display name** case passes when `name/1` answers the file's name, character for
character.

A **validation** case passes when `parse/1` reads the string the file calls a code, or
refuses the one it calls no code. The file's reason is a sentence for a reader; the
library's reason (spec/03) is not compared with it.

A **conversion** case passes when `convert/3`'s answer is the file's outcome **to the
significant figures the outcome states**: within half a unit of its last stated figure.
The file was written by an implementation that carries the precision of its input, so
6.3 `4.s/m` is `25` there and 6.30 `4.s/m` is `25.2`. UCUM defines no such arithmetic
and the library does not do it (spec/02 §4): it answers 25.2 for both, which is `25` to
two figures and `25.2` to three. An outcome stating more figures than a float holds
(`0.00000125663706143591729538506`) is compared to its fifteenth.

The figures an outcome states are its digits from the first that is not zero: `0.160`
states three and `0.0063` two. Zeros ending a whole number state none: `6300000` states
two.

```test:conformance-outcome
an outcome states its significant figures, and an answer meets it within half a unit of the last one and no further
```

## 3. The pending list {#conformance-pending}

`test/conformance/pending.exs` lists the cases the library does not pass yet, each under
the reason it does not. **The list only shrinks:**

- a case that fails and is not listed fails the suite;
- a case that is listed and passes fails the suite, until it is taken out;
- a key that names no case of the file fails the suite, and so does a key listed twice.

So the list is exactly what is left to do. The library conforms when the list is empty,
or holds only cases where the file contradicts UCUM's specification, each argued in this
section.

`mix conformance` prints the cases passing in each section and in all; CI prints it with
every run.

## 4. Where the library stands {#conformance-statement}

Over UCUM's essence table version 2.2 (2024-06-17) and the functional tests as of
Ucum-java's commit `e7d054e` (2025-04-22; the file's last history entry is 3 February
2021), the library passes **572 of 573** cases: validation 529 of 529, display name 8 of
9, conversion 30 of 30, multiplication 2 of 2, division 3 of 3. The README says the same,
and a test holds the two to what the suite measures.

```test:conformance-statement
the README states the count of cases passing that the suite measures
```

**Cases the library does not pass, and will not:**

- `displayNameGeneration/2-101` names the empty string `(unity)`. The same file's
  `validation/1-103` calls the empty string no code ("empty string is not a valid term"),
  and so does UCUM's grammar, in which a term is at least one component. The library
  refuses it everywhere, `name/1` included, with `:empty` (spec/03 §1): a function of a
  code has no answer for what is not one. The unity's code is `1`, whose name is `1`.

```test:conformance-pending
a case passes or is listed, never both and never neither; the list names only cases of the file, each once
```
