-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the logic gates package and add xand and xnand
- Loading branch information
Showing
17 changed files
with
928 additions
and
613 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { XandGate } from '@hckrnews/logic-gates'; | ||
import TruthTable from './BaseTruthTable.mjs'; | ||
|
||
class XandTruthTable extends TruthTable { | ||
generateOutput() { | ||
this.output = this.inputs.map(row => XandGate.create(row).output); | ||
this.result = this.inputs.map(row => [ | ||
XandGate.create(row).output, | ||
...row, | ||
]); | ||
} | ||
} | ||
|
||
export default XandTruthTable; |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { XnandGate } from '@hckrnews/logic-gates'; | ||
import TruthTable from './BaseTruthTable.mjs'; | ||
|
||
class XnandTruthTable extends TruthTable { | ||
generateOutput() { | ||
this.output = this.inputs.map(row => XnandGate.create(row).output); | ||
this.result = this.inputs.map(row => [ | ||
XnandGate.create(row).output, | ||
...row, | ||
]); | ||
} | ||
} | ||
|
||
export default XnandTruthTable; |
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
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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { XandTruthTable } from '../../src/TruthTable.mjs'; | ||
|
||
const TestCasesResult = [ | ||
{ | ||
description: '1 proposition', | ||
input: 1, | ||
expectedResult: [true, true], | ||
}, | ||
{ | ||
description: '2 propositions', | ||
input: 2, | ||
expectedResult: [true, false, false, true], | ||
}, | ||
{ | ||
description: '3 propositions', | ||
input: 3, | ||
expectedResult: [true, false, false, false, false, false, false, true], | ||
}, | ||
{ | ||
description: '4 propositions', | ||
input: 4, | ||
expectedResult: [ | ||
true, | ||
false, | ||
false, | ||
false, | ||
false, | ||
false, | ||
false, | ||
false, | ||
false, | ||
false, | ||
false, | ||
false, | ||
false, | ||
false, | ||
false, | ||
true, | ||
], | ||
}, | ||
]; | ||
|
||
describe.each(TestCasesResult)( | ||
'Test xand', | ||
({ description, input, expectedResult }) => { | ||
it(description, () => { | ||
const table = XandTruthTable.create(input); | ||
expect(table.output).toMatchObject(expectedResult); | ||
}); | ||
} | ||
); |
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { XandTruthTable } from '../../src/TruthTable.mjs'; | ||
|
||
const TestCasesResult = [ | ||
{ | ||
description: '1 proposition', | ||
input: 1, | ||
expectedResult: [ | ||
[true, false], | ||
[true, true], | ||
], | ||
}, | ||
{ | ||
description: '2 propositions', | ||
input: 2, | ||
expectedResult: [ | ||
[true, false, false], | ||
[false, false, true], | ||
[false, true, false], | ||
[true, true, true], | ||
], | ||
}, | ||
{ | ||
description: '3 propositions', | ||
input: 3, | ||
expectedResult: [ | ||
[true, false, false, false], | ||
[false, false, false, true], | ||
[false, false, true, false], | ||
[false, false, true, true], | ||
[false, true, false, false], | ||
[false, true, false, true], | ||
[false, true, true, false], | ||
[true, true, true, true], | ||
], | ||
}, | ||
{ | ||
description: '4 propositions', | ||
input: 4, | ||
expectedResult: [ | ||
[true, false, false, false, false], | ||
[false, false, false, false, true], | ||
[false, false, false, true, false], | ||
[false, false, false, true, true], | ||
[false, false, true, false, false], | ||
[false, false, true, false, true], | ||
[false, false, true, true, false], | ||
[false, false, true, true, true], | ||
[false, true, false, false, false], | ||
[false, true, false, false, true], | ||
[false, true, false, true, false], | ||
[false, true, false, true, true], | ||
[false, true, true, false, false], | ||
[false, true, true, false, true], | ||
[false, true, true, true, false], | ||
[true, true, true, true, true], | ||
], | ||
}, | ||
]; | ||
|
||
describe.each(TestCasesResult)( | ||
'Test xand with inputs', | ||
({ description, input, expectedResult }) => { | ||
it(description, () => { | ||
const table = XandTruthTable.create(input); | ||
expect(table.result).toMatchObject(expectedResult); | ||
}); | ||
} | ||
); |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { XnandTruthTable } from '../../src/TruthTable.mjs'; | ||
|
||
const TestCasesResult = [ | ||
{ | ||
description: '1 proposition', | ||
input: 1, | ||
expectedResult: [false, false], | ||
}, | ||
{ | ||
description: '2 propositions', | ||
input: 2, | ||
expectedResult: [false, true, true, false], | ||
}, | ||
{ | ||
description: '3 propositions', | ||
input: 3, | ||
expectedResult: [false, true, true, true, true, true, true, false], | ||
}, | ||
{ | ||
description: '4 propositions', | ||
input: 4, | ||
expectedResult: [ | ||
false, | ||
true, | ||
true, | ||
true, | ||
true, | ||
true, | ||
true, | ||
true, | ||
true, | ||
true, | ||
true, | ||
true, | ||
true, | ||
true, | ||
true, | ||
false, | ||
], | ||
}, | ||
]; | ||
|
||
describe.each(TestCasesResult)( | ||
'Test xnand', | ||
({ description, input, expectedResult }) => { | ||
it(description, () => { | ||
const table = XnandTruthTable.create(input); | ||
expect(table.output).toMatchObject(expectedResult); | ||
}); | ||
} | ||
); |
Oops, something went wrong.