Comments (9)
@MrDupin I changed _isOperand
to _is_operand
since camel case is not common in python syntaxing. After fixing the removed paranthesis all UnitTests now pass!
Thank you!!
Launching Nosetest with arguments C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.3.2\helpers\pycharm\_jb_nosetest_runner.py tests.test_data_structure:TestStack.test_stack in C:\Users\doarni\pygorithm
.
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
from pygorithm.
They both work fine for me. I'm using Python 3.5.3 and I installed pygorithm
from pip3 install pygorithm
+ have cloned the repository. I am running python3 -m unittest
from the pygorithm
directory.
Does this occur with the changes you made in #37? Maybe the issue is there.
from pygorithm.
@MrDupin I think the changes I made caused this
from pygorithm.
@MrDupin I've reverted changes in #37 to and test_searching works now. How ever my knowledge of Stacks is essentially none, and test_data_structures is still failing.
The only major change besides removing unnecessary parenthesis in conditionals and modifiying this method __isOperand(char)
# OLD VERSION
return ord(char) >= ord('a') and ord(char) <= ord('z') or ord(char) >= ord('A') and ord(char) <= ord('Z')
# NEW VERISON
return True if ord(char) in [ord(c) for c in list(ascii_letters)] else False
from pygorithm.
The above works for me. This is my _isOperand
function:
def _isOperand(self, char):
from string import ascii_letters
return True if ord(char) in [ord(c) for c in ascii_letters] else False
I removed the conversion of ascii_letters
to a list, since it's not necessary.
What is your error message?
from pygorithm.
@MrDupin The same as the error above
Error
Traceback (most recent call last):
File "C:\Users\doarni\AppData\Local\Continuum\Anaconda3\lib\unittest\case.py", line 58, in testPartExecutor
yield
File "C:\Users\doarni\AppData\Local\Continuum\Anaconda3\lib\unittest\case.py", line 600, in run
testMethod()
File "C:\Users\doarni\Dev\pygorithm\tests\test_data_structure.py", line 39, in test_infix_to_postfix
resultString = result.infix_to_postfix()
File "C:\Users\doarni\Dev\pygorithm\pygorithm\data_structures\stack.py", line 131, in infix_to_postfix
and self.__precedence(self.expression[i] <= self.__precedence(self.my_stack.peek())):
TypeError: unorderable types: str() <= int()
from pygorithm.
The error occurs in the infix_to_postfix
. Can you comment your infix_to_postfix
function? Maybe you converted something that shouldn't have been converted, or vice-versa.
from pygorithm.
def infix_to_postfix(self):
"""
function to generate postfix expression from infix expression
"""
postfix = []
for i in range(len(self.expression)):
if self.__is_operand(self.expression[i]):
postfix.append(self.expression[i])
elif self.expression[i] == '(':
self.my_stack.push(self.expression[i])
elif self.expression[i] == ')':
top_operator = self.my_stack.pop()
while not self.my_stack.is_empty() and top_operator != '(':
postfix.append(top_operator)
top_operator = self.my_stack.pop()
else:
while not self.my_stack.is_empty() \
and self.__precedence(self.expression[i] <= self.__precedence(self.my_stack.peek())):
postfix.append(self.my_stack.pop())
self.my_stack.push(self.expression[i])
while not self.my_stack.is_empty():
postfix.append(self.my_stack.pop())
return ' '.join(postfix)
from pygorithm.
First of all, you accidentally wrote __is_operand
and __precedence
instead of _isOperand
and _precedence
.
Second, you removed a parentheses in self.__precedence(self.expression[i] <= ...
. There should have been a parenthesis before the "<=".
The tests pass now: https://pastebin.com/vH8KdUEu
from pygorithm.
Related Issues (20)
- Some tests are failing
- The `quadtree` code is empty at 1.0.4
- Pygorithms
- Proposal/Ideas of things to add HOT 23
- Geometry
- Error in pygorithm.geometry HOT 4
- ImportError: cannot import name 'data_structures' HOT 4
- Abstract interface for classes HOT 1
- Tests for different versions of Python HOT 2
- Avoiding name conflicts in datastructures HOT 10
- Branches, Deprication HOT 10
- Jupyter Notebooks? HOT 1
- Update readthedocs python version to 3.5 HOT 1
- importing strings package HOT 4
- Updated PYPI Repository w/ latest master branch HOT 1
- Better way to do images? HOT 6
- Syntax error in test.test_geometry HOT 2
- BinaryTree class does not have adding-node functions HOT 2
- Inclusion of International Competition Algorithms & Data Structures HOT 1
- Singly linked list _search is not working, get_next() doesnot exists. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pygorithm.