Skip to content

Commit

Permalink
Merge pull request #8 from isaacphysics/improvement/test-updates
Browse files Browse the repository at this point in the history
Add and update tests for Chemistry Checker
  • Loading branch information
mwtrew authored Dec 18, 2024
2 parents a9d414f + 2c83aa6 commit e9856cb
Show file tree
Hide file tree
Showing 5 changed files with 594 additions and 338 deletions.
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

0 comments on commit e9856cb

Please sign in to comment.