0
function calculatePrice(base_cost, base_dist, additional_cost, additional_dist, total_dist) {
if (total_dist > base_dist) {
} else {
return base_cost;
}
}
function unitTest() {
var cost;
cost = calculatePrice(10,20,5,5,15);
if (cost != 10) console.log ("FAILED 1");
cost = calculatePrice(10,10,5,5,15);
if (cost != 15) console.log ("FAILED 2");
cost = calculatePrice(20,10,5,1,15);
if (cost != 45) console.log ("FAILED 3");
cost = calculatePrice(20,10,5,1,1);
if (cost != 20) console.log ("FAILED 4");
cost = calculatePrice(10,10,5,1,14);
if (cost != 30) console.log ("FAILED 5");
cost = calculatePrice(10,10,5,2,14);
if (cost != 20) console.log ("FAILED 6");
console.log('Test complete');
}
나는 전달할 unitTest의 함수 값을 계산하려고합니다 .1을 전달하고 calculatePrice 함수에 일부 패스 코드를 작성해야합니다. 감사Javascript 단위 함수 매개 변수로 테스트하기
조금 더 설명해 주시겠습니까 –
unitTest 함수의 모든 비용 값을 전달하고 싶습니다. – cyberoot
unitTest를 전달하기위한 calcutePrice 함수를 작성해야합니다. – cyberoot