Skip to content

play with some lab and add test file :) #1

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
__pycache__/*
*.pyc

.idea/
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries

# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle:
.idea/**/gradle.xml
.idea/**/libraries

# CMake
cmake-build-debug/

# Mongo Explorer plugin:
.idea/**/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
.static_storage/
.media/
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@
#For Practicing my datastructure&algorithm class in Computer Engineering ,KMITL

And It's open-sources eiei


## Testing
```bash
$ python3 -m pip install pytest
$ pytest -q test.py
```
4 changes: 3 additions & 1 deletion lab1_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ def factorial(n):
return num
raise NotImplementedError()

print(factorial(9))
factorial2 = lambda x: x * factorial2(x - 1) if x else 1

# print(factorial(9))
5 changes: 4 additions & 1 deletion lab1_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ def multiples_of_3_and_5(n):
return num
raise NotImplementedError()

print(multiples_of_3_and_5(10))
def multiples_of_3_and_5_new(n):
return sum([i for i in range(10) if i%3 == 0 or i%5 == 0])

# print(multiples_of_3_and_5(10))
21 changes: 19 additions & 2 deletions lab2_2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
order = str(input('Enter : '))
# order = str(input('Enter : '))
order = "{}"

LEFT_BRACKET = ('[','{','(')
RIGHT_BRACKET = (']','}',')')
Expand All @@ -25,7 +26,7 @@ def match(bracket,next_bracket):
bracket = left_bracket_stack.pop()
if match(bracket,char):
pass
else:
else:
err = True
break

Expand All @@ -37,3 +38,19 @@ def match(bracket,next_bracket):
else:
print('MATCH')


def matcher2(expression):
tmp = []
pList = ['(', '[', '{', ')', ']', "}"]
pureP = ''.join([i for i in expression if i in pList])
for c in pureP:
if(pList.index(c) < 3):
tmp.append(c)
elif pList[pList.index(c)-3] == tmp[-1]:
tmp.pop()
else:
return False
return tmp == []

def matcher2List(expressionList):
return [matcher2(expression) for expression in expressionList]
15 changes: 15 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from lab1_1 import *
from lab1_2 import *
from lab2_2 import *

def test_lab1_1():
assert factorial(9) == 362880
assert factorial2(9) == 362880

def test_lab1_1():
assert multiples_of_3_and_5(10) == 23
assert multiples_of_3_and_5_new(10) ==23

def test_lab2_2():
orders = ["( a+b-c *[d+e]/{f*(g+h) }", " [ ( a+b-c }*[d+e]/{f*(g+h) }", " ( 3 + 2 ) / { 4**5 }"]
assert matcher2List(orders) == [False, False, True]