FAILURE MAP
← Case archive

FA-97356 / Knitting and sewing pattern grading / Open access

Gauge-based cast-on calculator: minimum one repeat · case 01

A narrow strap in an 8-stitch cable casts on only selvedge stitches.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

A zero-repeat rounding result is not raised to one full repeat.

VERIFIED REPAIR

Clamp body stitches to at least one repeat.

Unsuccessful approach: A floor of one stitch is not a whole repeat.

Case contract

Target width = width + ease (ease may be negative). Raw stitches = target * gauge / 10 (gauge per 10 cm). Body stitches = nearest multiple of repeat, half-up in repeat units, at least one repeat. Cast on = body + 2*edge (selvedge each side). Actual body width = body*10/gauge, half-up to 0.1 cm. Non-positive target, gauge or repeat returns an error string.

Why this case matters

Knitting patterns and calculators convert a finished measurement and gauge into a stitch count that fits the stitch pattern repeat.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(width_cm, sts_per_10cm, repeat, edge, ease_cm):
    w = Fraction(str(width_cm)) + Fraction(str(ease_cm))
    g = Fraction(str(sts_per_10cm))
    if w <= 0 or g <= 0 or repeat < 1:
        return 'error: bad measurements'
    raw = w * g / 10
    body = repeat * math.floor(raw / repeat + Fraction(1, 2))
    body = body
    total = body + 2 * edge
    actual = body * 10 / g
    return [total, math.floor(actual * 10 + Fraction(1, 2)) / 10]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain stockinette', [50, '20', 1, 0, 0], [100, 50.0]],
  ['rib with selvedges', [45, '22', 4, 1, 5], [114, 50.9]],
  ['narrow strap one repeat', [3, '16', 8, 2, 0], [12, 5.0]],
  ['regression: minimum one repeat', [3, '24', 8, 3, -2], [14, 3.3]],
  ['repair check: minimum one repeat', [3, '20', 8, 2, -2], [12, 4.0]],
  ['generated control 1', [52.5, '20', 6, 2, -5], [100, 48.0]],
  ['generated control 2', [52.5, '27.5', 6, 1, -2], [140, 50.2]],
  ['generated control 3', [10, '22', 12, 1, 7.5], [38, 16.4]]],
 [['rib with selvedges', [45, '22', 4, 1, 5], [114, 50.9]],
  ['narrow strap one repeat', [3, '16', 8, 2, 0], [12, 5.0]],
  ['negative ease', [40, '24', 2, 1, -5], [86, 35.0]],
  ['regression: minimum one repeat', [3, '22', 6, 2, -2], [10, 2.7]],
  ['repair check: minimum one repeat', [3, '24', 6, 1, -2], [8, 2.5]],
  ['generated control 1', [52.5, '20', 6, 1, -2], [104, 51.0]],
  ['generated control 2', [3, '16', 1, 3, -2], [8, 1.3]],
  ['generated control 3', [50, '22', 1, 3, 7.5], [133, 57.7]]],
 [['narrow strap one repeat', [3, '16', 8, 2, 0], [12, 5.0]],
  ['negative ease', [40, '24', 2, 1, -5], [86, 35.0]],
  ['invalid width', [3, '20', 2, 0, -5], 'error: bad measurements'],
  ['regression: minimum one repeat', [3, '24', 12, 2, -2], [16, 5.0]],
  ['repair check: minimum one repeat', [3, '18', 12, 0, -2], [12, 6.7]],
  ['generated control 1', [45, '16', 6, 2, 5], [82, 48.8]],
  ['generated control 2', [30, '27.5', 4, 1, -5], [70, 24.7]],
  ['generated control 3', [45, '20', 6, 1, 7.5], [110, 54.0]]],
 [['negative ease', [40, '24', 2, 1, -5], [86, 35.0]],
  ['invalid width', [3, '20', 2, 0, -5], 'error: bad measurements'],
  ['plain stockinette', [50, '20', 1, 0, 0], [100, 50.0]],
  ['regression: minimum one repeat', [3, '18', 12, 2, -2], [16, 6.7]],
  ['repair check: minimum one repeat', [3, '20', 6, 0, -2], [6, 3.0]],
  ['generated control 1', [3, '22', 4, 3, -5], 'error: bad measurements'],
  ['generated control 2', [8, '22', 12, 3, -5], [18, 5.5]],
  ['generated control 3', [10, '22', 2, 3, 10], [50, 20.0]]],
 [['invalid width', [3, '20', 2, 0, -5], 'error: bad measurements'],
  ['plain stockinette', [50, '20', 1, 0, 0], [100, 50.0]],
  ['rib with selvedges', [45, '22', 4, 1, 5], [114, 50.9]],
  ['regression: minimum one repeat', [3, '18', 12, 1, 0], [14, 6.7]],
  ['repair check: minimum one repeat', [3, '22', 12, 3, -2], [18, 5.5]],
  ['generated control 1', [10, '18', 6, 0, 7.5], [30, 16.7]],
  ['generated control 2', [3, '18', 6, 2, -5], 'error: bad measurements'],
  ['generated control 3', [52.5, '24', 1, 3, -2], [127, 50.4]]]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
