Skip to content

Commit bb8c950

Browse files
committed
Add test case components
1 parent ee43fb4 commit bb8c950

File tree

2 files changed

+98
-2
lines changed

2 files changed

+98
-2
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { Box, styled, Typography } from "@mui/material";
2+
3+
type TestCaseProps = {
4+
input: string;
5+
output: string;
6+
stdout: string;
7+
result: string;
8+
};
9+
10+
const StyledBox = styled(Box)(({ theme }) => ({
11+
margin: theme.spacing(2, 0),
12+
}));
13+
14+
const StyledTypography = styled(Typography)(({ theme }) => ({
15+
background: theme.palette.divider,
16+
padding: theme.spacing(1, 2),
17+
borderRadius: theme.spacing(1),
18+
whiteSpace: "pre-line",
19+
}));
20+
21+
const TestCase: React.FC<TestCaseProps> = ({
22+
input,
23+
output,
24+
stdout,
25+
result,
26+
}) => {
27+
return (
28+
<Box>
29+
<StyledBox sx={(theme) => ({ marginBottom: theme.spacing(2) })}>
30+
<Typography variant="overline">Input</Typography>
31+
<StyledTypography fontFamily={"monospace"}>{input}</StyledTypography>
32+
</StyledBox>
33+
<StyledBox>
34+
<Typography variant="overline">Output</Typography>
35+
<StyledTypography fontFamily={"monospace"}>{output}</StyledTypography>
36+
</StyledBox>
37+
<StyledBox>
38+
<Typography variant="overline">Standard output</Typography>
39+
<StyledTypography fontFamily={"monospace"}>{stdout}</StyledTypography>
40+
</StyledBox>
41+
<StyledBox>
42+
<Typography variant="overline">Result</Typography>
43+
<StyledTypography fontFamily={"monospace"}>{result}</StyledTypography>
44+
</StyledBox>
45+
</Box>
46+
);
47+
};
48+
49+
export default TestCase;

frontend/src/pages/CollabSandbox/index.tsx

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
Grid2,
1111
Tab,
1212
Tabs,
13-
Typography,
1413
} from "@mui/material";
1514
import classes from "./index.module.css";
1615
import { useMatch } from "../../contexts/MatchContext";
@@ -26,6 +25,31 @@ import QuestionDetailComponent from "../../components/QuestionDetail";
2625
import { Navigate } from "react-router-dom";
2726
import Chat from "../../components/Chat";
2827
import TabPanel from "../../components/TabPanel";
28+
import TestCase from "../../components/TestCase";
29+
30+
// hardcode for now...
31+
32+
type TestCase = {
33+
input: string;
34+
output: string;
35+
stdout: string;
36+
result: string;
37+
};
38+
39+
const testcases: TestCase[] = [
40+
{
41+
input: "1 2 3 4",
42+
output: "1 2 3 4",
43+
stdout: "1\n2\n3\n4",
44+
result: "1 2 3 4",
45+
},
46+
{
47+
input: "5 6 7 8",
48+
output: "5 6 7 8",
49+
stdout: "5\n6\n7\n8",
50+
result: "5 6 7 8",
51+
},
52+
];
2953

3054
const CollabSandbox: React.FC = () => {
3155
const [showErrorScreen, setShowErrorScreen] = useState<boolean>(false);
@@ -48,6 +72,7 @@ const CollabSandbox: React.FC = () => {
4872
const [state, dispatch] = useReducer(reducer, initialState);
4973
const { selectedQuestion } = state;
5074
const [selectedTab, setSelectedTab] = useState<"tests" | "chat">("tests");
75+
const [selectedTestcase, setSelectedTestcase] = useState(0);
5176

5277
useEffect(() => {
5378
if (!partner) {
@@ -193,7 +218,29 @@ const CollabSandbox: React.FC = () => {
193218
<Tab label="Chat" value="chat" />
194219
</Tabs>
195220
<TabPanel selected={selectedTab} value="tests">
196-
<Typography>Tests</Typography>
221+
<Box sx={(theme) => ({ margin: theme.spacing(2, 0) })}>
222+
{[...Array(testcases.length)]
223+
.map((_, index) => index + 1)
224+
.map((i) => (
225+
<Button
226+
key={i}
227+
variant="contained"
228+
color={
229+
selectedTestcase === i - 1 ? "primary" : "secondary"
230+
}
231+
onClick={() => setSelectedTestcase(i - 1)}
232+
sx={(theme) => ({ margin: theme.spacing(0, 1) })}
233+
>
234+
Testcase {i}
235+
</Button>
236+
))}
237+
</Box>
238+
<TestCase
239+
input={testcases[selectedTestcase].input}
240+
output={testcases[selectedTestcase].output}
241+
stdout={testcases[selectedTestcase].stdout}
242+
result={testcases[selectedTestcase].result}
243+
/>
197244
</TabPanel>
198245
<TabPanel selected={selectedTab} value="chat">
199246
<Chat isActive={selectedTab === "chat"} />

0 commit comments

Comments
 (0)