This repository has been archived by the owner on Jan 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
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
1 parent
c83949d
commit 12260cf
Showing
7 changed files
with
1,167 additions
and
263 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import { setup } from '../../src/setup' | ||
setup() | ||
import Multiplexer from '../../src/modules/Multiplexer' | ||
import Demultiplexer from '../../src/modules/Demultiplexer' | ||
import Input from '../../src/modules/Input' | ||
import { update, updateSimulationSet } from '../../src/engine' | ||
|
||
/* | ||
* Multiplexer test | ||
*/ | ||
describe('Multiplexer works', () => { | ||
/* | ||
* basic setup | ||
*/ | ||
const a = new Multiplexer(40, 40); | ||
const n1 = a.nodeList[0] | ||
const n2 = a.nodeList[1] | ||
const n3 = a.nodeList[2] | ||
const n4 = a.nodeList[3] | ||
const i1 = new Input(10, 30); | ||
const i2 = new Input(10, 50); | ||
const i3 = new Input(10, 50); | ||
i1.output1.connect(n1); | ||
n1.connect(i1.output1); | ||
i2.output1.connect(n2); | ||
n2.connect(i2.output1); | ||
i3.output1.connect(n4); | ||
n4.connect(i3.output1); | ||
/* | ||
* test cases | ||
*/ | ||
it("draws correctly", () => { | ||
|
||
}) | ||
var bools = [[0, 0], [0, 1], [1, 0], [1, 1]]; | ||
it.each(bools)("logic works for control signal 1", (val1, val2) => { | ||
i1.state = val1 | ||
i2.state = val2 | ||
i3.state = 1 | ||
updateSimulationSet(true); | ||
update(); | ||
expect(n3.value).toBe(val2); | ||
}) | ||
it.each(bools)("logic works for control signal 0", (val1, val2) => { | ||
i1.state = val1 | ||
i2.state = val2 | ||
i3.state = 0 | ||
updateSimulationSet(true); | ||
update(); | ||
expect(n3.value).toBe(val1); | ||
}) | ||
}) | ||
|
||
/* | ||
* Demultiplexer test | ||
*/ | ||
describe('Demultiplexer works', () => { | ||
/* | ||
* basic setup | ||
*/ | ||
const a = new Demultiplexer(40, 40); | ||
const n1 = a.nodeList[0] | ||
const n2 = a.nodeList[1] | ||
const n3 = a.nodeList[2] | ||
const n4 = a.nodeList[3] | ||
const i1 = new Input(10, 30); | ||
const i3 = new Input(10, 50); | ||
i1.output1.connect(n1); | ||
n1.connect(i1.output1); | ||
i3.output1.connect(n4); | ||
n4.connect(i3.output1); | ||
/* | ||
* test cases | ||
*/ | ||
it("draws correctly", () => { | ||
|
||
}) | ||
var bools = [0,1]; | ||
it.each(bools)("logic works for control signal 1", (val1) => { | ||
i1.state = val1 | ||
i3.state = 1 | ||
updateSimulationSet(true); | ||
update(); | ||
expect([n2.value,n3.value]).toEqual([0,val1]); | ||
}) | ||
it.each(bools)("logic works for control signal 0", (val1) => { | ||
i1.state = val1 | ||
i3.state = 0 | ||
updateSimulationSet(true); | ||
update(); | ||
expect([n2.value, n3.value]).toEqual([val1,0]); | ||
}) | ||
}) |
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
Oops, something went wrong.