plain stockinette[100, 50.0][100, 50.0]Passed
rib with selvedges[114, 50.9][114, 50.9]Passed
narrow strap one repeat[12, 5.0][12, 5.0]Passed
regression: minimum one repeat[6, 0.0][14, 3.3]Failed
repair check: minimum one repeat[4, 0.0][12, 4.0]Failed
generated control 1[100, 48.0][100, 48.0]Passed
generated control 2[140, 50.2][140, 50.2]Passed
generated control 3[38, 16.4][38, 16.4]Passed

SHA-256 / f5bf6759c888f851c4556a0620697fe04f98b667ea434997d75f7b12fa194e20

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(width_cm, sts_per_10cm, repeat, edge, ease_cm):
    w = Fraction(str(width_cm)) + Fraction(str(ease_cm))
    g = Fraction(str(sts_per_10cm))
    if w <= 0 or g <= 0 or repeat < 1:
        return 'error: bad measurements'
    raw = w * g / 10
    body = repeat * math.floor(raw / repeat + Fraction(1, 2))
    body = max(1, body)
    total = body + 2 * edge
    actual = body * 10 / g
    return [total, math.floor(actual * 10 + Fraction(1, 2)) / 10]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain stockinette', [50, '20', 1, 0, 0], [100, 50.0]],
  ['rib with selvedges', [45, '22', 4, 1, 5], [114, 50.9]],
  ['narrow strap one repeat', [3, '16', 8, 2, 0], [12, 5.0]],
  ['regression: minimum one repeat', [3, '24', 8, 3, -2], [14, 3.3]],
  ['repair check: minimum one repeat', [3, '20', 8, 2, -2], [12, 4.0]],
  ['generated control 1', [52.5, '20', 6, 2, -5], [100, 48.0]],
  ['generated control 2', [52.5, '27.5', 6, 1, -2], [140, 50.2]],
  ['generated control 3', [10, '22', 12, 1, 7.5], [38, 16.4]]],
 [['rib with selvedges', [45, '22', 4, 1, 5], [114, 50.9]],
  ['narrow strap one repeat', [3, '16', 8, 2, 0], [12, 5.0]],
  ['negative ease', [40, '24', 2, 1, -5], [86, 35.0]],
  ['regression: minimum one repeat', [3, '22', 6, 2, -2], [10, 2.7]],
  ['repair check: minimum one repeat', [3, '24', 6, 1, -2], [8, 2.5]],
  ['generated control 1', [52.5, '20', 6, 1, -2], [104, 51.0]],
  ['generated control 2', [3, '16', 1, 3, -2], [8, 1.3]],
  ['generated control 3', [50, '22', 1, 3, 7.5], [133, 57.7]]],
 [['narrow strap one repeat', [3, '16', 8, 2, 0], [12, 5.0]],
  ['negative ease', [40, '24', 2, 1, -5], [86, 35.0]],
  ['invalid width', [3, '20', 2, 0, -5], 'error: bad measurements'],
  ['regression: minimum one repeat', [3, '24', 12, 2, -2], [16, 5.0]],
  ['repair check: minimum one repeat', [3, '18', 12, 0, -2], [12, 6.7]],
  ['generated control 1', [45, '16', 6, 2, 5], [82, 48.8]],
  ['generated control 2', [30, '27.5', 4, 1, -5], [70, 24.7]],
  ['generated control 3', [45, '20', 6, 1, 7.5], [110, 54.0]]],
 [['negative ease', [40, '24', 2, 1, -5], [86, 35.0]],
  ['invalid width', [3, '20', 2, 0, -5], 'error: bad measurements'],
  ['plain stockinette', [50, '20', 1, 0, 0], [100, 50.0]],
  ['regression: minimum one repeat', [3, '18', 12, 2, -2], [16, 6.7]],
  ['repair check: minimum one repeat', [3, '20', 6, 0, -2], [6, 3.0]],
  ['generated control 1', [3, '22', 4, 3, -5], 'error: bad measurements'],
  ['generated control 2', [8, '22', 12, 3, -5], [18, 5.5]],
  ['generated control 3', [10, '22', 2, 3, 10], [50, 20.0]]],
 [['invalid width', [3, '20', 2, 0, -5], 'error: bad measurements'],
  ['plain stockinette', [50, '20', 1, 0, 0], [100, 50.0]],
  ['rib with selvedges', [45, '22', 4, 1, 5], [114, 50.9]],
  ['regression: minimum one repeat', [3, '18', 12, 1, 0], [14, 6.7]],
  ['repair check: minimum one repeat', [3, '22', 12, 3, -2], [18, 5.5]],
  ['generated control 1', [10, '18', 6, 0, 7.5], [30, 16.7]],
  ['generated control 2', [3, '18', 6, 2, -5], 'error: bad measurements'],
  ['generated control 3', [52.5, '24', 1, 3, -2], [127, 50.4]]]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
