diff --git a/tests/Logisim/Bitwidth.test.ts b/tests/Logisim/Bitwidth.test.ts index b3e3765..32878e7 100644 --- a/tests/Logisim/Bitwidth.test.ts +++ b/tests/Logisim/Bitwidth.test.ts @@ -75,7 +75,6 @@ for (let entry of table) { Output1: new BitString(entry[2]), }; const results = circ.run(inputs); - console.log(results); expect(results.outputs.Output1.toString()).toStrictEqual( outputs.Output1.toString(), ); diff --git a/tests/jls/AddVector.jls b/tests/jls/AddVector.jls new file mode 100644 index 0000000..dc6a176 Binary files /dev/null and b/tests/jls/AddVector.jls differ diff --git a/tests/jls/AddVector.test.ts b/tests/jls/AddVector.test.ts new file mode 100644 index 0000000..e5e3d73 --- /dev/null +++ b/tests/jls/AddVector.test.ts @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2025 Jordan Bancino + * Copyright (c) 2025 Austin Hargis + * Copyright (c) 2025 Aaron MacDougall + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import { beforeAll, test, expect } from "@jest/globals"; +import { BitString, Circuit, loadCircuit } from "../../src"; +import { JLSLoader } from "../../src/CircuitLoader/JLSLoader"; +import { FileLogger } from "../../src/CircuitLogger/FileLogger"; +import { LogLevel } from "../../src/CircuitLogger"; + +let circuit: Circuit; + +beforeAll(async () => { + const logger = new FileLogger("AddVector.log"); + logger.setLevel(LogLevel.TRACE); + circuit = await loadCircuit( + JLSLoader, + "tests/jls/AddVector.jls", + "AddVector", + logger, + ); +}); + +test("Test Memory", () => { + const initialState = [ + "0x0", + "0x10", + "0x20", + "0x30", + "0x40", + "0x50", + + "0x60", + "0x70", + "0x80", + "0x90", + "0xa0", + "0xb0", + "0xc0", + + "0xd0", + "0xe0", + "0xf0", + ].map((val) => new BitString(val, 16)); + + circuit.writeMemory("TheMemory", 0, initialState); + + circuit.run( + { + Offset: "0101", + Counter: "0011", + }, + (clockHigh, clockCycles, { outputs: { Halt } }) => { + console.log(`${clockHigh}, ${clockCycles}`); + + //return Halt.toString() == "1"; + return clockCycles == 100; + }, + 3000, + ); + + const finalState = circuit.readMemory("TheMemory", 0, 16); + + expect(finalState.map((b) => b.toString())).toStrictEqual( + initialState.map((b) => b.add("0101").toString()), + ); +});