You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would expect Sets to have different behavior than objects in deep equality testing. Currently all Set objects are evaulated as equal using std/testing/asserts.ts's equal method. As side notes I would expect new Set([1,2,3]) to equal new Set([3,2,1]) as order shouldn't matter, and I would also expect new Set([1,2,3]) to not equal a set with different length of elements such as new Set([1]) and I would also expect new Set([1,2,3]) to not equal a set with different elements such as new Set([1,2,4]).
Here is a gist that shows a failing test of the implementation and a passing test that uses my own equality method, equalsIncludingSet, that handles sets, but there is a problem in the equals method I wrote. The .has method of set does not check with deep equality therefore with the below code we are only shallowly comparing objects within the set, but I think atleast for now it may be better than saying all sets are equal. Due to random ordering still being equal in sets deep equality checking would seem to me to have atleast a O(n^2) check time (run through the set for each item and run through the other set for a deep equality match of that item) I mean we could narrow n down to only the objects within the set. Also showing differences between not equal sets would be another hurdle to jump that's not covered in my little example implementation.
Currently what fails in the test is this method assertNotEquals(setA, setB); in the withNormalAssertions test this is because as stated before all sets are currently being evaluated as equal even when they are not.
You can run the gist by running it's raw file like so:
import{runTests,test}from"https://deno.land/std@v0.3.4/testing/mod.ts";import{assertNotEquals,assertEquals,equal}from"https://deno.land/std@v0.3.4/testing/asserts.ts";/** * determines if the two sets are equal order shouldn't matter */functionequalsIncludingSet(setA,setB){if(setAinstanceofSet||setBinstanceofSet){if(!(setAinstanceofSet&&setBinstanceofSet)){returnfalse;}if(setA.size!==setB.size){returnfalse;}for(constitemofsetA){if(!setB.has(item)){returnfalse;}}returntrue;}returnequal(setA,setB);}functionassertEqualsSet(setA,setB){if(!equalsIncludingSet(setA,setB)){thrownewError("SET A NOT EQUAL TO SET B");}}functionassertNotEqualsSet(setA,setB){if(equalsIncludingSet(setA,setB)){thrownewError("SET A IS EQUAL TO SET B");}}test(functionwithNormalAssertions(){constsetA=newSet([1,2,3]);constsetB=newSet([1]);constsetC=newSet([3,2,1]);assertEquals(setA,setC);assertNotEquals(setA,setB);});test(functionwithModifiedAssertionsForSets(){constsetA=newSet([1,2,3]);constsetB=newSet([1]);constsetC=newSet([3,2,1]);assertEqualsSet(setA,setC);assertNotEqualsSet(setA,setB);});runTests();
The text was updated successfully, but these errors were encountered:
I would expect Sets to have different behavior than objects in deep equality testing. Currently all Set objects are evaulated as equal using
std/testing/asserts.ts
's equal method. As side notes I would expectnew Set([1,2,3])
to equalnew Set([3,2,1])
as order shouldn't matter, and I would also expectnew Set([1,2,3])
to not equal a set with different length of elements such asnew Set([1])
and I would also expectnew Set([1,2,3])
to not equal a set with different elements such asnew Set([1,2,4])
.Here is a gist that shows a failing test of the implementation and a passing test that uses my own equality method,
equalsIncludingSet
, that handles sets, but there is a problem in the equals method I wrote. The.has
method of set does not check with deep equality therefore with the below code we are only shallowly comparing objects within the set, but I think atleast for now it may be better than saying all sets are equal. Due to random ordering still being equal in sets deep equality checking would seem to me to have atleast aO(n^2)
check time (run through the set for each item and run through the other set for a deep equality match of that item) I mean we could narrown
down to only the objects within the set. Also showing differences between not equal sets would be another hurdle to jump that's not covered in my little example implementation.Currently what fails in the test is this method
assertNotEquals(setA, setB);
in thewithNormalAssertions
test this is because as stated before all sets are currently being evaluated as equal even when they are not.You can run the gist by running it's raw file like so:
Gist pasted below for reference.
The text was updated successfully, but these errors were encountered: