From 70c6e83727b93ba1df063dd167f8e0ea8165b75c Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Wed, 27 Nov 2024 12:42:21 -0800 Subject: [PATCH] update: automatically adjust number of materials in the test --- tests/js/material.test.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/js/material.test.ts b/tests/js/material.test.ts index c440da2..624411d 100644 --- a/tests/js/material.test.ts +++ b/tests/js/material.test.ts @@ -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"; @@ -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", () => {