plain stockinette[100, 50.0][100, 50.0]Passed
rib with selvedges[114, 50.9][114, 50.9]Passed
narrow strap one repeat[12, 5.0][12, 5.0]Passed
regression: minimum one repeat[7, 0.4][14, 3.3]Failed
repair check: minimum one repeat[5, 0.5][12, 4.0]Failed
generated control 1[100, 48.0][100, 48.0]Passed
generated control 2[140, 50.2][140, 50.2]Passed
generated control 3[38, 16.4][38, 16.4]Passed

SHA-256 / 6fcf085f3ca4f50dd7d5e77818a519bd92f106c14bc06ad0ef8837b6ca2424ff

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(width_cm, sts_per_10cm, repeat, edge, ease_cm):
    w = Fraction(str(width_cm)) + Fraction(str(ease_cm))
    g = Fraction(str(sts_per_10cm))
    if w <= 0 or g <= 0 or repeat < 1:
        return 'error: bad measurements'
    raw = w * g / 10
    body = repeat * math.floor(raw / repeat + Fraction(1, 2))
    body = max(repeat, body)
    total = body + 2 * edge
    actual = body * 10 / g
    return [total, math.floor(actual * 10 + Fraction(1, 2)) / 10]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain stockinette', [50, '20', 1, 0, 0], [100, 50.0]],
  ['rib with selvedges', [45, '22', 4, 1, 5], [114, 50.9]],
  ['narrow strap one repeat', [3, '16', 8, 2, 0], [12, 5.0]],
  ['regression: minimum one repeat', [3, '24', 8, 3, -2], [14, 3.3]],
  ['repair check: minimum one repeat', [3, '20', 8, 2, -2], [12, 4.0]],
  ['generated control 1', [52.5, '20', 6, 2, -5], [100, 48.0]],
  ['generated control 2', [52.5, '27.5', 6, 1, -2], [140, 50.2]],
  ['generated control 3', [10, '22', 12, 1, 7.5], [38, 16.4]]],
 [['rib with selvedges', [45, '22', 4, 1, 5], [114, 50.9]],
  ['narrow strap one repeat', [3, '16', 8, 2, 0], [12, 5.0]],
  ['negative ease', [40, '24', 2, 1, -5], [86, 35.0]],
  ['regression: minimum one repeat', [3, '22', 6, 2, -2], [10, 2.7]],
  ['repair check: minimum one repeat', [3, '24', 6, 1, -2], [8, 2.5]],
  ['generated control 1', [52.5, '20', 6, 1, -2], [104, 51.0]],
  ['generated control 2', [3, '16', 1, 3, -2], [8, 1.3]],
  ['generated control 3', [50, '22', 1, 3, 7.5], [133, 57.7]]],
 [['narrow strap one repeat', [3, '16', 8, 2, 0], [12, 5.0]],
  ['negative ease', [40, '24', 2, 1, -5], [86, 35.0]],
  ['invalid width', [3, '20', 2, 0, -5], 'error: bad measurements'],
  ['regression: minimum one repeat', [3, '24', 12, 2, -2], [16, 5.0]],
  ['repair check: minimum one repeat', [3, '18', 12, 0, -2], [12, 6.7]],
  ['generated control 1', [45, '16', 6, 2, 5], [82, 48.8]],
  ['generated control 2', [30, '27.5', 4, 1, -5], [70, 24.7]],
  ['generated control 3', [45, '20', 6, 1, 7.5], [110, 54.0]]],
 [['negative ease', [40, '24', 2, 1, -5], [86, 35.0]],
  ['invalid width', [3, '20', 2, 0, -5], 'error: bad measurements'],
  ['plain stockinette', [50, '20', 1, 0, 0], [100, 50.0]],
  ['regression: minimum one repeat', [3, '18', 12, 2, -2], [16, 6.7]],
  ['repair check: minimum one repeat', [3, '20', 6, 0, -2], [6, 3.0]],
  ['generated control 1', [3, '22', 4, 3, -5], 'error: bad measurements'],
  ['generated control 2', [8, '22', 12, 3, -5], [18, 5.5]],
  ['generated control 3', [10, '22', 2, 3, 10], [50, 20.0]]],
 [['invalid width', [3, '20', 2, 0, -5], 'error: bad measurements'],
  ['plain stockinette', [50, '20', 1, 0, 0], [100, 50.0]],
  ['rib with selvedges', [45, '22', 4, 1, 5], [114, 50.9]],
  ['regression: minimum one repeat', [3, '18', 12, 1, 0], [14, 6.7]],
  ['repair check: minimum one repeat', [3, '22', 12, 3, -2], [18, 5.5]],
  ['generated control 1', [10, '18', 6, 0, 7.5], [30, 16.7]],
  ['generated control 2', [3, '18', 6, 2, -5], 'error: bad measurements'],
  ['generated control 3', [52.5, '24', 1, 3, -2], [127, 50.4]]]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
plain stockinette[100, 50.0][100, 50.0]Passed
rib with selvedges[114, 50.9][114, 50.9]Passed
narrow strap one repeat[12, 5.0][12, 5.0]Passed
regression: minimum one repeat[14, 3.3][14, 3.3]Passed
repair check: minimum one repeat[12, 4.0][12, 4.0]Passed
generated control 1[100, 48.0][100, 48.0]Passed
generated control 2[140, 50.2][140, 50.2]Passed
generated control 3[38, 16.4][38, 16.4]Passed

SHA-256 / 0ea2b21be2310316e26836fb26b8cd593ad569304117525f539b75b6383b2bd5

Verification & scope

A deterministic toy contract stated in full here; it is a bounded teaching model, not an authoritative reference or standards implementation. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:52:31.410393+00:00.

Case digest / 5b6d263fb6cc79ce77bb52e2d8de63ddf453c385d95213ff7ceb3172ab5a5278