>"Invariants, like assertions, are things that must be true during or after the execution of a piece of code. "This array is sorted", "the first item is the smallest", "items in the deleted state must have a deleted time", that kind of thing. Invariants are broader than assertions: they can assert properties of a piece of data, properties of an entire data structure, or even properties of collections of data structures spread across multiple machines."<p>Yes!<p>In theory it would be possible to assert the correctness of an entire codebase with <i>only a single unit test(!)</i> ran on only a single piece of data(!) -- but that's IF, <i>if and only if</i> -- the code is known to be tightly and invariably bound to that key piece of data such that its entire functionality can be asserted via the state of that piece of data!<p>There is a broader pattern here, too...<p>Let's suppose we have a cup which is half-full, half-empty.<p>If we call the fullness of the cup "X" and the emptiness of the cup "Y" -- then if we know one of these things, one of these aspects of the underlying system -- then we also know the other one! (X's relationship to Y is: X = 1/Y, correspondingly, Y's relationship to X is: Y=1/X (inverse AKA reciprocal relationship...))<p>But the point is: <i>If you know the state of one, you also know the state of the other...</i><p>In the case of the theoretical codebase whose code is tightly, invariably, deterministically coupled to one key variable thus requiring only one unit test of that variable to assert the correctness of the entire codebase -- "X" is that variable, and "Y" is "the codebase"!<p>These relationships do not need to be inverse or reciprocal as with the half full, half empty cup of water example -- they can be <i>asymmetric</i>, as in the case of the theoretical codebase with the single unit test!<p>The broader broader pattern is "if thing A (correctly and invariably!) asserts thing B -- then if you have thing A -- then <i>you also have thing B</i> (without needing to check thing B independently!)".<p>In Logic, this can be thought of as "If A implies B, and you have A (A is True), then you also have B (B exists and is True -- as a result of merely having A)"<p>In Business, one might compare the concept of KPI's (Key Performance Indicators) to this -- if you have a KPI (measurement, observation) on the one hand, then you also have an asserted state of the business on the other, but remember, that's <i>if and only if</i> the two things are tightly and invariably bound -- that is, aspects of the same underlying phenomena...