Skip to content

Commit afe8f7a

Browse files
authored
Merge pull request #44 from atcoder/patch/expander
Add tests for expander
2 parents e666c35 + d113abc commit afe8f7a

File tree

7 files changed

+172
-1
lines changed

7 files changed

+172
-1
lines changed

.github/workflows/expander.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Expander test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
expander:
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
matrix:
10+
os: [ubuntu-latest, windows-latest]
11+
python-version: [3.6]
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Set up Python ${{ matrix.python-version }}
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: ${{ matrix.python-version }}
18+
- name: Set up pytest
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install pytest
22+
- name: Run test_expander.py
23+
run: pytest

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ build
22

33
*.html
44
!tools/*.html
5-
tools/ac-library.zip
5+
tools/ac-library.zip
6+
__pycache__

test/expander/comment_out.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// #include <atcoder/dsu>
2+
/* #include <atcoder/dsu> */
3+
/* #include <atcoder/dsu>
4+
*/
5+
6+
namespace atcoder {
7+
struct dsu {
8+
9+
};
10+
}
11+
12+
int main() {
13+
}

test/expander/include_all.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <atcoder/all>
2+
#include <cstdio>
3+
4+
using namespace std;
5+
using namespace atcoder;
6+
7+
int main() {
8+
int n, q;
9+
scanf("%d %d", &n, &q);
10+
11+
dsu uf(n);
12+
for (int i = 0; i < q; i++) {
13+
int t, u, v;
14+
scanf("%d %d %d", &t, &u, &v);
15+
if (t == 0) {
16+
// merge
17+
uf.merge(u, v);
18+
} else {
19+
// find
20+
if (uf.same(u, v)) {
21+
printf("1\n");
22+
} else {
23+
printf("0\n");
24+
}
25+
}
26+
}
27+
}

test/expander/include_unionfind.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <atcoder/dsu>
2+
#include <cstdio>
3+
4+
using namespace std;
5+
using namespace atcoder;
6+
7+
int main() {
8+
int n, q;
9+
scanf("%d %d", &n, &q);
10+
11+
dsu uf(n);
12+
for (int i = 0; i < q; i++) {
13+
int t, u, v;
14+
scanf("%d %d %d", &t, &u, &v);
15+
if (t == 0) {
16+
// merge
17+
uf.merge(u, v);
18+
} else {
19+
// find
20+
if (uf.same(u, v)) {
21+
printf("1\n");
22+
} else {
23+
printf("0\n");
24+
}
25+
}
26+
}
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <atcoder/dsu>
2+
#include <atcoder/dsu>
3+
#include <cstdio>
4+
5+
using namespace std;
6+
using namespace atcoder;
7+
8+
int main() {
9+
int n, q;
10+
scanf("%d %d", &n, &q);
11+
12+
dsu uf(n);
13+
for (int i = 0; i < q; i++) {
14+
int t, u, v;
15+
scanf("%d %d %d", &t, &u, &v);
16+
if (t == 0) {
17+
// merge
18+
uf.merge(u, v);
19+
} else {
20+
// find
21+
if (uf.same(u, v)) {
22+
printf("1\n");
23+
} else {
24+
printf("0\n");
25+
}
26+
}
27+
}
28+
}

test/test_expander.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
3+
import unittest
4+
from logging import Logger, basicConfig, getLogger
5+
from os import getenv, environ
6+
from pathlib import Path
7+
from shutil import copy
8+
from subprocess import run
9+
from tempfile import TemporaryDirectory
10+
from typing import List
11+
12+
logger = getLogger(__name__) # type: Logger
13+
14+
15+
class Test(unittest.TestCase):
16+
def compile_test(self, source: Path, env=None):
17+
if not env:
18+
env = environ.copy()
19+
lib_dir = Path.cwd().resolve()
20+
expander_path = Path('expander.py').resolve()
21+
with TemporaryDirectory() as new_dir:
22+
tmp = Path(new_dir)
23+
proc = run(['python', str(expander_path), str(
24+
source.resolve()), '--lib', str(lib_dir)], cwd=str(tmp), env=env)
25+
self.assertEqual(proc.returncode, 0)
26+
proc = run(['g++', 'combined.cpp', '-std=c++14'], cwd=str(tmp))
27+
self.assertEqual(proc.returncode, 0)
28+
29+
def test_unionfind(self):
30+
self.compile_test(Path('test/expander/include_unionfind.cpp'))
31+
32+
def test_unusual_format(self):
33+
self.compile_test(Path('test/expander/include_unusual_format.cpp'))
34+
35+
def test_all(self):
36+
self.compile_test(Path('test/expander/include_all.cpp'))
37+
38+
def test_comment_out(self):
39+
self.compile_test(Path('test/expander/comment_out.cpp'))
40+
41+
def test_env_value(self):
42+
env = environ.copy()
43+
env['CPLUS_INCLUDE_PATH'] = str(Path.cwd().resolve())
44+
self.compile_test(Path('test/expander/include_all.cpp'), env=env)
45+
46+
47+
if __name__ == "__main__":
48+
basicConfig(
49+
level=getenv('LOG_LEVEL', 'DEBUG'),
50+
format="%(asctime)s %(levelname)s %(name)s : %(message)s"
51+
)
52+
unittest.main()

0 commit comments

Comments
 (0)