definitions = [
	{
		"name": "lib.string_coin",
		"procedure": lambda input_: string_coin(input_["template"], input_["arguments"]),
		"cases": [
			{
				"input": {
					"template": "{{sachen}} sind {{farbe}}",
					"arguments": {
						"farbe": "rot",
					},
				},
				"output": "{{sachen}} sind rot"
			},
			{
				"input": {
					"template": "{{sachen}} sind {{farbe}}",
					"arguments": {
					},
				},
				"output": "{{sachen}} sind {{farbe}}"
			},
			{
				"input": {
					"template": "{{sachen}} sind {{farbe}}",
					"arguments": {
						"sachen": "rosen",
						"farbe": "rot",
					},
				},
				"output": "rosen sind rot"
			},
			{
				"input": {
					"template": "{{sachen}} sind {{farbe}}",
					"arguments": {
						"sachen": "rosen",
						"farbe": "rot",
						"ort": "frankreich",
					},
				},
				"output": "rosen sind rot"
			},
		],
	},
	{
		"name": "lib.format_bytes",
		"procedure": lambda input_: format_bytes(input_),
		"cases": [
			{
				"input": 999,
				"output": "999 B",
			},
			{
				"input": 1000,
				"output": "1.0 KB",
			},
			{
				"input": 1000000,
				"output": "1.0 MB",
			},
			{
				"input": 1000000000,
				"output": "1.0 GB",
			},
			{
				"input": 1000000000000,
				"output": "1.0 TB",
			},
			{
				"input": 1000000000000000,
				"output": "1.0 PB",
			},
			{
				"input": 1000000000000000000,
				"output": "1000.0 PB",
			},
		],
	},
]


for definition in definitions:
	fails = 0
	for index in range(len(definition["cases"])):
		case = definition["cases"][index]
		output_actual = definition["procedure"](case["input"])
		output_expected = case["output"]
		passed = (output_actual == output_expected)
		fails += (0 if passed else 1)
		info = {
			"input": case["input"],
			"output_expected": output_expected,
			"output_actual": output_actual,
		}
		_sys.stderr.write(
			"[%s] %s.%u%s\n"
			% (
				("+" if passed else "x"),
				definition["name"],
				index,
				("" if passed else (": " + _json.dumps(info))),
			)
		)
_sys.exit(1 if (fails > 0) else 0)
