Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 62 additions & 33 deletions src/simulator/spec/bitConvertor.spec.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,66 @@
import { setup } from '../src/setup';
import { bitConverterDialog, setBaseValues, setupBitConvertor } from '../src/utils';
import { createPinia, setActivePinia } from 'pinia';
import { mount } from '@vue/test-utils';
import { createRouter, createWebHistory } from 'vue-router';
import i18n from '#/locales/i18n';
import { routes } from '#/router';
import vuetify from '#/plugins/vuetify';
import simulator from '#/pages/simulator.vue';
import { setup } from '../src/setup'
import {
bitConverterDialog,
setBaseValues,
setupBitConvertor,
} from '../src/utils'
import { createPinia, setActivePinia } from 'pinia'
import { mount } from '@vue/test-utils'
import { createRouter, createWebHistory } from 'vue-router'
import i18n from '#/locales/i18n'
import { routes } from '#/router'
import vuetify from '#/plugins/vuetify'
import simulator from '#/pages/simulator.vue'
import { vi } from 'vitest'

vi.mock('@tauri-apps/api/event', () => ({
listen: vi.fn(() => Promise.resolve(() => {})),
}))

global.ResizeObserver = vi.fn().mockImplementation(() => ({
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
}))

HTMLCanvasElement.prototype.getContext = vi.fn(() => ({
clearRect: vi.fn(),
fillRect: vi.fn(),
fillText: vi.fn(),
strokeRect: vi.fn(),
beginPath: vi.fn(),
moveTo: vi.fn(),
lineTo: vi.fn(),
stroke: vi.fn(),
closePath: vi.fn(),
arc: vi.fn(),
fill: vi.fn(),
}))

vi.mock('codemirror', async (importOriginal) => {
const actual = await importOriginal();
const actual = await importOriginal()
return {
...actual,
fromTextArea: vi.fn(() => ({ setValue: () => { } })),
};
});
fromTextArea: vi.fn(() => ({ setValue: () => {} })),
}
})

vi.mock('codemirror-editor-vue3', () => ({
defineSimpleMode: vi.fn(),
}));
}))

describe('data dir working', () => {
let pinia;
let router;
let pinia
let router

beforeAll(async () => {
pinia = createPinia();
setActivePinia(pinia);
pinia = createPinia()
setActivePinia(pinia)

router = createRouter({
history: createWebHistory(),
routes,
});
})

const elem = document.createElement('div')

Expand All @@ -57,32 +86,32 @@
length: 0,
[Symbol.iterator]: vi.fn(() => []),
})),
}));
}))

global.globalScope = global.globalScope || {};
global.globalScope = global.globalScope || {}

mount(simulator, {
global: {
plugins: [pinia, router, i18n, vuetify],
},
attachTo: elem,
});
})

setup();
});
setup()
})

// Open BitConvertor Dialog
test('bitConvertor Dialog working', () => {
expect(() => bitConverterDialog()).not.toThrow();
});
expect(() => bitConverterDialog()).not.toThrow()

Check failure

Code scanning / ESLint

Disallow the use of undeclared variables unless mentioned in `/*global */` comments Error test

'expect' is not defined.
})

test('function setupBitConvertor working', () => {
expect(() => setupBitConvertor()).not.toThrow();
});
expect(() => setupBitConvertor()).not.toThrow()

Check failure

Code scanning / ESLint

Disallow the use of undeclared variables unless mentioned in `/*global */` comments Error test

'expect' is not defined.
})

test('function setBaseValues working', () => {
const randomBaseValue = Math.floor(Math.random() * 100);
console.log('Testing for Base Value --> ', randomBaseValue);
expect(() => setBaseValues(randomBaseValue)).not.toThrow();
});
});
const randomBaseValue = Math.floor(Math.random() * 100)
console.log('Testing for Base Value --> ', randomBaseValue)
expect(() => setBaseValues(randomBaseValue)).not.toThrow()

Check failure

Code scanning / ESLint

Disallow the use of undeclared variables unless mentioned in `/*global */` comments Error test

'expect' is not defined.
})
})
106 changes: 68 additions & 38 deletions src/simulator/spec/combinationalAnalysis.spec.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,67 @@
import { setup } from '../src/setup';
import { runAll } from '../src/testbench';
import testData from './testData/gates-testdata.json';
import { GenerateCircuit, performCombinationalAnalysis } from '../src/combinationalAnalysis';
import { createPinia, setActivePinia } from 'pinia';
import { mount } from '@vue/test-utils';
import { createRouter, createWebHistory } from 'vue-router';
import i18n from '#/locales/i18n';
import { routes } from '#/router';
import vuetify from '#/plugins/vuetify';
import simulator from '#/pages/simulator.vue';
import { setup } from '../src/setup'
import { runAll } from '../src/testbench'
import testData from './testData/gates-testdata.json'
import {
GenerateCircuit,
performCombinationalAnalysis,
} from '../src/combinationalAnalysis'
import { createPinia, setActivePinia } from 'pinia'
import { mount } from '@vue/test-utils'
import { createRouter, createWebHistory } from 'vue-router'
import i18n from '#/locales/i18n'
import { routes } from '#/router'
import vuetify from '#/plugins/vuetify'
import simulator from '#/pages/simulator.vue'
import { vi } from 'vitest'

vi.mock('@tauri-apps/api/event', () => ({
listen: vi.fn(() => Promise.resolve(() => {})),
}))

global.ResizeObserver = vi.fn().mockImplementation(() => ({
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
}))

HTMLCanvasElement.prototype.getContext = vi.fn(() => ({
clearRect: vi.fn(),
fillRect: vi.fn(),
fillText: vi.fn(),
strokeRect: vi.fn(),
beginPath: vi.fn(),
moveTo: vi.fn(),
lineTo: vi.fn(),
stroke: vi.fn(),
closePath: vi.fn(),
arc: vi.fn(),
fill: vi.fn(),
}))

vi.mock('codemirror', async (importOriginal) => {
const actual = await importOriginal();
const actual = await importOriginal()
return {
...actual,
fromTextArea: vi.fn(() => ({ setValue: () => { } })),
};
});
fromTextArea: vi.fn(() => ({ setValue: () => {} })),
}
})

vi.mock('codemirror-editor-vue3', () => ({
defineSimpleMode: vi.fn(),
}));
}))

describe('Combinational Analysis Testing', () => {
let pinia;
let router;
let pinia
let router

beforeAll(async () => {
pinia = createPinia();
setActivePinia(pinia);
pinia = createPinia()
setActivePinia(pinia)

router = createRouter({
history: createWebHistory(),
routes,
});
})

const elem = document.createElement('div')

Expand All @@ -59,34 +87,36 @@
length: 0,
[Symbol.iterator]: vi.fn(() => []),
})),
}));
}))

global.globalScope = global.globalScope || {};
global.globalScope = global.globalScope || {}

mount(simulator, {
global: {
plugins: [pinia, router, i18n, vuetify],
},
attachTo: elem,
});
})

setup();
});
setup()
})

test('performCombinationalAnalysis function working', () => {
expect(() => performCombinationalAnalysis('', '', 'AB')).not.toThrow();
});
expect(() => performCombinationalAnalysis('', '', 'AB')).not.toThrow()

Check failure

Code scanning / ESLint

Disallow the use of undeclared variables unless mentioned in `/*global */` comments Error test

'expect' is not defined.
})

test('Generating Circuit', () => {
expect(() => GenerateCircuit([13], ['A', 'B'], [0, 0, 0, 1], 'AB')).not.toThrow();
});
expect(() =>

Check failure

Code scanning / ESLint

Disallow the use of undeclared variables unless mentioned in `/*global */` comments Error test

'expect' is not defined.
GenerateCircuit([13], ['A', 'B'], [0, 0, 0, 1], 'AB')
).not.toThrow()
})

test('testing Combinational circuit', () => {
testData.AndGate.groups[0].inputs[0].label = 'A';
testData.AndGate.groups[0].inputs[1].label = 'B';
testData.AndGate.groups[0].outputs[0].label = 'AB';

const result = runAll(testData.AndGate);
expect(result.summary.passed).toBe(3);
});
});
testData.AndGate.groups[0].inputs[0].label = 'A'
testData.AndGate.groups[0].inputs[1].label = 'B'
testData.AndGate.groups[0].outputs[0].label = 'AB'

const result = runAll(testData.AndGate)
expect(result.summary.passed).toBe(3)

Check failure

Code scanning / ESLint

Disallow the use of undeclared variables unless mentioned in `/*global */` comments Error test

'expect' is not defined.
})
})
Loading
Loading