Skip to content

Commit 165e5a1

Browse files
committed
add atcoder contest/tasks/task test
1 parent 4209155 commit 165e5a1

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-0
lines changed
+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`AtCoder contest abc101 1`] = `
4+
Object {
5+
"id": "abc101",
6+
"title": "AtCoder Beginner Contest 101",
7+
"url": "https://atcoder.jp/contests/abc101",
8+
}
9+
`;
10+
11+
exports[`AtCoder contest arc101 1`] = `
12+
Object {
13+
"id": "arc101",
14+
"title": "AtCoder Regular Contest 101",
15+
"url": "https://atcoder.jp/contests/arc101",
16+
}
17+
`;
18+
19+
exports[`AtCoder task abc101 abc101_a 1`] = `
20+
Object {
21+
"id": "abc101_a",
22+
"label": "A",
23+
"title": "Eating Symbols Easy",
24+
"url": "https://atcoder.jp/contests/abc101/tasks/abc101_a",
25+
}
26+
`;
27+
28+
exports[`AtCoder task abc101 abc101_b 1`] = `
29+
Object {
30+
"id": "abc101_b",
31+
"label": "B",
32+
"title": "Digit Sums",
33+
"url": "https://atcoder.jp/contests/abc101/tasks/abc101_b",
34+
}
35+
`;
36+
37+
exports[`AtCoder task arc101 arc101_a 1`] = `
38+
Object {
39+
"id": "arc101_a",
40+
"label": "C",
41+
"title": "Candles",
42+
"url": "https://atcoder.jp/contests/arc101/tasks/arc101_a",
43+
}
44+
`;
45+
46+
exports[`AtCoder tasks abc101 1`] = `
47+
Array [
48+
Object {
49+
"id": "abc101_a",
50+
"label": "A",
51+
"title": "Eating Symbols Easy",
52+
"url": "https://atcoder.jp/contests/abc101/tasks/abc101_a",
53+
},
54+
Object {
55+
"id": "abc101_b",
56+
"label": "B",
57+
"title": "Digit Sums",
58+
"url": "https://atcoder.jp/contests/abc101/tasks/abc101_b",
59+
},
60+
Object {
61+
"id": "arc099_a",
62+
"label": "C",
63+
"title": "Minimization",
64+
"url": "https://atcoder.jp/contests/abc101/tasks/arc099_a",
65+
},
66+
Object {
67+
"id": "arc099_b",
68+
"label": "D",
69+
"title": "Snuke Numbers",
70+
"url": "https://atcoder.jp/contests/abc101/tasks/arc099_b",
71+
},
72+
]
73+
`;
74+
75+
exports[`AtCoder tasks arc101 1`] = `
76+
Array [
77+
Object {
78+
"id": "arc101_a",
79+
"label": "C",
80+
"title": "Candles",
81+
"url": "https://atcoder.jp/contests/arc101/tasks/arc101_a",
82+
},
83+
Object {
84+
"id": "arc101_b",
85+
"label": "D",
86+
"title": "Median of Medians",
87+
"url": "https://atcoder.jp/contests/arc101/tasks/arc101_b",
88+
},
89+
Object {
90+
"id": "arc101_c",
91+
"label": "E",
92+
"title": "Ribbons on Tree",
93+
"url": "https://atcoder.jp/contests/arc101/tasks/arc101_c",
94+
},
95+
Object {
96+
"id": "arc101_d",
97+
"label": "F",
98+
"title": "Robots and Exits",
99+
"url": "https://atcoder.jp/contests/arc101/tasks/arc101_d",
100+
},
101+
]
102+
`;

__tests__/login.ts renamed to __tests__/atcoder.ts

+40
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
jest.useFakeTimers();
12
import {username, password} from "./auth.json";
23
import inquirer from "inquirer";
34
import {AtCoder} from "../src/atcoder";
@@ -34,3 +35,42 @@ test("AtCoder Login", async () => {
3435
expect(await atcoder.login()).toBe(true);
3536
expect(await atcoder.checkSession(true)).toBe(true);
3637
});
38+
39+
describe("AtCoder", async () => {
40+
let atcoder: AtCoder;
41+
beforeEach(async () => {
42+
atcoder = new AtCoder();
43+
// @ts-ignore
44+
inquirer.prompt.mockResolvedValueOnce({username, password});
45+
await atcoder.login();
46+
});
47+
const contests = ["abc101", "arc101"];
48+
describe("contest", async () => {
49+
test.each(contests)("%s", async (contest_id) => {
50+
expect(await atcoder.contest(contest_id)).toMatchSnapshot();
51+
});
52+
test("invalid contest id", async()=>{
53+
await expect(atcoder.contest("abc0xx")).rejects.toThrow();
54+
});
55+
});
56+
describe("tasks", async () => {
57+
test.each(contests)("%s", async (contest_id) => {
58+
expect(await atcoder.tasks(contest_id)).toMatchSnapshot();
59+
});
60+
test("invalid contest id", async()=>{
61+
await expect(atcoder.tasks("abc0xx")).rejects.toThrow();
62+
});
63+
});
64+
const tasks = [["abc101", "abc101_a"], ["abc101", "abc101_b"], ["arc101", "arc101_a"]];
65+
describe("task", async () => {
66+
test.each(tasks)("%s %s", async (contest_id, task_id) => {
67+
expect(await atcoder.task(contest_id, task_id)).toMatchSnapshot();
68+
});
69+
test("invalid contest id", async()=>{
70+
await expect(atcoder.task("abc0xx", "abc0xx_z")).rejects.toThrow();
71+
});
72+
test("invalid task id", async()=>{
73+
await expect(atcoder.task("abc101", "abc102_a")).rejects.toThrow();
74+
});
75+
});
76+
});

0 commit comments

Comments
 (0)