Skip to content

Commit

Permalink
Merge pull request #9 from isaacphysics/hotfix/change-equality-to-nul…
Browse files Browse the repository at this point in the history
…lish-check

Set sameHydrate to true by default
  • Loading branch information
jsharkey13 authored Nov 26, 2024
2 parents 43f6235 + 799d5f1 commit 3c0a211
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/models/Chemistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const STARTING_RESPONSE: (options?: ChemistryOptions, coefficientScalingValue?:
isEqual: true,
typeMismatch: false,
sameCoefficient: true,
sameHydrate: true,
sameElements: true,
sameState: true,
sameCharge: true,
Expand Down Expand Up @@ -426,7 +427,7 @@ function checkNodesEqual(test: ASTNode, target: ASTNode, response: CheckerRespon
const comparator = (test: [Molecule, number], target: [Molecule, number], response: CheckerResponse): CheckerResponse => {
const newResponse = checkNodesEqual(test[0], target[0], response);
newResponse.sameCharge = newResponse.sameCharge && test[1] === target[1];
newResponse.isEqual = newResponse.isEqual && (newResponse.sameCharge === true);
newResponse.isEqual = newResponse.isEqual && (newResponse.sameCharge ?? true);

if (!test[0].bracketed) {
// If not bracketed, add the charge directly to the chargeCount of the term
Expand Down Expand Up @@ -609,7 +610,7 @@ export function check(test: ChemAST, target: ChemAST, options: ChemistryOptions)

let newResponse = checkNodesEqual(test.result, target.result, response);
// We set flags for these properties in checkNodesEqual, but we only apply the isEqual check here due to listComparison
newResponse.isEqual = newResponse.isEqual && newResponse.sameCoefficient && (newResponse.sameState === true) && (newResponse.sameBrackets === true) && (newResponse.sameHydrate === true);
newResponse.isEqual = newResponse.isEqual && newResponse.sameCoefficient && (newResponse.sameState ?? true) && (newResponse.sameBrackets ?? true) && (newResponse.sameHydrate ?? true);

if (!newResponse.options?.keepAggregates) {
newResponse = removeAggregates(newResponse);
Expand Down
2 changes: 1 addition & 1 deletion 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
2 changes: 2 additions & 0 deletions src/models/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export function mergeResponses(response1: CheckerResponse, response2: CheckerRes
newResponse.sameCoefficient = response1.sameCoefficient && response2.sameCoefficient;
newResponse.sameElements = response1.sameElements && response2.sameElements;
if (!response1.isNuclear) {
newResponse.sameCharge = response1.sameCharge && response2.sameCharge;
newResponse.sameHydrate = response1.sameHydrate && response2.sameHydrate;
newResponse.sameState = response1.sameState && response2.sameState;
newResponse.sameBrackets = response1.sameBrackets && response2.sameBrackets;
} else {
Expand Down

0 comments on commit 3c0a211

Please sign in to comment.