From 7c4f9a35ef92d79ea95fdae99dd712cc8e8207b9 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Wed, 3 Jan 2024 20:35:44 -0800 Subject: [PATCH] Fixed isEqual for Squiggle Lists --- .changeset/new-ways-clap.md | 5 +++++ packages/squiggle-lang/__tests__/library/builtin_test.ts | 3 +++ packages/squiggle-lang/src/value/index.ts | 5 ++++- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/new-ways-clap.md diff --git a/.changeset/new-ways-clap.md b/.changeset/new-ways-clap.md new file mode 100644 index 0000000000..9afa8c980d --- /dev/null +++ b/.changeset/new-ways-clap.md @@ -0,0 +1,5 @@ +--- +"@quri/squiggle-lang": patch +--- + +Fix isEqual for Squiggle Lists diff --git a/packages/squiggle-lang/__tests__/library/builtin_test.ts b/packages/squiggle-lang/__tests__/library/builtin_test.ts index 188a4205a7..50a701118e 100644 --- a/packages/squiggle-lang/__tests__/library/builtin_test.ts +++ b/packages/squiggle-lang/__tests__/library/builtin_test.ts @@ -22,6 +22,9 @@ describe("Operators", () => { testEvalToBe("0 == true", "false"); testEvalToBe("0 == false", "false"); testEvalToBe('"" == false', "false"); + testEvalToBe("[1,2,3,5] == [1,2,3,5]", "true"); + testEvalToBe("[1,2,3] == [1,2,3,5]", "false"); + testEvalToBe("[1,2,3,8] == [1,2,3,5]", "false", true); testEvalToBe("normal(5,2) == normal(5,2)", "false"); testEvalToBe("Sym.normal(5,2) == Sym.normal(5,2)", "true"); testEvalToBe("Sym.uniform(10,12) == Sym.normal(5,2)", "false"); diff --git a/packages/squiggle-lang/src/value/index.ts b/packages/squiggle-lang/src/value/index.ts index 0df2bfc636..b27c4e1465 100644 --- a/packages/squiggle-lang/src/value/index.ts +++ b/packages/squiggle-lang/src/value/index.ts @@ -112,7 +112,10 @@ class VArray extends BaseValue implements Indexable { } for (let i = 0; i < this.value.length; i++) { - isEqual(this.value[i], other.value[i]); + const _isEqual = isEqual(this.value[i], other.value[i]); + if (!_isEqual) { + return false; + } } return true; }