-
Notifications
You must be signed in to change notification settings - Fork 10
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
finished validation issue number:240 #281
base: master
Are you sure you want to change the base?
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.
First, please install prettier in visual studio code, so that when you save the file it will be formatted to the style set for this project. It makes it easier to review changes.
Then, if you npm run test
there will be many test failures. And you can npm run test dturn
and it will run fewer tests and that might help.
We need to make all tests pass.
I looked into this one: npm run test app/dturn/tests/rank-statements.js
The problem in that insertStatementIds is failing with
console.error
User user0 is not part of discussion testRankingDiscussion
For insertStatementId we need to allow new users. This is how users join the deliberation, by adding a statement to it.
Please fix this one, and see what else comes up. There may be things we need to discuss, I don't know.
We may have to make some changes to the tests, or we may have to reconsider the validation checks, but in the end all the tests need to pass.
Thanks.
OK, I will solve this problem at first. |
Test ResultsinsertStatementId
getStatementIds
putGroupings
rankMostImportant
Here are some test results pictures |
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 is looking good and I'm so glad all the dturn tests are passing. Beside the comments inline, there's still a problem with the formatting. I see all these semicolons at the end of lines. We aren't using those in this project. If you install prettier into vscode it will automatically format everything on save and we won't have to worry about it. https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode (or find it for whatever editor you are using).
expect(statements).toBeDefined() | ||
expect(statements.length).toBe(10) | ||
expect(statements.length).toBeGreaterThanOrEqual(2) |
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.
statements.length must be 10 -- or Options.group_size. If it's not then lets discuss.
for (let i = 0; i < 20; i++) { | ||
props.push([DISCUSSION_ID, `user${i}`, `statement${i}`]) | ||
|
||
console.log("After initDiscussion:", JSON.stringify(Discussions[DISCUSSION_ID], null, 2)); |
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.
please remove the console.log statements since you have it working.
app/dturn/dturn.js
Outdated
shownCount: 0, | ||
rank: 0, | ||
if (!Discussions[discussionId].Uitems[userId]) { | ||
console.log(`User ${userId} is new, adding to discussion ${discussionId}`); |
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.
please remove console.log statements.
app/dturn/dturn.js
Outdated
return undefined; | ||
} | ||
|
||
// 确保 `statementId` 存在于 `ShownStatements` |
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.
comments are good, but please make them in english.
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, I will pay attention to this
dis.ShownStatements[round][cutoff].rank > dis.min_rank ? dis.ShownStatements[round][cutoff].rank : dis.min_rank | ||
const cutoff = Math.ceil(dis.ShownStatements[round].length / dis.group_size); | ||
const minRank = Math.max(dis.ShownStatements[round][cutoff].rank, dis.min_rank); | ||
|
||
if (delta > 0) { | ||
if (sitem.rank >= minRank) { | ||
if (!dis.ShownStatements[round + 1].some(s => s.statementId === sitem.statementId)) { |
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.
please put back the 2 lines of comments
app/dturn/tests/dturn.js
Outdated
// Tests | ||
test('Succeed if all options are valid.', async () => { | ||
initDiscussion(DISCUSSION_ID, { group_size: 15 }) | ||
}) | ||
|
||
test('Fail if all options are not valid.', async () => { | ||
const func = async () => { | ||
await initDiscussion(DISCUSSION_ID, { a_nonexistent_option: 12345 }) | ||
} | ||
expect(func()).rejects.toThrow(nonexistentOptionErrorRegex) | ||
}) | ||
|
||
test('Fail if at least 1 option is not valid.', async () => { | ||
const func = async () => { | ||
await initDiscussion(DISCUSSION_ID, { group_size: 10, a_nonexistent_option: 12345 }) | ||
} | ||
expect(func()).rejects.toThrow(nonexistentOptionErrorRegex) | ||
}) |
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.
These tests seem to be missing?
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.
Yes, these cases have already been covered in other test cases.
app/dturn/tests/dturn.js
Outdated
Object.keys(Discussions).forEach(key => delete Discussions[key]); | ||
|
||
// Initialize a test discussion with required properties | ||
Discussions.testDiscussion = { |
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.
We should try to use initDiscussion rather than directly manipulating it.
Hi David. I already fixed these format problem. I downloaded prettier and make the format is the same with out codebase. |
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 is going really well, and I see some good changes to dturn.js. I know it's hard working in other peoples code, and this code is especially complicated.
While all of the dturn tests pass, it turns out there are a few others when I do npm run test that don't pass.
npm run test app/socket-apis/__tests__/complete-round.js app/socket-apis/__tests__/post-point-groupings.js app/socket-apis/__tests__/get-points-for-round.js
In one case I see getStatementIds is returning [] instead of undefined, so dturn needs to be fixed for that.
For some of the others, it may be that the test needs to be fixed. Can you look at them, and see what you can do, but if it's gets too deep then I can take a turn figuring them out.
Also, I pushed some changes, so you will need to git pull
in this branch. I put back some comments that were taken out, that are still valuable. What I learned is that comments about why a piece of code is there are the most valuable. I also changed the other throw's .to cosole.errors. When code is being used in api calls, throws leave the api call incomplete. I know I'm the one that put the throws there. But since I was in there it was time to get rid of them.
Have a look through this commit to see what I changed: deeb271
expect(statements).toBeDefined() | ||
expect(statements.length).toBe(10) | ||
|
||
console.log('Retrieved statements:', statements) |
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.
okay, now that this code is working isn't it time to take the console.log statements out.
package.json
Outdated
@@ -71,6 +71,7 @@ | |||
"@babel/preset-react": "^7.16.0", | |||
"@svgr/cli": "^8.1.0", | |||
"babel-loader": "^8.2.3", | |||
"prettier": "3.5.2", |
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.
Was prettier required to get it working in vscode? -- are you using vs code or something else?
I don't want to have prettier as a dependency if we don't have to. But if that was required then lets do it. But can you uninstall prettier and see if it's working in your editor?
Also, if it is required it should be in optionalDependencies. You have to put it there manually in the editor. When we push to production on heroku, devDependencies are installed and build and used to build the repo. optionalDependencies are not installed in order to save space and build time.
|
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.
-
Okay, I think there was a misunderstanding about how to handle the tests failing. It is the design intent that getStatementIds returns undefined rather than [] when there are no statements to work on. If undefined is returned sometimes, and [] other times, then the code has to test for if(!ids || !ids.length) where as if it just returns undefines, then the test is just if(!ids). Can you please change it the other way. And FYI - there's another test.
node app/dturn/test.js
which runs there a big loop of putting stuff in to a discussion, and then validating it. I don't have it in jest because it takes a long time to run. -
Please look through the changes in the PR Files Changed and put back the comments that were taken out. Some of them may not be appropriate anymore, but many of them are and comments are hard to get.
-
please do
git checkout origin/master package.json
andgit checkout origin/master package-lock.json
. The changes to those files aren't relevant to this issue.
throw new Error( | ||
`getStatments unexpected number of statments ${JSON.stringify(dis.Uitems?.[userId]?.[round], null, 2)}` | ||
) | ||
return sIds.length > 0 ? sIds : [] |
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 is a long way of saying return sIds
- please shorten.
@@ -336,7 +345,7 @@ async function getStatementIds(discussionId, round, userId) { | |||
|
|||
await dis.updateUInfo(delta) | |||
|
|||
return statementIds | |||
return statementIds.length > 0 ? statementIds : [] |
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.
here is another case where it's the long way of saying return statementIds
No description provided.