Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Commit

Permalink
testing improved
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhankarsharma00 committed Jun 29, 2020
1 parent c83949d commit 12260cf
Show file tree
Hide file tree
Showing 7 changed files with 1,167 additions and 263 deletions.
823 changes: 566 additions & 257 deletions index.html

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/circuitElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ export default class CircuitElement {
* adds the element to scopeList
*/
baseSetup() {
console.log(this.objectType);
this.scope[this.objectType].push(this);
}

Expand Down
96 changes: 96 additions & 0 deletions test/gates/decoders.test.js
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]);
})
})
270 changes: 268 additions & 2 deletions test/gates/gates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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));
})
});
Loading

0 comments on commit 12260cf

Please sign in to comment.