Skip to content

Commit

Permalink
Fix electron representations
Browse files Browse the repository at this point in the history
  • Loading branch information
sjd210 committed Dec 11, 2024
1 parent a9d414f commit b3d52c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/models/Chemistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,9 @@ function checkNodesEqual(test: ASTNode, target: ASTNode, response: CheckerRespon
}
}
else if (isElectron(test) && isElectron(target)) {
// There is no need to check electrons, they are always equal
// Electrons have no properties to test equivalence of, but charge must still be aggregated
response.termChargeCount = (response.termChargeCount ?? 0) + 1;

return response;
}
else if (isTerm(test) && isTerm(target)) {
Expand Down
12 changes: 4 additions & 8 deletions src/models/Nuclear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,9 @@ const STARTING_RESPONSE: (options?: ChemistryOptions) => CheckerResponse = (opti

function checkNodesEqual(test: ASTNode, target: ASTNode, response: CheckerResponse): CheckerResponse {
if (isParticle(test) && isParticle(target)) {
// Answers can be entered without a mass or atomic number. However, this is always wrong so we throw an error
if (test.mass === null || test.atomic === null) {
response.containsError = true;
response.error = "Check that all atoms have a mass and atomic number!"
response.isEqual = false;
return response;
}
// Answers can be entered without a mass or atomic number. Some particles e.g. electrons can be validly represented this way so a conversion is made
if (test.mass === null) test.mass = 0;
if (test.atomic === null) test.atomic = 0;

response.validAtomicNumber = (response.validAtomicNumber ?? true) && isValidAtomicNumber(test);
response.sameElements = response.sameElements && checkParticlesEqual(test, target);
Expand All @@ -214,7 +210,7 @@ function checkNodesEqual(test: ASTNode, target: ASTNode, response: CheckerRespon

return response;
} else if (isIsotope(test) && isIsotope(target)) {
// Answers can be entered without a mass or atomic number. However, this is always wrong so we throw an error
// Answers can be entered without a mass or atomic number. However, this is always wrong for isotopes so we throw an error
if (test.mass === null || test.atomic === null) {
response.containsError = true;
response.error = "Check that all atoms have a mass and atomic number!"
Expand Down

0 comments on commit b3d52c8

Please sign in to comment.