Giter Club home page Giter Club logo

Comments (9)

IanDoarn avatar IanDoarn commented on May 22, 2024 1

@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.

antmarakis avatar antmarakis commented on May 22, 2024

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.

IanDoarn avatar IanDoarn commented on May 22, 2024

@MrDupin I think the changes I made caused this

from pygorithm.

IanDoarn avatar IanDoarn commented on May 22, 2024

@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.

antmarakis avatar antmarakis commented on May 22, 2024

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.

IanDoarn avatar IanDoarn commented on May 22, 2024

@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.

antmarakis avatar antmarakis commented on May 22, 2024

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.

IanDoarn avatar IanDoarn commented on May 22, 2024

@MrDupin

    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.

antmarakis avatar antmarakis commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.