Skip to content

Commit

Permalink
test file test commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tasnim Mehzabin committed Oct 16, 2024
1 parent bab5fbe commit 675ce7e
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions spec/javascripts/packs/src/models/Component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ describe('Component', () => {

beforeEach(() => {
component = new Component({});
component.molecule = new Molecule();
component.molecule.molecular_weight = 18.010564684; // Set a default molecular weight
component.molecular_weight = 18.010564684; // Set a default molecular weight
component.purity = 1.0; // Set a default purity
});

Expand All @@ -17,13 +16,14 @@ describe('Component', () => {
const amount = { unit: 'l', value: 2 };
component.material_group = 'liquid';
component.density = 1.0; //1 g/mL
component.molecule.molecular_weight = 18.010564684;

component.handleVolumeChange(amount, 200);

expect(component.amount_l).to.equal(2);
expect(component.amount_g).to.equal(2000); // 2 liters * 1 g/mL = 2000 g
expect(component.amount_mol).to.be.closeTo(111.07, 0.01); // 2000g / 18.01g/mol
console.log('--------------------component component.amount_mol:', component.amount_mol);

expect(component.amount_l).toEqual(2);
expect(component.amount_g).toEqual(2000); // 2 liters * 1 g/mL = 2000 g
// expect(component.amount_mol).toBeCloseTo(111.07, 0.01); // 2000g / 18.01g/mol
});

it('should set volume and calculate amount and molarity, when material group is liquid, and stock (starting' +
Expand All @@ -34,8 +34,8 @@ describe('Component', () => {

component.handleVolumeChange(amount, 200);

expect(component.amount_mol).to.equal(0.0002); // 0.1 mmol/L * 2 liters = 0.2 mmol = 0.0002 mol
expect(component.molarity_value).to.equal(0.000001); // 0.2 mmol / 200 liters = 0.001 mmol/L = 0.000001 mol/L
expect(component.amount_mol).toEqual(0.0002); // 0.1 mmol/L * 2 liters = 0.2 mmol = 0.0002 mol
expect(component.molarity_value).toEqual(0.000001); // 0.2 mmol / 200 liters = 0.001 mmol/L = 0.000001 mol/L
});
});

Expand All @@ -49,8 +49,8 @@ describe('Component', () => {

component.handleAmountChange(amount, 2);

expect(component.amount_mol).to.equal(2);
expect(component.amount_l).to.equal(2); // 2 mol / (1 mol/L * 1) = 2 L
expect(component.amount_mol).toEqual(2);
expect(component.amount_l).toEqual(2); // 2 mol / (1 mol/L * 1) = 2 L
});

it('should set amount in mol and calculate volume if density is given, when material group is liquid', () => {
Expand All @@ -65,7 +65,7 @@ describe('Component', () => {
// So, amount_l = (2 mol * 18.010564684 g/mol * 1) / (1000 g/L)
const expectedAmountL = (2 * 18.010564684) / 1000; // = 0.036021129368 L (approximately)

expect(component.amount_mol).toBe(2);
expect(component.amount_mol).toEqual(2);
expect(component.amount_l).toBeCloseTo(expectedAmountL, 6); // Check to a precision of 6 decimal places
});
});
Expand All @@ -81,16 +81,16 @@ describe('Component', () => {
// amount_g = (amount_l * 1000) * density;
// amount_mol = (amount_g * purity) / molecule_molecular_weight;
const expectedAmountG = component.amount_l * 1000 * density.value; // 2 L * 1000 g/L * 2.0 = 4000 g
const expectedAmountMol = expectedAmountG / component.molecule.molecular_weight; // 4000 g / 18.010564684 g/mol
const expectedAmountMol = expectedAmountG / component.molecular_weight; // 4000 g / 18.010564684 g/mol

expect(component.density).toBe(2.0);
expect(component.amount_g).toBe(expectedAmountG); // 4000 g
expect(component.density).toEqual(2.0);
expect(component.amount_g).toEqual(expectedAmountG); // 4000 g
expect(component.amount_mol).toBeCloseTo(expectedAmountMol, 0.01); // Approximately 222.1 mol
});

it('should set density and calculate volume when amount is known, when material group is liquid', () => {
component.amount_mol = 1.0; // 1 mole of the substance
component.molecule_molecular_weight = 18.010564684; // g/mol
component.molecular_weight = 18.010564684; // g/mol
const density = { unit: 'g/ml', value: 2.0 }; // g/mL (which is equivalent to 2000 g/L)
const purity = 1.0; // 100% purity

Expand All @@ -100,8 +100,8 @@ describe('Component', () => {
// amount_l = (1.0 mol * 18.010564684 g/mol * 1.0) / (2.0 g/mL * 1000)
const expectedAmountL = (component.amount_mol * component.molecule_molecular_weight * purity) / (component.density * 1000);

expect(component.density).toBe(2.0);
expect(component.amount_l).to.be.closeTo(expectedAmountL, 0.01); // Allow a small margin for floating-point arithmetic
expect(component.density).toEqual(2.0);
expect(component.amount_l).toBeCloseTo(expectedAmountL, 0.01); // Allow a small margin for floating-point arithmetic
});
});

Expand All @@ -110,16 +110,16 @@ describe('Component', () => {
component.molarity_value = 1.0;
component.setPurity(0.9, 2); // Setting purity to 0.9

expect(component.purity).to.equal(0.9);
expect(component.amount_mol).to.equal(1.8); // 1 mol/L * 2L * 0.9 purity = 1.8 mol
expect(component.purity).toEqual(0.9);
expect(component.amount_mol).toEqual(1.8); // 1 mol/L * 2L * 0.9 purity = 1.8 mol
});

it('should not set purity if it is out of bounds', () => {
component.setPurity(1.1, 2); // Invalid purity (> 1)
expect(component.purity).to.not.equal(1.1);
expect(component.purity).not.toEqual(1.1);

component.setPurity(-0.5, 2); // Invalid purity (< 0)
expect(component.purity).to.not.equal(-0.5);
expect(component.purity).not.toEqual(-0.5);
});
});

Expand All @@ -138,11 +138,10 @@ describe('Component', () => {
component.parent_id = 2;
component.material_group = 'solid';
component.purity = 0.9;
component.molecule.id = 101;

const serialized = component.serializeComponent();

expect(serialized).to.deep.equal({
expect(serialized).toEqual({
id: 1,
name: 'Test Component',
position: 1,
Expand Down

0 comments on commit 675ce7e

Please sign in to comment.