Functional Weave
Code in Rust

charts.contrast@1.0.0

vectors.json

3,034 bytes · view raw

[
  { "fn": "contrastRatio", "name": "black on white is the maximum, 21", "args": ["#000000", "#ffffff"], "expect": 21 },
  { "fn": "contrastRatio", "name": "the order of the colours does not matter", "args": ["#ffffff", "#000000"], "expect": 21 },
  { "fn": "contrastRatio", "name": "a colour against itself is 1", "args": ["#ffffff", "#FFF"], "expect": 1 },
  { "fn": "contrastRatio", "name": "#777777 on white just fails AA at 4.48", "args": ["#777777", "#ffffff"], "expect": 4.478089 },
  { "fn": "contrastRatio", "name": "#767676 on white just passes AA at 4.54", "args": ["#767676", "#ffffff"], "expect": 4.542225 },
  { "fn": "contrastRatio", "name": "#595959 on white passes AAA at 7.0", "args": ["#595959", "#ffffff"], "expect": 7.004729 },
  { "fn": "contrastRatio", "name": "pure red on white is under 4, despite looking strong", "args": ["#ff0000", "#ffffff"], "expect": 3.998477 },
  { "fn": "contrastRatio", "name": "mid grey against black", "args": ["#808080", "#000000"], "expect": 5.31721 },
  { "fn": "contrastRatio", "name": "mid grey against white is lower: luminance is linear light, not channel numbers", "args": ["#808080", "#ffffff"], "expect": 3.94944 },
  { "fn": "contrastRatio", "name": "Okabe-Ito orange against black", "args": ["#e69f00", "#000000"], "expect": 9.323854 },
  { "fn": "contrastRatio", "name": "Okabe-Ito blue against white", "args": ["#0072b2", "#ffffff"], "expect": 5.185446 },
  { "fn": "contrastRatio", "name": "a near-black on the straight part of the sRGB curve", "args": ["#0a0a0a", "#000"], "expect": 1.060705 },
  { "fn": "contrastRatio", "name": "a bad colour is an error", "args": ["#12345", "#ffffff"], "expectError": "is not a hex colour" },
  { "fn": "readableTextColor", "name": "white text on dark blue", "args": ["#0072b2", ["#000000", "#ffffff"]], "expect": "#ffffff" },
  { "fn": "readableTextColor", "name": "black text on orange", "args": ["#e69f00", ["#000000", "#ffffff"]], "expect": "#000000" },
  { "fn": "readableTextColor", "name": "black on mid grey #808080, which a 50% lightness rule gets wrong", "args": ["#808080", ["#ffffff", "#000000"]], "expect": "#000000" },
  { "fn": "readableTextColor", "name": "black on vermillion (5.4 against 3.9 for white)", "args": ["#d55e00", ["#ffffff", "#000000"]], "expect": "#000000" },
  { "fn": "readableTextColor", "name": "white on black", "args": ["#000", ["#000000", "#ffffff"]], "expect": "#ffffff" },
  { "fn": "readableTextColor", "name": "a tie goes to the first candidate, returned as given", "args": ["#ffffff", ["#000", "#000000"]], "expect": "#000" },
  { "fn": "readableTextColor", "name": "one candidate is returned whatever its contrast", "args": ["#ffffff", ["#eeeeee"]], "expect": "#eeeeee" },
  { "fn": "readableTextColor", "name": "three candidates, the dark grey wins on yellow", "args": ["#f0e442", ["#ffffff", "#333333", "#0072b2"]], "expect": "#333333" },
  { "fn": "readableTextColor", "name": "no candidates is an error", "args": ["#ffffff", []], "expectError": "candidates must not be empty" }
]