From e000febcf5cbd7ef26fc38d5534e207bd8152654 Mon Sep 17 00:00:00 2001 From: Isara Naranirattisai Date: Mon, 16 Oct 2017 15:54:02 +0700 Subject: [PATCH] play with some lab and add test file :) --- .gitignore | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 7 +++ lab1_1.py | 4 +- lab1_2.py | 5 +- lab2_2.py | 21 ++++++- test.py | 15 +++++ 6 files changed, 205 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100644 test.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3bb87ca --- /dev/null +++ b/.gitignore @@ -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/ \ No newline at end of file diff --git a/README.md b/README.md index 488c047..da7d267 100644 --- a/README.md +++ b/README.md @@ -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 +``` \ No newline at end of file diff --git a/lab1_1.py b/lab1_1.py index 98e8720..2fe50ca 100644 --- a/lab1_1.py +++ b/lab1_1.py @@ -5,4 +5,6 @@ def factorial(n): return num raise NotImplementedError() -print(factorial(9)) \ No newline at end of file +factorial2 = lambda x: x * factorial2(x - 1) if x else 1 + +# print(factorial(9)) \ No newline at end of file diff --git a/lab1_2.py b/lab1_2.py index 8e78774..9fd1f8a 100644 --- a/lab1_2.py +++ b/lab1_2.py @@ -6,4 +6,7 @@ def multiples_of_3_and_5(n): return num raise NotImplementedError() -print(multiples_of_3_and_5(10)) \ No newline at end of file +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)) \ No newline at end of file diff --git a/lab2_2.py b/lab2_2.py index 461f073..23fc483 100644 --- a/lab2_2.py +++ b/lab2_2.py @@ -1,4 +1,5 @@ -order = str(input('Enter : ')) +# order = str(input('Enter : ')) +order = "{}" LEFT_BRACKET = ('[','{','(') RIGHT_BRACKET = (']','}',')') @@ -25,7 +26,7 @@ def match(bracket,next_bracket): bracket = left_bracket_stack.pop() if match(bracket,char): pass - else: + else: err = True break @@ -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] \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..8e4b6c4 --- /dev/null +++ b/test.py @@ -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]