-
-
Notifications
You must be signed in to change notification settings - Fork 408
feat: add Linked Queue #88
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks good! A couple things:
- The tests are practically identical (if not, they should be, since both queues should implement the same implicit "interface"). Please avoid duplicating them. Can you try:
- Adding a
Queue
Interface - Parameterizing the tests for this interface in terms of the Queue implementation
- De-duplicating the
Queue
tests using this parameterized version
- Adding a
- Terminology-wise nitpick: I'd just call this a
LinkedQueue
.LinkedlistQueue
violates CamelCase, andLinkedListQueue
seems odd (is it a linked list, a queue, or both?). - Formatting-wise, please check your comments for typos and grammar mistakes. Many are also missing a space after the
//
; the comments at the start are pretty oddly formatted, please clean them up using JSDoc.
thanks for the feedback. Working on that! |
did you mean I should not duplicate the Queue test? if yes I don't think it will be possible since they have different names. |
It is tricky but definitely possible. Here's a simple example for a fictive generic "Box" container type: interface Box<T> {
peek(): T
}
// These two classes are deliberately identical.
class BoxA<T> implements Box<T> {
content: T
constructor(content: T) {
this.content = content
}
peek(): T {
return this.content
}
}
class BoxB<T> implements Box<T> {
content: T
constructor(content: T) {
this.content = content
}
peek(): T {
return this.content
}
}
// Test function parameterized in terms of the class
type BoxConstructor = new<T>(content: T) => Box<T>
function test(Box: BoxConstructor) {
const content = 42
const c = new Box<number>(content)
// This is just for a simple example that works in `ts-node`;
// you'd instead use Jest's `expect(...).toBe(...)` here.
if (c.peek() != content)
throw new Error("test failed")
}
test(BoxA)
test(BoxB) In terms of files, I'd like it split up as follows:
Ideally, the tests would have the same structure:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be going in the right direction. Please don't duplicate the Queue
interface, but rather export it from a queue.ts
file which both implementations import
.
is everything ok now? |
Not quite: The tests still need to be deduplicated as I have described. |
can you please check this out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Only minor things left:
- Please lowercase
Queue.test.ts
toqueue.test.ts
to follow our naming conventions; - Please remove leaading and trailing newlines
I'm confused with the leading and trailing newlines can you please show me an example? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution!
You are welcome! I have learnt a lot from you |
*added linkedlist Queue implementation
*added a test to the implementation( I used the tests from array queue implementation but tweak to make the tests uniform on the site)
*updated the Directory.md