\d+)%\)$", RegexOptions.CultureInvariant);
+ int pairs = 0, withDecimals = 0, atTheCap = 0, pastTheCap = 0;
+
+ for (var i = 0; i < 2000; i++)
+ {
+ var expected = Math.Pow(10, random.NextDouble() * 12 - 6);
+ if (i % 3 == 0)
+ expected = Math.Max(Math.Round(expected), 1);
+ var actual = expected * Math.Pow(10, random.NextDouble() * 2 - 1);
+ if (i % 5 == 0)
+ actual = Math.Round(actual);
+ if (i % 20 == 0)
+ actual = 0;
+
+ var label = PlanRowAccuracy.FormatActualOfExpected(actual, expected, Invariant);
+ var context = $"actual {actual:R}, expected {expected:R} -> \"{label}\"";
+ var match = shape.Match(label);
+ Assert.True(match.Success, $"unexpected label shape: {context}");
+ pairs++;
+
+ // (2) no exponent
+ Assert.False(label.Contains('E') || label.Contains('e'), $"exponent in {context}");
+
+ var actualText = match.Groups["a"].Value;
+ var expectedText = match.Groups["e"].Value;
+ var printedActual = double.Parse(actualText, NumberStyles.Number, Invariant);
+ var printedExpected = double.Parse(expectedText, NumberStyles.Number, Invariant);
+
+ // (3) a non-zero value never prints as zero
+ Assert.True(actual == 0 || printedActual != 0, $"actual printed as zero: {context}");
+ Assert.True(printedExpected != 0, $"expected printed as zero: {context}");
+
+ // (1) the printed numbers give the printed percentage, unless the search ran out at four decimals
+ var decimals = Math.Max(DecimalPlaces(actualText), DecimalPlaces(expectedText));
+ var agrees = (printedActual / printedExpected * 100).ToString("F0", Invariant) == match.Groups["p"].Value;
+ Assert.True(agrees || decimals >= 4, $"the label contradicts its percentage before the cap: {context}");
+
+ if (decimals > 0)
+ withDecimals++;
+ if (decimals >= 4)
+ atTheCap++;
+ if (decimals >= 5)
+ pastTheCap++;
+ }
+
+ Assert.Equal(2000, pairs);
+ // The sweep has to reach the interesting paths, or the three properties above prove little.
+ Assert.True(withDecimals > 800, $"only {withDecimals} labels needed decimals");
+ Assert.True(atTheCap > 200, $"only {atTheCap} labels reached the cap");
+ Assert.True(pastTheCap > 100, $"only {pastTheCap} labels needed the first-significant-digit rule");
+ }
+
+ private static int DecimalPlaces(string number)
+ {
+ var point = number.IndexOf('.');
+ return point < 0 ? 0 : number.Length - point - 1;
+ }
+
+ // ---- the surfaces ------------------------------------------------------------------------
+
+ ///