针对卫生部发布的新冠肺炎诊测指南,基于决策表方法实现测试,用JavaScript代码编写
时间: 2024-02-29 17:57:26 浏览: 53
以下是基于决策表方法实现测试的JavaScript代码:
```javascript
function checkCOVID19(symptoms, history) {
let isCOVID19 = false;
// 决策表
if (symptoms.includes("fever") && symptoms.includes("dry cough") && (history.includes("Wuhan") || history.includes("close contact"))) {
isCOVID19 = true;
}
return isCOVID19;
}
// 测试用例
console.log(checkCOVID19(["fever", "dry cough"], "I traveled to Wuhan last month and had close contact with someone who later tested positive for COVID-19.")); // true
console.log(checkCOVID19(["headache", "nausea"], "I stayed at home all week and didn't go out.")); // false
console.log(checkCOVID19(["fever", "loss of taste or smell"], "I visited Beijing last month.")); // false
console.log(checkCOVID19(["fever", "dry cough", "fatigue", "loss of taste or smell"], "I traveled to Wuhan last month and had close contact with someone who later tested positive for COVID-19.")); // true
```
该代码实现了一个 `checkCOVID19` 函数,该函数接受两个参数:症状列表 `symptoms` 和流行病学史 `history`。如果症状和流行病学史符合新冠肺炎诊断要求,则返回 `true`,否则返回 `false`。函数内部使用决策表方法进行判断。最后,代码提供了四个测试用例,用于验证 `checkCOVID19` 函数的正确性。