diff --git a/CHANGELOG.md b/CHANGELOG.md index 301efa22..25629534 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Modified `roughjs` import to be compatible with Jest's `moduleNameMapper` config option. - Added instructions on the `memory-viz/README.md` for running the test suite. - Fix CI build action for demo website. +- Added data type and manual layout tests for the `draw` function. - Updated file paths for example files under docs to import the correct file. ## [0.1.0] - 2024-04-16 diff --git a/memory-viz/package.json b/memory-viz/package.json index 6f6d6506..f053e23d 100644 --- a/memory-viz/package.json +++ b/memory-viz/package.json @@ -25,6 +25,7 @@ "Yoonie Jang", "Shannon Komguem", "Utku Egemen Umut", + "Sarah Wang", "Ziyuan (Jerry) Zhang" ], "license": "MIT", diff --git a/memory-viz/src/tests/__snapshots__/draw.spec.tsx.snap b/memory-viz/src/tests/__snapshots__/draw.spec.tsx.snap index 4a828475..1e2e4a61 100644 --- a/memory-viz/src/tests/__snapshots__/draw.spec.tsx.snap +++ b/memory-viz/src/tests/__snapshots__/draw.spec.tsx.snap @@ -1,3 +1,41 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`draw function renders a blank space 1`] = `""`; + +exports[`draw function renders a bool 1`] = `"Trueid32bool"`; + +exports[`draw function renders a bool using manual layout 1`] = `"Trueid32bool"`; + +exports[`draw function renders a dict 1`] = `"idxidyidz:id81:id100:id121id10dict"`; + +exports[`draw function renders a float 1`] = `"7id32float"`; + +exports[`draw function renders a list with indexes showing 1`] = `"id100id111id122id32list"`; + +exports[`draw function renders a list without indexes showing 1`] = `"id10id11id12id32list"`; + +exports[`draw function renders a set 1`] = `"id10id11,id12,id32set{}"`; + +exports[`draw function renders a stack frame and an int 1`] = `"my_intid13__main__7id13int"`; + +exports[`draw function renders a stack frame using manual layout 1`] = `"lst1id82lst2id84__main__"`; + +exports[`draw function renders a str 1`] = `""winter"id32str"`; + +exports[`draw function renders a tuple with indexes showing 1`] = `"id100id111id122id32tuple"`; + +exports[`draw function renders a tuple without indexes showing 1`] = `"id10id11id12id32tuple"`; + +exports[`draw function renders an empty dict 1`] = `"id32dict"`; + +exports[`draw function renders an empty list 1`] = `"id32list"`; + +exports[`draw function renders an empty set 1`] = `"id32set{}"`; + +exports[`draw function renders an empty tuple 1`] = `"id32tuple"`; + +exports[`draw function renders an int 1`] = `"7id32int"`; + +exports[`draw function renders an object with no type and no value 1`] = `""None"id13None"`; + exports[`draw function should produce consistent svg when provided seed 1`] = `"lst1id82lst2id84pid99did10tid11__main__"David is cool!"id19str7id13int"`; diff --git a/memory-viz/src/tests/draw.spec.tsx b/memory-viz/src/tests/draw.spec.tsx index 3acc508c..6752b45e 100644 --- a/memory-viz/src/tests/draw.spec.tsx +++ b/memory-viz/src/tests/draw.spec.tsx @@ -27,4 +27,279 @@ describe("draw function", () => { const svg: String = m.serializeSVG(); expect(svg).toMatchSnapshot(); }); + + it("renders a bool", () => { + const objects: Array = [ + { isClass: false, name: "bool", id: 32, value: true }, + ]; + const m: InstanceType = draw(objects, true, { + width: 1300, + seed: 12345, + }); + const svg: String = m.serializeSVG(); + expect(svg).toMatchSnapshot(); + }); + + it("renders an int", () => { + const objects: Array = [ + { isClass: false, name: "int", id: 32, value: 7 }, + ]; + const m: InstanceType = draw(objects, true, { + width: 1300, + seed: 12345, + }); + const svg: String = m.serializeSVG(); + expect(svg).toMatchSnapshot(); + }); + + it("renders a float", () => { + const objects: Array = [ + { isClass: false, name: "float", id: 32, value: 7.0 }, + ]; + const m: InstanceType = draw(objects, true, { + width: 1300, + seed: 12345, + }); + const svg: String = m.serializeSVG(); + expect(svg).toMatchSnapshot(); + }); + + it("renders a str", () => { + const objects: Array = [ + { isClass: false, name: "str", id: 32, value: "winter" }, + ]; + const m: InstanceType = draw(objects, true, { + width: 1300, + seed: 12345, + }); + const svg: String = m.serializeSVG(); + expect(svg).toMatchSnapshot(); + }); + + it("renders a set", () => { + const objects: Array = [ + { isClass: false, name: "set", id: 32, value: [10, 11, 12] }, + ]; + const m: InstanceType = draw(objects, true, { + width: 1300, + seed: 12345, + }); + const svg: String = m.serializeSVG(); + expect(svg).toMatchSnapshot(); + }); + + it("renders an empty set", () => { + const objects: Array = [ + { isClass: false, name: "set", id: 32, value: [] }, + ]; + const m: InstanceType = draw(objects, true, { + width: 1300, + seed: 12345, + }); + const svg: String = m.serializeSVG(); + expect(svg).toMatchSnapshot(); + }); + + it("renders a list with indexes showing", () => { + const objects: Array = [ + { + isClass: false, + name: "list", + id: 32, + value: [10, 11, 12], + show_indexes: true, + }, + ]; + const m: InstanceType = draw(objects, true, { + width: 1300, + seed: 12345, + }); + const svg: String = m.serializeSVG(); + expect(svg).toMatchSnapshot(); + }); + + it("renders a list without indexes showing", () => { + const objects: Array = [ + { isClass: false, name: "list", id: 32, value: [10, 11, 12] }, + ]; + const m: InstanceType = draw(objects, true, { + width: 1300, + seed: 12345, + }); + const svg: String = m.serializeSVG(); + expect(svg).toMatchSnapshot(); + }); + + it("renders an empty list", () => { + const objects: Array = [ + { isClass: false, name: "list", id: 32, value: [] }, + ]; + const m: InstanceType = draw(objects, true, { + width: 1300, + seed: 12345, + }); + const svg: String = m.serializeSVG(); + expect(svg).toMatchSnapshot(); + }); + + it("renders a tuple with indexes showing", () => { + const objects: Array = [ + { + isClass: false, + name: "tuple", + id: 32, + value: [10, 11, 12], + show_indexes: true, + }, + ]; + const m: InstanceType = draw(objects, true, { + width: 1300, + seed: 12345, + }); + const svg: String = m.serializeSVG(); + expect(svg).toMatchSnapshot(); + }); + + it("renders a tuple without indexes showing", () => { + const objects: Array = [ + { isClass: false, name: "tuple", id: 32, value: [10, 11, 12] }, + ]; + const m: InstanceType = draw(objects, true, { + width: 1300, + seed: 12345, + }); + const svg: String = m.serializeSVG(); + expect(svg).toMatchSnapshot(); + }); + + it("renders an empty tuple", () => { + const objects: Array = [ + { isClass: false, name: "tuple", id: 32, value: [] }, + ]; + const m: InstanceType = draw(objects, true, { + width: 1300, + seed: 12345, + }); + const svg: String = m.serializeSVG(); + expect(svg).toMatchSnapshot(); + }); + + it("renders a dict", () => { + const objects: Array = [ + { + isClass: false, + name: "dict", + id: 10, + value: { x: 81, y: 100, z: 121 }, + }, + ]; + const m: InstanceType = draw(objects, true, { + width: 1300, + seed: 12345, + }); + const svg: String = m.serializeSVG(); + expect(svg).toMatchSnapshot(); + }); + + it("renders an empty dict", () => { + const objects: Array = [ + { isClass: false, name: "dict", id: 32, value: {} }, + ]; + const m: InstanceType = draw(objects, true, { + width: 1300, + seed: 12345, + }); + const svg: String = m.serializeSVG(); + expect(svg).toMatchSnapshot(); + }); + + it("renders an object with no type and no value", () => { + const objects: Array = [ + { isClass: false, name: "None", id: 13, value: "None" }, + ]; + const m: InstanceType = draw(objects, true, { + width: 1300, + seed: 12345, + }); + const svg: String = m.serializeSVG(); + expect(svg).toMatchSnapshot(); + }); + + it("renders a blank space", () => { + const objects: Array = [ + { name: "BLANK", width: 100, height: 200 }, + ]; + const m: InstanceType = draw(objects, true, { + width: 1300, + seed: 12345, + }); + const svg: String = m.serializeSVG(); + expect(svg).toMatchSnapshot(); + }); + + it("renders a stack frame and an int", () => { + const objects: Array = [ + { + isClass: true, + name: "__main__", + id: null, + value: { + my_int: 13, + }, + stack_frame: true, + }, + { + isClass: false, + name: "int", + id: 13, + value: 7, + }, + ]; + const m: InstanceType = draw(objects, true, { + width: 1300, + seed: 12345, + }); + const svg: String = m.serializeSVG(); + expect(svg).toMatchSnapshot(); + }); + + it("renders a stack frame using manual layout", () => { + const objects: Array = [ + { + isClass: true, + x: 200, + y: 200, + name: "__main__", + id: null, + value: { + lst1: 82, + lst2: 84, + }, + stack_frame: true, + }, + ]; + const m: InstanceType = draw(objects, false, { + seed: 12345, + }); + const svg: String = m.serializeSVG(); + expect(svg).toMatchSnapshot(); + }); + + it("renders a bool using manual layout", () => { + const objects: Array = [ + { + isClass: false, + x: 750, + y: 250, + name: "bool", + id: 32, + value: true, + }, + ]; + const m: InstanceType = draw(objects, false, { + seed: 12345, + }); + const svg: String = m.serializeSVG(); + expect(svg).toMatchSnapshot(); + }); });