From 1c0f1511d45ff730c567a8aa51b0d1ef9bc9b81c Mon Sep 17 00:00:00 2001 From: Sarah Wang Date: Mon, 20 May 2024 00:52:05 -0400 Subject: [PATCH] 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" },