Skip to content

Commit

Permalink
Merge branch 'main' into improvement/test-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sjd210 committed Nov 26, 2024
2 parents d7491be + 3c0a211 commit 4e52f32
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build-and-test:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn --frozen-lockfile
- run: yarn run build
- run: yarn run test
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,
sameHydrate: true,

Check failure on line 127 in src/models/Chemistry.ts

View workflow job for this annotation

GitHub Actions / build-and-test (20)

An object literal cannot have multiple properties with the same name.
Expand Down Expand Up @@ -427,7 +428,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 @@ -610,7 +611,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 @@ -226,7 +226,7 @@ function checkNodesEqual(test: ASTNode, target: ASTNode, response: CheckerRespon
response.validAtomicNumber = (response.validAtomicNumber ?? true) && isValidAtomicNumber(test) && (response.sameElements ? test.mass === target.mass && test.atomic === target.atomic : true);
response.isEqual = response.isEqual && response.sameElements && response.validAtomicNumber;

// Add the term's nucleon counts to the term's nucleon count
// Add the isotope's nucleon counts to the term's nucleon count
if (response.termNucleonCount) {
response.termNucleonCount = [
response.termNucleonCount[0] + test.atomic,
Expand Down
9 changes: 6 additions & 3 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 Expand Up @@ -128,13 +130,14 @@ export function listComparison<T>(
returnResponse.isEqual = false;

// Attach actual aggregate values
returnResponse.bracketChargeCount = aggregatesResponse.bracketChargeCount;
returnResponse.termChargeCount = aggregatesResponse.termChargeCount;
returnResponse.chargeCount = aggregatesResponse.chargeCount;
returnResponse.bracketAtomCount = aggregatesResponse.bracketAtomCount;
returnResponse.termAtomCount = aggregatesResponse.termAtomCount;
returnResponse.atomCount = aggregatesResponse.atomCount;
if (aggregatesResponse.nucleonCount) {
returnResponse.nucleonCount = aggregatesResponse.nucleonCount;
}
returnResponse.termNucleonCount = aggregatesResponse.termNucleonCount;
returnResponse.nucleonCount = aggregatesResponse.nucleonCount;

return returnResponse;
}
Expand Down

0 comments on commit 4e52f32

Please sign in to comment.