Skip to content

Commit

Permalink
update: automatically adjust number of materials in the test
Browse files Browse the repository at this point in the history
  • Loading branch information
VsevolodX committed Nov 27, 2024
1 parent fd6fccd commit 70c6e83
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tests/js/material.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { expect } from "chai";
import * as fs from "fs";
import * as yaml from "js-yaml";

import h_BN from "../../materials/BN-[Hexagonal_Boron_Nitride]-HEX_[P6%2Fmmm]_2D_[Monolayer]-[2dm-4991].json";
import Graphene from "../../materials/C-[Graphene]-HEX_[P6%2Fmmm]_2D_[Monolayer]-[2dm-3993].json";
Expand All @@ -7,7 +9,20 @@ import Si from "../../materials/Si-[Silicon]-FCC_[Fd-3m]_3D_[Bulk]-[mp-149].json
import WS2 from "../../materials/WS2-[Tungsten_Disulfide]-HEX_[P-6m2]_2D_[Monolayer]-[2dm-3749].json";
import { MaterialStandata } from "../../src/js";

const TOTAL_NUMBER_OF_MATERIALS = 30;
function countEntitiesInYAML(filePath: string, entityKey: string): number {
try {
const fileContents = fs.readFileSync(filePath, "utf8");
const data = yaml.load(fileContents) as { [key: string]: any[] };
return data[entityKey]?.length || 0;
} catch (e) {
console.error(e);
return 0;
}
}

const materialsCategoriesFilePath = "materials/categories.yml";
const TOTAL_NUMBER_OF_MATERIALS = countEntitiesInYAML(materialsCategoriesFilePath, "entities");
console.log(`Total number of materials: ${TOTAL_NUMBER_OF_MATERIALS}`);

describe("Materials Standata", () => {
it("can return the list of all materials", () => {
Expand Down

0 comments on commit 70c6e83

Please sign in to comment.