Help with Priority Queue Challenge on BETA site

Help with Priority Queue Challenge on BETA site
0

#1

So let’s assume I have written the correct code for the function named PriorityQueue
in the Create a Priority Queue Class challenge

If I made the following statements after defining the function, what should it return?

var test = new PriorityQueue();
test.enqueue(['taco',1]);
test.enqueue(['kitten',0]);
test.enqueue(['dog',0]);
test.enqueue(['apple',0]);
test.enqueue(['whale',1]);
test.printCollection();

I may be misinterpreting the challenge description, but I thought it should return the following array:

[ [ 'kitten', 0 ], [ 'dog', 0 ], [ 'apple', 0 ], [ 'taco', 1 ], [ 'whale', 1 ] ]

Because the challenge does not tell me what test assertion I failed should return, I have been trying to figure out if the test is buggy or my code is wrong. Is there a way to look at the assertions for each test in the browser?

Or better yet, whoever is creating the tests for this particular challenge, can it be modified to show the “should return” part like the regular Free Code Camp site?

Thanks,

Randy


#2

Haven’t done the challenge yet, but I think the output should be:

[ [ 'taco', 1 ], [ 'whale', 1 ][ 'kitten', 0 ], [ 'dog', 0 ], [ 'apple', 0 ] ]

So first high priority in order of enqueue'ing and then low priority also in order.


#3

According to the challenge description 0 is a higher priority than 1, so 0’s come before 1’s because higher priority items leave the queue first (left to right).


#4

Should have read it better…

Which tests do you fail?


#5

the last one, but I don’t know what they are feeding into the test.


#6

This is super annoying. Just spend a hour trying this and then decided to see if I could find the tests. Well here they are: https://github.com/freeCodeCamp/freeCodeCamp/blob/staging/seed/challenges/08-coding-interview-questions-and-take-home-assignments/coding-interview-data-structure-questions.json

The last test expects the dequeue function to return the value of the item you remove. So if the first item = [“item”, 1], it expects you to return “item”. Also, the test doesn’t actually check if you implement the priority correctly. So this line: this.collection.push(arr); is enough for enqueue.


#7

So it sounds like they need to rewrite the test description and also check to make sure the enqueue works differently than just this.collection.push.(arr). Now it makes a lot more sense why I failed the last test. My dequeue was return [‘item’, 1] instead of ‘item’. I would have eventually figured that out I suppose if the test description would have reflected it.

I am going to report the tests as written incorrectly.

Thanks for finding the tests. I feel much better about my solution. Here are the 4 test group statements:

//test #1
var test = new PriorityQueue();
test.enqueue(['David Brown', 2]);
test.enqueue(['Jon Snow', 1]);
//test #2
var test = new PriorityQueue();
test.enqueue(['David Brown', 2]);
test.enqueue(['Jon Snow', 1]);
test.dequeue(); 
//test #3
var test = new PriorityQueue();
test.enqueue(['David Brown', 2]);
test.enqueue(['Jon Snow', 1]);
test.dequeue();
test.dequeue();
//test #4
var test = new PriorityQueue();
test.enqueue(['David Brown', 1]);
test.enqueue(['Jon Snow', 1]);

@BenGitter Do you think my original assumption would be correct regarding my example and what should show after printing the collection?


#8

Yes, the output you gave, should be correct.


#9

Hey I don’t know if you’ve opened an issue for this yet or not! I helped write some of these challenges and I know several of them need a lot of work still. I’m happy to work on this one based on the discussion here.

I just took a look at this now, this is definitely one of the ones that needed a lot more work.

I just made an Issue for this.


#10

@rmdawson71 & @BenGitter I just made a PR to improve this challenge it should be in better shape now.

If you happen to run into any other problems on the advanced data structures please let me know before spending too much time on them — like I mentioned above several of these challenges do still need work.


#11

I reviewed the changes to the tests you made on Gitbhub. How long before those changes are pushed to the BETA challenge? Also, I think it would be helpful to state some where in the test results section what is enqued and dequed on that last test in case someone fails it, so they understand what is actually expected vs just saying “The priority queue should return items with a higher priority before items with a lower priority and return items in first-in-first-out order otherwise.”

Below is example of how to make the error message more clear for the camper:

The following statements: var test = new PriorityQueue(); test.enqueue(['taco',1]); test.enqueue(['kitten',0]); test.enqueue(['dog',0]); test.enqueue(['apple',0]); test.enqueue(['whale',1]); test.printCollection();
should return the following array: 
[ [ 'kitten', 0 ], [ 'dog', 0 ], [ 'apple', 0 ], [ 'taco', 1 ], [ 'whale', 1 ] ]

This would make it more like the traditional challenges in the Basic, Intermediate, and Advanced algorithm sections. Just my suggestion.

How would I go about learning more about helping create the tests for challenges? I would like to write the test cases like you have been doing. There are a couple of bugs on the BETA challenges site which I reported a while back (over a month ago that would seem easy to resolve by modifying the test). Someone was assigned back then, but they have not made the changes yet.


#12

Thanks!

So the challenge did slightly change right? From priority = 0 (high) and everything else (low) to having nearly infinite amount of priority levels (every number is its own priority level)?

Will see if I can complete it once the changes are pushed to the beta site. Does it happen after every PR.


#13

I agree with you! I was aware of that regarding the last test and so I tried to make it clear in the instructions that the dequeue method should return the item itself, i.e. 'dog', 'apple', etc. and not the priority. However, your point about the format of the test is a good one. At the moment I think the vast majority of the tests in this advanced section are not formated like that however.

Regarding when this will be updated in Beta, first the PR would need to be merged (as of now it isn’t yet) and second someone (probably Berkeley) would need to update the Beta site with the current staging branch (this doesn’t happen after every PR but I think updates have been coming through frequently enough).

If you are interested in helping to write some of the test cases for these or any of the challenges, I’d be happy to help you. It’s not that difficult to do, all the challenges and tests are in large json files so you essentially just have to modify those. Getting more people interested in working on these would be great because there is still a lot of work and fine-tuning needed.


#14

I made a note in my other comment just now about when updates to Beta are made.

I did change how the priority worked, I thought just having two options (0 and 1) was somewhat constraining and less realistic. But the idea is the same, just having integer values representing a priority level and priority always overrides placement order.