Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Oct 31, 2024
1 parent e5dd054 commit 4a3befb
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions docs/source/atoms/color.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Supported style are:


-----------------------------
Custom color for each specie
Custom color for each species
-----------------------------
Use can set custom color for each specie. The color can be in the form of hex code or color name.
Use can set custom color for each species. The color can be in the form of hex code or color name.


.. code-block:: javascript
Expand Down
5 changes: 4 additions & 1 deletion src/atoms/AtomsViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,10 @@ class AtomsViewer {
addAtom(element, position = { x: 0, y: 0, z: 0 }) {
// Remove the selected atoms from the scene and data
const atom = new Atom(element, [position.x, position.y, position.z]);
this.atoms.addSpecie(element);
// if element is not in the species, add it to the species
if (!this.atoms.species[element]) {
this.atoms.addSpecie(element);
}
this.atoms.addAtom(atom);
// this.logger.debug("atoms: ", this.atoms);

Expand Down
1 change: 0 additions & 1 deletion src/atoms/atoms.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ class Atoms {
...this.attributes["specie"][name],
};
}
return result;
}

multiply(mx, my, mz) {
Expand Down
26 changes: 12 additions & 14 deletions tests/atoms.test.mjs
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
import { Species, Atom, Atoms } from "../dist/weas.mjs";
import { Specie, Atom, Atoms } from "../dist/weas.mjs";

describe("Species class", () => {
it("creates a new Species instance correctly", () => {
const species = new Species("C1", "C");
expect(species.symbol).toBe("C1");
describe("Specie class", () => {
it("creates a new Specie instance correctly", () => {
const species = new Specie("C");
expect(species.element).toBe("C");
expect(species.number).toBe(6);
});
it("creates a new Species use only symbol", () => {
const species = new Species("C");
expect(species.symbol).toBe("C");
it("creates a new Specie use only symbol", () => {
const species = new Specie("C");
expect(species.element).toBe("C");
expect(species.number).toBe(6);
});
it("throws an error when adding an unknown species", () => {
const value = "Unknown";
expect(() => {
const species = new Species("Unknown"); // This species does not exist in the atoms instance
}).toThrowError(`Element '${value}' is wrong.`);
const species = new Specie("Unknown"); // This species does not exist in the atoms instance
}).toThrowError(`Element '${value}' is invalid.`);
});
});

describe("Atom class", () => {
it("creates a new Atom instance correctly", () => {
const species = "H"; // Assuming this refers to an existing species
const symbol = "H"; // Assuming this refers to an existing symbol
const position = [1.0, 2.0, 3.0];
const atom = new Atom(species, position);
expect(atom.species).toBe(species);
const atom = new Atom(symbol, position);
expect(atom.symbol).toBe(symbol);
expect(atom.position).toEqual(position);
});
});
Expand All @@ -53,7 +51,7 @@ describe("Atoms class", () => {
it("adds a species correctly", () => {
atoms.addSpecie("H");
expect(atoms.species).toHaveProperty("H");
expect(atoms.species["H"]).toEqual(new Species("H"));
expect(atoms.species["H"]).toEqual(new Specie("H"));
});

// Add more tests for other methods like setCell, addAtom, removeAtom, etc.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions tests/parserXYZ.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseXYZ, Species } from "../dist/weas.mjs";
import { parseXYZ, Specie } from "../dist/weas.mjs";

describe("parseXYZ", () => {
it("parses valid XYZ data correctly", () => {
Expand All @@ -15,8 +15,8 @@ H 0.000000 0.757160 0.482080
expect(atoms).toBeDefined();
expect(atoms.species).toHaveProperty("H");
expect(atoms.species).toHaveProperty("O");
expect(atoms.species["H"]).toEqual(new Species("H"));
expect(atoms.species["O"]).toEqual(new Species("O"));
expect(atoms.species["H"]).toEqual(new Specie("H"));
expect(atoms.species["O"]).toEqual(new Specie("O"));
expect(atoms.positions.length).toBe(3);
expect(atoms.symbols).toEqual(["O", "H", "H"]);
console.log(atoms.positions[0]);
Expand Down

0 comments on commit 4a3befb

Please sign in to comment.