From 588cf217a3d680e6a072c2161dcd760e1194ccff Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Mon, 19 May 2025 22:52:52 -0400 Subject: [PATCH] WIP: Add AddVector.jls, a memory test. --- tests/Logisim/Bitwidth.test.ts | 1 - tests/jls/AddVector.jls | Bin 0 -> 2593 bytes tests/jls/AddVector.test.ts | 87 +++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 tests/jls/AddVector.jls create mode 100644 tests/jls/AddVector.test.ts 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 0000000000000000000000000000000000000000..dc6a176793250f5580896db55fae732c36f94267 GIT binary patch literal 2593 zcmai$X*3iJ7stm=h$OpY?6QS08C!$w6jBXYCePT%GWL-*jUj7f%UH4vVa67NMv)OA z6A@!6*_VhBinq>r&v~Bb{qo-X;okeJ8 z7UCHQ3-&}dL(PMxG`PEt99)ooYCZAwWfGA*!|GPvL`$x&5ukfxxhW@G@AgY&*(8#Z zA>A{o4i2G+E9p8F&ZT+x$oS2WGb za*5uLR}tDkI47CVLY3W>u;lqZYomi7l1G)$$(%ijNgt`(kDJ>WlhsD~yfaPno)?(_ zX=%!4yd}UZ#E!0!ohO#m{@R=fI-gsBk2{_Td?dy@v3It!BMyt~p?e3v>dzDEmR}-o z-J#?>I9&O>xJp?fGG!vRuw0*E8t9MtTKMQr%{Oz#px{#&W&=C4!RUpcxKhw~K)tx) z71NA`dT90CgU;IKbwgp0>6=GjuxP@*yq-yY<5HZ0E&1nKnFZ{)~addw|O4&zXF zt0}^01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Lb`mBh6Ty=vv6^Q z^DM*LSY%E6Gd%}}y&tRh$5UCn;E%%J;KfMy#}gerFW_%D u`={SOaQ5%|8`b_-_s^gI*7f~P@3-#1+1QvfG5`5V|GWKv&jPkT*M9)53b{`J literal 0 HcmV?d00001 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()), + ); +});