diff --git a/index.html b/index.html index 8d6facd..32e5c2e 100644 --- a/index.html +++ b/index.html @@ -1,295 +1,604 @@ - - + + - - - - + var projectName = "Shubhankar's Test"; + + CircuitVerse - - + + - - - Project - - New Project - Clear Project - Save Online - Save Offline - Open Offline - Recover project - + + + Project + + + New Project - - Circuit - - New Circuit + - Insert SubCircuit - + + Clear Project - - Tools - - Combinational - Analysis - Start Plot - Download Image - + + Save Online - - Help + + Save Offline - - - Untitled - - - + + Open Offline - + + Recover Project + + + + + Circuit + + + New Circuit + + + + Insert SubCircuit + + + + + Tools + + + Combinational Analysis + + + Hex-Bin-Dec-Converter + + + Start Plot + + + Download Image + + + + + Help + + + + Untitled + + + + Sign In + + - - - - - Circuit Elements - - - - - Properties - - - + + + + + Circuit Elements + + + + Properties + + + - - + + + + + + + + Restricted elements used: + + - - - - - Restricted elements used: - - - - - - - - - - - - - - - Paste - Copy - Cut - Delete - Undo - New Circuit - Insert SubCircuit - Center Focus - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Layout options - - Width: - - - - - - - - - Height: - - - - - - - - - Reset all nodes: - - - - - - Title: - - - - - - - - - - - - - - - Title Enabled : - - - - - Save: - - - - Cancel: - - - - - - + + + + + + + + + + + + + Paste + Copy + Cut + Delete + Undo + New Circuit + Insert SubCircuit + Center Focus + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Layout options + + Width: + + + + + + + + + Height: + + + + + + + + + Reset all nodes: + + + + + + Title: + + + + + + + + + + + + + + + + Title Enabled : + + + + + + + + Save: + + + + Cancel: + + + + + - - - + + + + + - - PNG - JPEG - SVG - BMP - GIF - TIFF - - - Full Circuit View - Current - View - - - Transparent - Background - - - Resolution: - 1x - 2x - 4x - + + PNG + JPEG + + SVG + + BMP + + GIF + + TIFF + + + Full Circuit + View + + Current View + + + + Transparent Background + + + Resolution: + + 1x + 2x + + 4x + - - - - \ No newline at end of file + + + + + + Report an issue + + + + + + + + × + + + Report an issue + + + + Describe your issue: + + + + + + + Report + + + + + + + + + diff --git a/src/circuitElement.js b/src/circuitElement.js index c6c3a98..8c6ac50 100644 --- a/src/circuitElement.js +++ b/src/circuitElement.js @@ -95,7 +95,6 @@ export default class CircuitElement { * adds the element to scopeList */ baseSetup() { - console.log(this.objectType); this.scope[this.objectType].push(this); } diff --git a/test/gates/decoders.test.js b/test/gates/decoders.test.js new file mode 100644 index 0000000..4a0e558 --- /dev/null +++ b/test/gates/decoders.test.js @@ -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]); + }) +}) \ No newline at end of file diff --git a/test/gates/gates.test.js b/test/gates/gates.test.js index bcbf0a4..c3a7ce2 100644 --- a/test/gates/gates.test.js +++ b/test/gates/gates.test.js @@ -4,10 +4,19 @@ import { setup } from '../../src/setup' setup() import AndGate from '../../src/modules/AndGate' +import OrGate from '../../src/modules/OrGate'; +import XnorGate from '../../src/modules/XnorGate'; +import XorGate from '../../src/modules/XorGate'; +import NandGate from '../../src/modules/NandGate'; +import NorGate from '../../src/modules/NorGate'; +import NotGate from '../../src/modules/NotGate'; import Input from '../../src/modules/Input' import { update, updateSimulationSet } from '../../src/engine' -describe('and gate works', () => { +/* + * AndGate test + */ +describe('AndGate works', () => { /* * basic setup */ @@ -29,11 +38,268 @@ describe('and gate works', () => { }) var bools = [[0,0],[0,1],[1,0],[1,1]]; it.each(bools)("logic works", (val1,val2) => { - console.log(val1,val2) i1.state = val1 i2.state = val2 updateSimulationSet(true); update(); expect(n3.value).toBe(val1&val2); }) + it('can change input node', () => { + const x = a.changeInputSize(3) + expect(x.inp.length).toBe(3) + }); +}); + +/* + * OrGate test + */ +describe('OrGate works', () => { + /* + * basic setup + */ + const a = new OrGate(40, 40); + const n1 = a.nodeList[0] + const n2 = a.nodeList[1] + const n3 = a.nodeList[2] + const i1 = new Input(10, 30); + const i2 = new Input(10, 50); + i1.output1.connect(n1); + n1.connect(i1.output1); + i2.output1.connect(n2); + n2.connect(i2.output1); + /* + * test cases + */ + it("draws correctly", () => { + + }) + var bools = [[0, 0], [0, 1], [1, 0], [1, 1]]; + it.each(bools)("logic works", (val1, val2) => { + i1.state = val1 + i2.state = val2 + updateSimulationSet(true); + update(); + expect(n3.value).toBe(val1 | val2); + }) + it('can change input node', () => { + const x = a.changeInputSize(3) + expect(x.inp.length).toBe(3) + }); +}); + +/* + * XorGate test + */ +describe('XorGate works', () => { + /* + * basic setup + */ + const a = new XorGate(40, 40); + const n1 = a.nodeList[0] + const n2 = a.nodeList[1] + const n3 = a.nodeList[2] + const i1 = new Input(10, 30); + const i2 = new Input(10, 50); + i1.output1.connect(n1); + n1.connect(i1.output1); + i2.output1.connect(n2); + n2.connect(i2.output1); + /* + * test cases + */ + it("draws correctly", () => { + + }) + var bools = [[0, 0], [0, 1], [1, 0], [1, 1]]; + it.each(bools)("logic works", (val1, val2) => { + i1.state = val1 + i2.state = val2 + updateSimulationSet(true); + update(); + expect(n3.value).toBe(val1 ^ val2); + }) + it('can change input node', () => { + const x = a.changeInputSize(3) + expect(x.inp.length).toBe(3) + }); +}); + + +/* + * XorGate test + */ +describe('XorGate works', () => { + /* + * basic setup + */ + const a = new XorGate(40, 40); + const n1 = a.nodeList[0] + const n2 = a.nodeList[1] + const n3 = a.nodeList[2] + const i1 = new Input(10, 30); + const i2 = new Input(10, 50); + i1.output1.connect(n1); + n1.connect(i1.output1); + i2.output1.connect(n2); + n2.connect(i2.output1); + /* + * test cases + */ + it("draws correctly", () => { + + }) + var bools = [[0, 0], [0, 1], [1, 0], [1, 1]]; + it.each(bools)("logic works", (val1, val2) => { + i1.state = val1 + i2.state = val2 + updateSimulationSet(true); + update(); + expect(n3.value).toBe(val1 ^ val2); + }) + it('can change input node', () => { + const x = a.changeInputSize(3) + expect(x.inp.length).toBe(3) + }); +}); + +/* + * XnorGate test + */ +describe('XnorGate works', () => { + /* + * basic setup + */ + const a = new XnorGate(40, 40); + const n1 = a.nodeList[0] + const n2 = a.nodeList[1] + const n3 = a.nodeList[2] + const i1 = new Input(10, 30); + const i2 = new Input(10, 50); + i1.output1.connect(n1); + n1.connect(i1.output1); + i2.output1.connect(n2); + n2.connect(i2.output1); + /* + * test cases + */ + it("draws correctly", () => { + + }) + var bools = [[0, 0], [0, 1], [1, 0], [1, 1]]; + it.each(bools)("logic works", (val1, val2) => { + i1.state = val1 + i2.state = val2 + updateSimulationSet(true); + update(); + expect(n3.value).toEqual(+!(val1 ^ val2)); + }) + it('can change input node', () => { + const x = a.changeInputSize(3) + expect(x.inp.length).toBe(3) + }); +}); + + +/* + * NorGate test + */ +describe('NorGate works', () => { + /* + * basic setup + */ + const a = new NorGate(40, 40); + const n1 = a.nodeList[0] + const n2 = a.nodeList[1] + const n3 = a.nodeList[2] + const i1 = new Input(10, 30); + const i2 = new Input(10, 50); + i1.output1.connect(n1); + n1.connect(i1.output1); + i2.output1.connect(n2); + n2.connect(i2.output1); + /* + * test cases + */ + it("draws correctly", () => { + + }) + var bools = [[0, 0], [0, 1], [1, 0], [1, 1]]; + it.each(bools)("logic works", (val1, val2) => { + i1.state = val1 + i2.state = val2 + updateSimulationSet(true); + update(); + expect(n3.value).toEqual(+!(val1 | val2)); + }) + it('can change input node', () => { + const x = a.changeInputSize(3) + expect(x.inp.length).toBe(3) + }); +}); + + +/* + * NandGate test + */ +describe('NandGate works', () => { + /* + * basic setup + */ + const a = new NandGate(40, 40); + const n1 = a.nodeList[0] + const n2 = a.nodeList[1] + const n3 = a.nodeList[2] + const i1 = new Input(10, 30); + const i2 = new Input(10, 50); + i1.output1.connect(n1); + n1.connect(i1.output1); + i2.output1.connect(n2); + n2.connect(i2.output1); + /* + * test cases + */ + it("draws correctly", () => { + + }) + var bools = [[0, 0], [0, 1], [1, 0], [1, 1]]; + it.each(bools)("logic works", (val1, val2) => { + i1.state = val1 + i2.state = val2 + updateSimulationSet(true); + update(); + expect(n3.value).toEqual(+!(val1 & val2)); + }) + it('can change input node', () => { + const x = a.changeInputSize(3) + expect(x.inp.length).toBe(3) + }); +}); + + +/* + * NotGate test + */ +describe('NotGate works', () => { + /* + * basic setup + */ + const a = new NotGate(40, 40); + const n1 = a.nodeList[0] + const n2 = a.nodeList[1] + const i1 = new Input(10, 30); + i1.output1.connect(n1); + n1.connect(i1.output1); + /* + * test cases + */ + it("draws correctly", () => { + + }) + var bools = [0,1]; + it.each(bools)("logic works", (val1) => { + i1.state = val1 + updateSimulationSet(true); + update(); + expect(n2.value).toEqual(+!(val1)); + }) }); diff --git a/test/gates/sequential.test.js b/test/gates/sequential.test.js new file mode 100644 index 0000000..84c630c --- /dev/null +++ b/test/gates/sequential.test.js @@ -0,0 +1,234 @@ +/** + * @jest-environment jsdom + */ +import { setup } from '../../src/setup' +setup() +import Input from '../../src/modules/Input' +import { update, updateSimulationSet } from '../../src/engine' +import Dlatch from '../../src/sequential/Dlatch'; +import DflipFlop from '../../src/sequential/DflipFlop'; +import TflipFlop from '../../src/sequential/TflipFlop'; +import SRflipFlop from '../../src/sequential/SRflipFlop'; +import JKflipFlop from '../../src/sequential/JKflipFlop'; + +/* + * Dlatch test + */ +describe('Dlatch works', () => { + /* + * basic setup + */ + const a = new Dlatch(40, 40); + const c = a.nodeList[0] + const d = a.nodeList[1] + const q = a.nodeList[2] + const i1 = new Input(10, 30); + i1.output1.connect(d); + d.connect(i1.output1); + it('draws right', () => { + i1.state = 0 + c.value = 0 + updateSimulationSet(true) + update() + c.value = 1 + updateSimulationSet(true) + update() + expect(q.value).toEqual(0) + }); + it('value of q', () => { + i1.state = 1 + c.value = 0 + updateSimulationSet(true) + update() + c.value = 1 + updateSimulationSet(true) + update() + expect(q.value).toEqual(1) + }); +}) + +/* + * DflipFlop test + */ +describe('DflipFlop works', () => { + /* + * basic setup + */ + const a = new DflipFlop(40, 40); + const c = a.nodeList[0] + const d = a.nodeList[1] + const q = a.nodeList[2] + const i1 = new Input(10, 30); + i1.output1.connect(d); + d.connect(i1.output1); + it('draws right', () => { + i1.state = 0 + c.value = 0 + updateSimulationSet(true) + update() + c.value = 1 + updateSimulationSet(true) + update() + expect(q.value).toEqual(0) + }); + it('value of q', () => { + i1.state = 1 + c.value = 0 + updateSimulationSet(true) + update() + c.value = 1 + updateSimulationSet(true) + update() + expect(q.value).toEqual(1) + }); +}) + +/* + * TflipFlop test + */ +describe('TflipFlop works', () => { + /* + * basic setup + */ + const a = new TflipFlop(40, 40); + const c = a.nodeList[0] + const t = a.nodeList[1] + const q = a.nodeList[2] + const i1 = new Input(10, 30); + i1.output1.connect(t); + t.connect(i1.output1); + it('draws right', () => { + i1.state = 0 + c.value = 0 + updateSimulationSet(true) + update() + c.value = 1 + expect(q.value).toEqual(0) + updateSimulationSet(true) + update() + expect(q.value).toEqual(0) + }); + it('value of T', () => { + i1.state = 1 + c.value = 0 + updateSimulationSet(true) + update() + expect(q.value).toEqual(0) + c.value = 1 + updateSimulationSet(true) + update() + expect(q.value).toEqual(1) + c.value = 0 + updateSimulationSet(true) + update() + expect(q.value).toEqual(1) + c.value = 1 + updateSimulationSet(true) + update() + expect(q.value).toEqual(0) + }); +}) + +/* + * SRflipFlop test + */ +describe('SRflipFlop works', () => { + /* + * basic setup + */ + const a = new SRflipFlop(40, 40); + const r = a.nodeList[0] + const s = a.nodeList[1] + const q = a.nodeList[2] + const i1 = new Input(10, 30); + const i2 = new Input(20, 40); + i1.output1.connect(s); + s.connect(i1.output1); + i2.output1.connect(r); + r.connect(i2.output1); + it('1 0 sr logic', () => { + i1.state = 1 + i2.state = 0 + updateSimulationSet(true) + update() + expect(q.value).toEqual(1) + }); + it('0 1 sr logic', () => { + i1.state = 0 + i2.state = 1 + updateSimulationSet(true) + update() + expect(q.value).toEqual(0) + }); + it('value of q with 0,0 sr logic', () => { + i1.state = 0 + i2.state = 0 + const state = q.value + updateSimulationSet(true) + update() + expect(q.value).toEqual(+state) + }); +}) + +/* + * JKflipFlop test + */ +describe('JKflipFlop works', () => { + /* + * basic setup + */ + const a = new JKflipFlop(40, 40); + const j = a.nodeList[0] + const k = a.nodeList[1] + const c = a.nodeList[2] + const q = a.nodeList[3] + const i1 = new Input(10, 30); + const i2 = new Input(10, 50); + i1.output1.connect(j); + j.connect(i1.output1); + i2.output1.connect(k); + k.connect(i2.output1); + it('0 1 jk logic', () => { + i1.state = 1 + c.value = 0 + updateSimulationSet(true) + update() + c.value = 1 + expect(q.value).toEqual(0) + updateSimulationSet(true) + update() + expect(q.value).toEqual(1) + }); + it('1 0 jk logic', () => { + i2.state = 1 + c.value = 0 + updateSimulationSet(true) + update() + c.value = 1 + expect(q.value).toEqual(1) + updateSimulationSet(true) + update() + expect(q.value).toEqual(0) + }); + it('value of q with 1,1 jk', () => { + i1.state = 1 + i2.state = 1 + c.value = 0 + const state = q.value + updateSimulationSet(true) + update() + expect(q.value).toEqual(+state) + c.value = 1 + updateSimulationSet(true) + update() + expect(q.value).toEqual(+!state) + c.value = 0 + updateSimulationSet(true) + update() + expect(q.value).toEqual(+!state) + c.value = 1 + updateSimulationSet(true) + update() + expect(q.value).toEqual(+state) + }); +}) diff --git a/test/listenertest.test.js b/test/listenertest.test.js index 87795f9..b4194f0 100644 --- a/test/listenertest.test.js +++ b/test/listenertest.test.js @@ -18,9 +18,9 @@ describe('button', function () { await page.click('#zoomIn') const newScale = await page.evaluate(() => globalScope.scale); expect(newScale).toBeGreaterThan(prevScale); - },100000) + },1000000) - it("zooms on scrlling", async () => { + it("zooms on scrolling", async () => { const prevScale = await page.evaluate(() => globalScope.scale); await page.waitForSelector('#simulationArea'); await page.hover('#simulationArea'); @@ -31,7 +31,7 @@ describe('button', function () { }); const newScale = await page.evaluate(() => globalScope.scale); expect(newScale).toBeGreaterThan(prevScale); - }); + },1000000); afterAll(async () => { await browser.close() diff --git a/test/sample.test.js b/test/restrictedElements.test.js similarity index 100% rename from test/sample.test.js rename to test/restrictedElements.test.js
Title Enabled : - -
+ Title Enabled : + + + + +
- PNG - JPEG - SVG - BMP - GIF - TIFF -
- Full Circuit View - Current - View -
- Transparent - Background -
- Resolution: - 1x - 2x - 4x -
+ PNG + JPEG + + SVG + + BMP + + GIF + + TIFF +
+ Full Circuit + View + + Current View +
+ + Transparent Background +
+ Resolution: + + 1x + 2x + + 4x +