Skip to content
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

Multiple tests written under single test name. #154

Closed
HarsheetKakar opened this issue Mar 15, 2020 · 8 comments · Fixed by #163
Closed

Multiple tests written under single test name. #154

HarsheetKakar opened this issue Mar 15, 2020 · 8 comments · Fixed by #163

Comments

@HarsheetKakar
Copy link
Contributor

Description of the problem

generally one module has one test which has all of the tests implemented in it.

Example of the problem

def test_Queue():

    q1 = Queue(implementation='array', items=[0])
    q1.append(1)
    q1.append(2)
    q1.append(3)

    q1 = Queue(implementation='linked_list')
    q1.append(1)
    assert raises(TypeError, lambda: Queue(implementation='linked_list', items={0, 1}))
    q1 = Queue(implementation='linked_list', items = [0, 1])
    q1.append(2)
    q1.append(3)

This can be changed to

test_Queue():
   <tests for Queue abstract class>

test_ArrayQueue():
   <tests for ArrayQueue class>

test_LinkedListQueue():
    <tests for LinkedListQueue class>

This will increase readability, and maintaining tests would be easier.

@HarsheetKakar
Copy link
Contributor Author

image
from here also, if I just want to test ArrayQueue I cant, it will run all the tests for Queue module.

@czgdp1807
Copy link
Member

This can be changed to

test_Queue():
   <tests for Queue abstract class>

test_ArrayQueue():
   <tests for ArrayQueue class>

test_LinkedListQueue():
    <tests for LinkedListQueue class>

This will increase readability, and maintaining tests would be easier.

Looks like a nice idea.

@czgdp1807
Copy link
Member

I think this can be done for stacks as well.

@HarsheetKakar
Copy link
Contributor Author

shall I make a different PR?

@czgdp1807
Copy link
Member

Yeah, I would recommend to do that. #152 is ready to merge and will be merge soon.

@HarsheetKakar
Copy link
Contributor Author

string in ArrayStack is:
assert str(s) == '[1, 2, 3]'

and string in LinkedListStack is:
assert str(s) == '[3, 2, 1]'

which of them is better representation of a stack?

@czgdp1807
Copy link
Member

string in ArrayStack is:
assert str(s) == '[1, 2, 3]'

and string in LinkedListStack is:
assert str(s) == '[3, 2, 1]'

As LinkedListStack modify the left side of stack and ArrayStack modify the right side, both outputs are different. It doesn't matter how they are stored in memory but at least the printing should be consistent. We should follow the representation as used in ArrayStack, so the LinkedListStack should be reversed before it is printed. Modification in LinkedListStack.__str__ method is needed.
In addition, LinkedListStack.top should be removed. and LinkedListStack.peek should return self.stack.head rather than self.stack.head.data.

@HarsheetKakar
Copy link
Contributor Author

understood

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants