Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0a557d7

Browse files
author
luwei
committed
add go unittest by aQuaYi/LeetCode-in-Go
1 parent 1888660 commit 0a557d7

File tree

5 files changed

+141
-0
lines changed

5 files changed

+141
-0
lines changed

.gitignore

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
env/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
parts/
19+
sdist/
20+
var/
21+
*.egg-info/
22+
.installed.cfg
23+
*.egg
24+
25+
# PyInstaller
26+
# Usually these files are written by a python script from a template
27+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
28+
*.manifest
29+
*.spec
30+
31+
# Installer logs
32+
pip-log.txt
33+
pip-delete-this-directory.txt
34+
35+
# Unit test / coverage reports
36+
htmlcov/
37+
.tox/
38+
.coverage
39+
.coverage.*
40+
.cache
41+
nosetests.xml
42+
coverage.xml
43+
*,cover
44+
45+
# Translations
46+
*.mo
47+
*.pot
48+
49+
# Django stuff:
50+
*.log
51+
52+
# Sphinx documentation
53+
docs/_build/
54+
55+
# PyBuilder
56+
target/
57+
58+
js/
59+
60+
records/
61+
62+
.idea

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule ".pkg/LeetCode-in-Go"]
2+
path = .pkg/LeetCode-in-Go
3+
url = https://github.com/aQuaYi/LeetCode-in-Go.git

.pkg/LeetCode-in-Go

Submodule LeetCode-in-Go added at 9dda821

Readme.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
##Usage:
2+
build all unittest: `python3 build.py go_all`
3+
4+
build the keyword of leetcode problem, such as: '1', 'two-sum', 'Two Sum': `python3 build.py go KEYWORD`
5+
6+
7+
##WHY:
8+
We can submit the leetcode code using [leetcode-cli](https://skygragon.github.io/leetcode-cli/commands).
9+
10+
But it not fast enough. Only local unittest, We can enjoy programming.
11+
12+
13+
###DONE:
14+
15+
[x] go
16+
[ ] python
17+
[ ] java
18+
19+
20+
THANKS:
21+
- aQuaYi/LeetCode-in-Go
22+
23+
24+

build.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import os
4+
import os.path
5+
import re
6+
7+
from shutil import copyfile
8+
9+
10+
class Go:
11+
src_path = '.pkg/LeetCode-in-Go/Algorithms'
12+
dst_path = 'go'
13+
file_match = re.compile(".*_test.go|readme.md")
14+
15+
def build(self, keyword):
16+
17+
if isinstance(keyword, int) or keyword.isdigit():
18+
path_match = re.compile("{0:04d}.*".format(int(keyword)))
19+
else:
20+
path_match = re.compile("\d+.*{}.*".format(keyword))
21+
for p in os.listdir(self.src_path):
22+
if path_match.match(p):
23+
self.copy_test(p)
24+
25+
def copy_test(self, p: str):
26+
parent = os.path.join(self.src_path, p)
27+
if not os.path.isdir(parent):
28+
return
29+
for filename in os.listdir(parent):
30+
src = os.path.join(parent, filename)
31+
dst_parent = os.path.join(self.dst_path, p)
32+
dst = os.path.join(dst_parent, filename)
33+
if self.file_match.match(filename.lower()) and os.path.isfile(src):
34+
if not os.path.exists(dst_parent):
35+
os.mkdir(dst_parent)
36+
copyfile(src, dst)
37+
38+
39+
def go(keyword: str):
40+
"""创建"""
41+
Go().build(keyword)
42+
43+
44+
def go_all():
45+
Go().build("")
46+
47+
48+
if __name__ == '__main__':
49+
from fire import Fire
50+
51+
Fire()

0 commit comments

Comments
 (0)