Skip to content

Commit

Permalink
also add simple functions for logic gates
Browse files Browse the repository at this point in the history
  • Loading branch information
w3nl committed Jul 1, 2020
1 parent 4bb4816 commit 4b240b0
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hckrnews/logic-gates",
"version": "1.0.3",
"version": "2.0.0",
"description": "Generate logic gates without thinking.",
"main": "src/LogicGates.mjs",
"files": [
Expand Down
3 changes: 3 additions & 0 deletions src/AndGate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ class AndGate extends Gate {
}
}

const and = input => AndGate.create(input).output;

export default AndGate;
export { AndGate, and };
6 changes: 4 additions & 2 deletions src/LogicGates.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Gate from './Gate.mjs';
import AndGate from './AndGate.mjs';
import NandGate from './NandGate.mjs';
import { AndGate, and } from './AndGate.mjs';
import { NandGate, nand } from './NandGate.mjs';
import OrGate from './OrGate.mjs';
import NorGate from './NorGate.mjs';
import XorGate from './XorGate.mjs';
Expand All @@ -12,7 +12,9 @@ import NotGate from './NotGate.mjs';
export default Gate;
export {
AndGate,
and,
NandGate,
nand,
OrGate,
NorGate,
XorGate,
Expand Down
3 changes: 3 additions & 0 deletions src/NandGate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ class NandGate extends Gate {
}
}

const nand = input => NandGate.create(input).output;

export default NandGate;
export { NandGate, nand };
12 changes: 10 additions & 2 deletions tests/unit/and.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AndGate } from '../../src/LogicGates.mjs';
import { AndGate, and } from '../../src/LogicGates.mjs';

const TestCases = [
{
Expand Down Expand Up @@ -53,11 +53,19 @@ const TestCases = [
},
];

describe.each(TestCases)('Test and', ({ description, expectedResult }) => {
describe.each(TestCases)('Test AndGate', ({ description, expectedResult }) => {
it(description, () => {
expectedResult.forEach(inputTest => {
const table = AndGate.create(inputTest[0]);
expect(table.output).toBe(inputTest[1]);
});
});
});

describe.each(TestCases)('Test and', ({ description, expectedResult }) => {
it(description, () => {
expectedResult.forEach(inputTest => {
expect(and(inputTest[0])).toBe(inputTest[1]);
});
});
});
12 changes: 10 additions & 2 deletions tests/unit/nand.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NandGate } from '../../src/LogicGates.mjs';
import { NandGate, nand } from '../../src/LogicGates.mjs';

const TestCases = [
{
Expand Down Expand Up @@ -53,11 +53,19 @@ const TestCases = [
},
];

describe.each(TestCases)('Test nand', ({ description, expectedResult }) => {
describe.each(TestCases)('Test NandGate', ({ description, expectedResult }) => {
it(description, () => {
expectedResult.forEach(inputTest => {
const table = NandGate.create(inputTest[0]);
expect(table.output).toBe(inputTest[1]);
});
});
});

describe.each(TestCases)('Test nand', ({ description, expectedResult }) => {
it(description, () => {
expectedResult.forEach(inputTest => {
expect(nand(inputTest[0])).toBe(inputTest[1]);
});
});
});

0 comments on commit 4b240b0

Please sign in to comment.