Skip to content

Commit

Permalink
Use the logic gates package
Browse files Browse the repository at this point in the history
  • Loading branch information
w3nl committed Jun 30, 2020
1 parent f558723 commit 29b6749
Show file tree
Hide file tree
Showing 9 changed files with 654 additions and 613 deletions.
2 changes: 1 addition & 1 deletion jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
'^.+\\.cjs?$': 'babel-jest',
},

transformIgnorePatterns: ['/node_modules/'],
transformIgnorePatterns: [],

moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
Expand Down
1,207 changes: 616 additions & 591 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hckrnews/truth-table",
"version": "2.0.0",
"version": "2.1.0",
"description": "",
"main": "src/TruthTable.mjs",
"files": [
Expand Down Expand Up @@ -32,6 +32,7 @@
"@babel/preset-env": "^7.10.3",
"@hckrnews/eslint-config": "^0.2.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.1.0",
"codecov": "^3.6.5",
"coveralls": "^3.0.13",
"eslint": "^6.6.0",
Expand All @@ -43,7 +44,7 @@
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-vue": "^6.2.2",
"jest": "^25.4.0",
"jest": "^26.1.0",
"jscpd": "^3.2.1",
"prettier": "1.19.1"
},
Expand All @@ -58,5 +59,8 @@
"truth",
"table",
"truth table"
]
],
"dependencies": {
"@hckrnews/logic-gates": "^1.0.1"
}
}
8 changes: 6 additions & 2 deletions src/AndTruthTable.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { AndGate } from '@hckrnews/logic-gates';
import TruthTable from './BaseTruthTable.mjs';

class AndTruthTable extends TruthTable {
generateOutput() {
this.output = this.inputs.map(row => row.every(Boolean));
this.result = this.inputs.map(row => [row.every(Boolean), ...row]);
this.output = this.inputs.map(row => AndGate.create(row).output);
this.result = this.inputs.map(row => [
AndGate.create(row).output,
...row,
]);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/NandTruthTable.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { NandGate } from '@hckrnews/logic-gates';
import TruthTable from './BaseTruthTable.mjs';

class NandTruthTable extends TruthTable {
generateOutput() {
this.output = this.inputs.map(row => !row.every(Boolean));
this.result = this.inputs.map(row => [!row.every(Boolean), ...row]);
this.output = this.inputs.map(row => NandGate.create(row).output);
this.result = this.inputs.map(row => [
NandGate.create(row).output,
...row,
]);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/NorTruthTable.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { NorGate } from '@hckrnews/logic-gates';
import TruthTable from './BaseTruthTable.mjs';

class NorTruthTable extends TruthTable {
generateOutput() {
this.output = this.inputs.map(row => !row.some(Boolean));
this.result = this.inputs.map(row => [!row.some(Boolean), ...row]);
this.output = this.inputs.map(row => NorGate.create(row).output);
this.result = this.inputs.map(row => [
NorGate.create(row).output,
...row,
]);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/OrTruthTable.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { OrGate } from '@hckrnews/logic-gates';
import TruthTable from './BaseTruthTable.mjs';

class OrTruthTable extends TruthTable {
generateOutput() {
this.output = this.inputs.map(row => row.some(Boolean));
this.result = this.inputs.map(row => [row.some(Boolean), ...row]);
this.output = this.inputs.map(row => OrGate.create(row).output);
this.result = this.inputs.map(row => [
OrGate.create(row).output,
...row,
]);
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/XnorTruthTable.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { XnorGate } from '@hckrnews/logic-gates';
import TruthTable from './BaseTruthTable.mjs';
import Helper from './Helper';

class XnorTruthTable extends TruthTable {
generateOutput() {
this.output = this.inputs.map(
row => Helper.totalTrueInputs(row) % 2 === 0
);
this.output = this.inputs.map(row => XnorGate.create(row).output);
this.result = this.inputs.map(row => [
Helper.totalTrueInputs(row) % 2 === 0,
XnorGate.create(row).output,
...row,
]);
}
Expand Down
8 changes: 3 additions & 5 deletions src/XorTruthTable.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { XorGate } from '@hckrnews/logic-gates';
import TruthTable from './BaseTruthTable.mjs';
import Helper from './Helper';

class XorTruthTable extends TruthTable {
generateOutput() {
this.output = this.inputs.map(
row => Helper.totalTrueInputs(row) % 2 === 1
);
this.output = this.inputs.map(row => XorGate.create(row).output);
this.result = this.inputs.map(row => [
Helper.totalTrueInputs(row) % 2 === 1,
XorGate.create(row).output,
...row,
]);
}
Expand Down

0 comments on commit 29b6749

Please sign in to comment.