| import re | |
| def is_decimal(s): | |
| try: | |
| a = float(s) | |
| except: | |
| return False | |
| return bool(re.match(r"^-?\d+\.\d+$", s)) | |
| def test_output_comparison(output_string, expected_stdout): | |
| if isinstance(output_string, float): | |
| output_string = str(output_string) | |
| expected_lines = [line.strip() for line in output_string.splitlines()] | |
| actual_lines = [line.strip() for line in expected_stdout.splitlines()] | |
| # 移除空行 | |
| expected_lines = [line for line in expected_lines if line] | |
| actual_lines = [line for line in actual_lines if line] | |
| # ## 合并为一行 | |
| actual_lines = (" ".join(actual_lines)).strip() | |
| expected_lines = (" ".join(expected_lines)).strip() | |
| # ## 小数保留 6 位 | |
| if is_decimal(actual_lines) and is_decimal(expected_lines): | |
| if abs(float(actual_lines) - float(expected_lines)) > 1e-6: | |
| return False | |
| if actual_lines != expected_lines: | |
| return False | |
| # 比较 | |
| if actual_lines == expected_lines: | |
| return True | |
| return False |
Xet Storage Details
- Size:
- 1.07 kB
- Xet hash:
- fdc518c24bde65170b0b3d31ac0533429ab429cc994708d4f66a2f1074b0b2ac
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.