-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yves Ulrich Tittes
committed
Oct 21, 2024
1 parent
7b47fe5
commit 586d86d
Showing
2 changed files
with
29 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,47 @@ | ||
// Currently only covers converToSI | ||
import { convertToSI } from './utils'; | ||
import { createUnit, Unit } from 'mathjs'; | ||
import { convertToSI } from "./utils"; | ||
|
||
|
||
describe('convertToSI', () => { | ||
it('should convert a known unit to SI successfully', () => { | ||
const result = convertToSI(1, 'cm'); | ||
describe("convertToSI", () => { | ||
it("should convert a known unit to SI successfully", () => { | ||
const result = convertToSI(1, "cm"); | ||
expect(result.valueSI).toBeCloseTo(0.01); | ||
expect(result.unitSI).toEqual('m'); | ||
expect(result.unitSI).toEqual("m"); | ||
}); | ||
|
||
it('should convert angstrom to SI successfully', () => { | ||
const result = convertToSI(1, 'Å'); | ||
it("should convert angstrom to SI successfully", () => { | ||
const result = convertToSI(1, "Å"); | ||
expect(result.valueSI).toBeCloseTo(1e-10); | ||
expect(result.unitSI).toEqual('m'); | ||
expect(result.unitSI).toEqual("m"); | ||
}); | ||
|
||
it('should handle different versions of Å in unicode', () => { | ||
const inputUnit = '\u212B'; // Old unicode representation of "Å", is not boolean equal to the one we added. | ||
it("should handle different versions of Å in unicode", () => { | ||
const inputUnit = "\u212B"; // Old unicode representation of "Å", is not boolean equal to the one we added. | ||
const result = convertToSI(1, inputUnit); | ||
expect(result.valueSI).toBeCloseTo(1e-10); | ||
expect(result.unitSI).toEqual('m'); | ||
expect(result.unitSI).toEqual("m"); | ||
}); | ||
|
||
it('should return the input value and unit if conversion fails', () => { | ||
const result = convertToSI(1, 'invalidUnit'); | ||
it("should return the input value and unit if conversion fails", () => { | ||
const result = convertToSI(1, "invalidUnit"); | ||
expect(result.valueSI).toEqual(1); | ||
expect(result.unitSI).toEqual('invalidUnit'); | ||
expect(result.unitSI).toEqual("invalidUnit"); | ||
}); | ||
|
||
it('should convert SI units correctly', () => { | ||
const result = convertToSI(1000, 'g'); | ||
it("should convert SI units correctly", () => { | ||
const result = convertToSI(1000, "g"); | ||
expect(result.valueSI).toBeCloseTo(1); | ||
expect(result.unitSI).toEqual('kg'); | ||
expect(result.unitSI).toEqual("kg"); | ||
}); | ||
|
||
it('should handle already normalized units', () => { | ||
const result = convertToSI(1, 'm'); | ||
it("should handle already normalized units", () => { | ||
const result = convertToSI(1, "m"); | ||
expect(result.valueSI).toEqual(1); | ||
expect(result.unitSI).toEqual('m'); | ||
expect(result.unitSI).toEqual("m"); | ||
}); | ||
|
||
it('should handle negative values properly', () => { | ||
const result = convertToSI(-5, 'cm'); | ||
it("should handle negative values properly", () => { | ||
const result = convertToSI(-5, "cm"); | ||
expect(result.valueSI).toBeCloseTo(-0.05); | ||
expect(result.unitSI).toEqual('m'); | ||
expect(result.unitSI).toEqual("m"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters