From ae902a997d4f288edc980c839c70be9c9b8a3a16 Mon Sep 17 00:00:00 2001 From: Sarah Wang Date: Thu, 16 May 2024 12:41:03 -0400 Subject: [PATCH 1/4] add draw function tests for variable types and manual layout --- .../tests/__snapshots__/draw.spec.tsx.snap | 24 +++ memory-viz/src/tests/draw.spec.tsx | 185 ++++++++++++++++++ 2 files changed, 209 insertions(+) diff --git a/memory-viz/src/tests/__snapshots__/draw.spec.tsx.snap b/memory-viz/src/tests/__snapshots__/draw.spec.tsx.snap index 4a828475..1908a548 100644 --- a/memory-viz/src/tests/__snapshots__/draw.spec.tsx.snap +++ b/memory-viz/src/tests/__snapshots__/draw.spec.tsx.snap @@ -1,3 +1,27 @@ // 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 list with indexes showing 1`] = `"id100id111id122id32list"`; + +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 without indexes showing 1`] = `"id10id11id12id32tuple"`; + +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..27bdc504 100644 --- a/memory-viz/src/tests/draw.spec.tsx +++ b/memory-viz/src/tests/draw.spec.tsx @@ -27,4 +27,189 @@ 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 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 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 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 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 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(); + }); }); From 2b2513df73cf06fb50d3f9b76a3a8ab00124d589 Mon Sep 17 00:00:00 2001 From: Sarah Wang Date: Thu, 16 May 2024 12:43:07 -0400 Subject: [PATCH 2/4] add myself to contributors list --- memory-viz/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/memory-viz/package.json b/memory-viz/package.json index aef0e56e..1c6fb212 100644 --- a/memory-viz/package.json +++ b/memory-viz/package.json @@ -24,6 +24,7 @@ "Mimis Chlympatsos", "Shannon Komguem", "Utku Egemen Umut", + "Sarah Wang", "Ziyuan (Jerry) Zhang" ], "license": "MIT", From c0e1d0363de3d50eb75f4f0f99c9a33cde40f962 Mon Sep 17 00:00:00 2001 From: Sarah Wang Date: Thu, 16 May 2024 12:52:35 -0400 Subject: [PATCH 3/4] update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d94ce7e..3a7a446c 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 ## [0.1.0] - 2024-04-16 From 1c0f1511d45ff730c567a8aa51b0d1ef9bc9b81c Mon Sep 17 00:00:00 2001 From: Sarah Wang Date: Mon, 20 May 2024 00:52:05 -0400 Subject: [PATCH 4/4] add tests for float, empty collections --- .../tests/__snapshots__/draw.spec.tsx.snap | 14 +++ memory-viz/src/tests/draw.spec.tsx | 90 +++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/memory-viz/src/tests/__snapshots__/draw.spec.tsx.snap b/memory-viz/src/tests/__snapshots__/draw.spec.tsx.snap index 1908a548..1e2e4a61 100644 --- a/memory-viz/src/tests/__snapshots__/draw.spec.tsx.snap +++ b/memory-viz/src/tests/__snapshots__/draw.spec.tsx.snap @@ -8,8 +8,12 @@ exports[`draw function renders a bool using manual layout 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"`; @@ -18,8 +22,18 @@ exports[`draw function renders a stack frame using manual layout 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"`; diff --git a/memory-viz/src/tests/draw.spec.tsx b/memory-viz/src/tests/draw.spec.tsx index 27bdc504..6752b45e 100644 --- a/memory-viz/src/tests/draw.spec.tsx +++ b/memory-viz/src/tests/draw.spec.tsx @@ -52,6 +52,18 @@ describe("draw function", () => { 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" }, @@ -76,6 +88,18 @@ describe("draw function", () => { 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 = [ { @@ -94,6 +118,48 @@ describe("draw function", () => { 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] }, @@ -106,6 +172,18 @@ describe("draw function", () => { 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 = [ { @@ -123,6 +201,18 @@ describe("draw function", () => { 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" },