Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LiveCode] 컴파일-테스트케이스 로직 재구성 필요 #2

Open
wjdwl002 opened this issue Feb 12, 2023 · 0 comments
Open

[LiveCode] 컴파일-테스트케이스 로직 재구성 필요 #2

wjdwl002 opened this issue Feb 12, 2023 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@wjdwl002
Copy link
Member

뭔가 안에서 로직이 꼬였는지, 각 테스트케이스에 대한 컴파일 결과가 제대로 매칭되지않음

const useCompile = () => {
const [, setToastObj] = useRecoilState(toastMsgState);
const testCaseList = useRecoilValue(testCaseState);
const [, setTestCaseResultList] = useRecoilState(testCaseResultState);
const handleCompileResult = (res: any, testCaseList: ITestCase[]) => {
const data = res;
console.log(data);
console.log("testCaseList", testCaseList);
const newList = testCaseList.map((e: ITestCase) => ({
output: e.output,
testCaseId: e.testCaseId,
}));
const testCaseResultList = newList.map((e: any) => {
if (e.testCaseId == data.testCaseId) {
console.log("data", e, data);
return data.output === e.output
? { ...e, time: data.time, success: true }
: { ...e, time: data.time, success: false };
}
else return e
});
console.log(newList, testCaseResultList);
setTestCaseResultList(testCaseResultList);
};
const { isLoading, error, sendRequest } = usePost(
{ url: "/api/compile" },
handleCompileResult
);
const stompClient = useContext(WebSocketContext);
const userInfo = useRecoilValue(userInfoState);
const onCompile = ({ code }: PropType) => {
const inputList = testCaseList.map((e) => e?.input);
if (!code || code.length == 0) {
setToastObj({ show: true, msg: "코드를 입력하세요." });
} else if (!inputList || inputList.length == 0) {
setToastObj({ show: true, msg: "테스트케이스를 등록하세요." });
} else {
// sendRequest({
// code,
// inputs: inputList,
// });
// stompClient.connect({}, () => {
stompClient.send(
`/pub/compile/${userInfo.workspaceId}`,
JSON.stringify({ code: code })
);
// });
}
};
useEffect(() => {
if (stompClient.connected)
stompClient.subscribe(
`/sub/compile/${userInfo.workspaceId}`,
async (res: any) => {
const data = await JSON.parse(res.body);
handleCompileResult(data, testCaseList);
}
);
}, [stompClient.connected, testCaseList]);
return { isLoading, error, onCompile };
};

컴파일시 각 테스트케이스에 대한 컴파일 정보가 아래와 같은 형식으로 내려오는데, 적절히 변환해서 테스트케이스의 기대 output과 실제 output이 맞으면 성공, 다르면 실패로 데이터를 전처리해서 보여줄 필요가 있음.

{ 
	"testCaseId": "cd89da31-2fea-4bce-b9e3-a5036bb2be78",
	"output": "output", // 테스트케이스의 실행 결과
	"time": 23 // ms 단위
}

이때, 아직 등록되지 않은(편집중인) 테스트케이스나 이미 삭제한 테스트케이스 등 다양한 경우의 수를 고려해주어야함.

@wjdwl002 wjdwl002 added bug Something isn't working good first issue Good for newcomers labels Feb 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant