Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(module): add new notations module for science #2415

Open
wants to merge 16 commits into
base: next
Choose a base branch
from
Open
7 changes: 6 additions & 1 deletion src/definitions/science.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ChemicalElement, Unit } from '../modules/science';
import type { ChemicalElement, Notation, Unit } from '../modules/science';
import type { LocaleEntry } from './definitions';

/**
Expand All @@ -14,4 +14,9 @@
* Some periodic table element information.
*/
chemicalElement: ReadonlyArray<ChemicalElement>;

/**
* Some science notations
*/
notation: ReadonlyArray<Notation>;

Check warning on line 21 in src/definitions/science.ts

View check run for this annotation

Codecov / codecov/patch

src/definitions/science.ts#L17-L21

Added lines #L17 - L21 were not covered by tests
}>;
2 changes: 2 additions & 0 deletions src/locales/en/science/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
*/
import type { ScienceDefinition } from '../../..';
import chemicalElement from './chemicalElement';
import notation from './notation';
import unit from './unit';

const science: ScienceDefinition = {
chemicalElement,
notation,
unit,
};

Expand Down
50 changes: 50 additions & 0 deletions src/locales/en/science/notation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
export default Object.freeze([
{
symbol: 'W',
name: 'work',
},
{
symbol: 'F',
name: 'force',
},
{
name: 'gravity',
symbol: 'G',
},
{
name: 'friction force',
symbol: 'f',
},
{
name: 'pressure',
symbol: 'P',
},
{
name: 'power',
symbol: 'P',
},
{
name: 'heat capacity',
symbol: 'c',
},
{
name: 'square',
symbol: 'S',
},
{
name: 'time',
symbol: 't',
},
{
name: 'velocity',
symbol: 'v',
},
{
name: 'volume',
symbol: 'V',
},
{
name: 'mass',
symbol: 'm',
},
]);
26 changes: 26 additions & 0 deletions src/modules/science/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ export interface Unit {
symbol: string;
}

export interface Notation {
/**
* The long version of the notations (e.g. `work`).
*/
name: string;
/**
* The short version/abbreviation of the notations (e.g. `w`)
*/
symbol: string;
}
/**
* Module to generate science related entries.
*
Expand Down Expand Up @@ -66,4 +76,20 @@ export class ScienceModule extends ModuleBase {
unit(): Unit {
return this.faker.helpers.arrayElement(this.faker.definitions.science.unit);
}

/**
* Retunrs a ransom scientific notation.
*
* @example
* faker.science.notation() // { name: 'work', symbol: 'w' }
* faker.science.notation() // { name: 'force', symbol: 'F' }
* faker.science.notation() // { name: 'work', symbol: 'W'}
*
* @since 8.2.0
*/
notation(): Notation {
return this.faker.helpers.arrayElement(
this.faker.definitions.science.notation
);
}
}
21 changes: 21 additions & 0 deletions test/modules/__snapshots__/science.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ exports[`science > 42 > chemicalElement 1`] = `
}
`;

exports[`science > 42 > notation 1`] = `
{
"name": "pressure",
"symbol": "P",
}
`;

exports[`science > 42 > unit 1`] = `
{
"name": "pascal",
Expand All @@ -23,6 +30,13 @@ exports[`science > 1211 > chemicalElement 1`] = `
}
`;

exports[`science > 1211 > notation 1`] = `
{
"name": "mass",
"symbol": "m",
}
`;

exports[`science > 1211 > unit 1`] = `
{
"name": "henry",
Expand All @@ -38,6 +52,13 @@ exports[`science > 1337 > chemicalElement 1`] = `
}
`;

exports[`science > 1337 > notation 1`] = `
{
"name": "friction force",
"symbol": "f",
}
`;

exports[`science > 1337 > unit 1`] = `
{
"name": "radian",
Expand Down
2 changes: 1 addition & 1 deletion test/modules/science.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const NON_SEEDED_BASED_RUN = 5;

describe('science', () => {
seededTests(faker, 'science', (t) => {
t.itEach('chemicalElement', 'unit');
t.itEach('chemicalElement', 'unit', 'notation');
});

// Create and log-back the seed for debug purposes
Expand Down
Loading