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

Add and update tests for Chemistry Checker #8

Merged
merged 15 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/models/Chemistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ export function check(test: ChemAST, target: ChemAST, options: ChemistryOptions)
response.expectedType = target.result.type;
response.receivedType = test.result.type;

if (isEqual(test.result, target.result) && !options.keepAggregates) {
if (!options.keepAggregates && isEqual(test.result, target.result)) {
return response;
}

Expand Down
9 changes: 5 additions & 4 deletions src/models/Nuclear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function checkNodesEqual(test: ASTNode, target: ASTNode, response: CheckerRespon
return response;
}

response.validAtomicNumber = (response.validAtomicNumber ?? true) && isValidAtomicNumber(test);
response.validAtomicNumber = (response.validAtomicNumber === true) && isValidAtomicNumber(test);
response.sameElements = response.sameElements && checkParticlesEqual(test, target);
response.isEqual = response.isEqual && response.sameElements && response.validAtomicNumber;

Expand Down Expand Up @@ -283,6 +283,7 @@ function checkNodesEqual(test: ASTNode, target: ASTNode, response: CheckerRespon
// Merge the responses so that the final response contains all the information
const finalResponse = mergeResponses(leftResponse, rightResponse);


// Nuclear question balance is determined by atom/mass count equality
finalResponse.balancedAtom = leftResponse.nucleonCount && rightResponse.nucleonCount ?
leftResponse.nucleonCount[0] === rightResponse.nucleonCount[0] : false;
Expand All @@ -308,12 +309,12 @@ function checkNodesEqual(test: ASTNode, target: ASTNode, response: CheckerRespon
}
}

export function check(test: NuclearAST, target: NuclearAST): CheckerResponse {
const response = STARTING_RESPONSE();
export function check(test: NuclearAST, target: NuclearAST, options: ChemistryOptions): CheckerResponse {
const response = STARTING_RESPONSE(options);
response.expectedType = target.result.type;
response.receivedType = test.result.type;

if (isEqual(test.result, target.result)) {
if (!options.keepAggregates && isEqual(test.result, target.result)) {
return response;
}

Expand Down
2 changes: 1 addition & 1 deletion src/routes/Nuclear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ router.post('/check', checkValidationRules, (req: Request, res: Response) => {

const target: NuclearAST = augment(parseNuclearExpression(req.body.target)[0]);
const test: NuclearAST = augment(parseNuclearExpression(req.body.test)[0]);
const result: CheckerResponse = check(test, target);
const result: CheckerResponse = check(test, target, {});

res.status(201).send(result);

Expand Down
Loading
Loading