@@ -4,6 +4,7 @@ import { MultiSet } from "../../src/multiset.js"
4
4
import { distinct } from "../../src/operators/distinct.js"
5
5
import { output } from "../../src/operators/output.js"
6
6
import { MessageTracker , assertResults } from "../test-utils.js"
7
+ import { hash } from "../../src/hashing/index.js"
7
8
8
9
describe ( `Operators` , ( ) => {
9
10
describe ( `Efficient distinct operation` , ( ) => {
@@ -39,9 +40,9 @@ function testDistinct() {
39
40
40
41
expect ( data ) . toEqual ( [
41
42
[
42
- [ [ 1 , `a` ] , 1 ] ,
43
- [ [ 2 , `b` ] , 1 ] ,
44
- [ [ 2 , `c` ] , 1 ] ,
43
+ [ [ hash ( [ 1 , `a` ] ) , `a` ] , 1 ] ,
44
+ [ [ hash ( [ 2 , `b` ] ) , `b` ] , 1 ] ,
45
+ [ [ hash ( [ 2 , `c` ] ) , `c` ] , 1 ] ,
45
46
] ,
46
47
] )
47
48
} )
@@ -74,7 +75,7 @@ function testDistinct() {
74
75
75
76
graph . run ( )
76
77
77
- const data = messages . map ( ( m ) => m . getInner ( ) ) [ 0 ]
78
+ const data = messages . map ( ( m ) => m . getInner ( ) ) [ 0 ] !
78
79
const countries = data
79
80
. map ( ( [ [ _ , value ] , multiplicity ] ) => [ value . country , multiplicity ] )
80
81
. sort ( )
@@ -118,8 +119,8 @@ function testDistinct() {
118
119
`distinct with updates - initial` ,
119
120
initialResult ,
120
121
[
121
- [ 1 , `a` ] ,
122
- [ 1 , `b` ] ,
122
+ [ hash ( [ 1 , `a` ] ) , `a` ] ,
123
+ [ hash ( [ 1 , `b` ] ) , `b` ] ,
123
124
] , // Should have both distinct values
124
125
4 // Max expected messages
125
126
)
@@ -140,7 +141,7 @@ function testDistinct() {
140
141
assertResults (
141
142
`distinct with updates - second batch` ,
142
143
secondResult ,
143
- [ [ 1 , `c` ] ] , // Should only have 'c' remaining
144
+ [ [ hash ( [ 1 , `c` ] ) , `c` ] ] , // Should only have 'c' remaining
144
145
4 // Max expected messages
145
146
)
146
147
@@ -186,9 +187,9 @@ function testDistinct() {
186
187
187
188
expect ( data ) . toEqual ( [
188
189
[
189
- [ [ `key1` , 1 ] , 1 ] ,
190
- [ [ `key1` , 2 ] , 1 ] ,
191
- [ [ `key2` , 1 ] , 1 ] ,
190
+ [ [ hash ( [ `key1` , 1 ] ) , 1 ] , 1 ] ,
191
+ [ [ hash ( [ `key1` , 2 ] ) , 2 ] , 1 ] ,
192
+ [ [ hash ( [ `key2` , 1 ] ) , 1 ] , 1 ] ,
192
193
] ,
193
194
] )
194
195
} )
@@ -224,8 +225,8 @@ function testDistinct() {
224
225
`distinct with multiple batches that cancel out` ,
225
226
result ,
226
227
[
227
- [ `key1` , 1 ] , // Should remain (multiplicity 2 -> 1 in distinct)
228
- [ `key2` , 1 ] , // Should remain (multiplicity 2 -> 1 in distinct)
228
+ [ hash ( [ `key1` , 1 ] ) , 1 ] , // Should remain (multiplicity 2 -> 1 in distinct)
229
+ [ hash ( [ `key2` , 1 ] ) , 1 ] , // Should remain (multiplicity 2 -> 1 in distinct)
229
230
] ,
230
231
6 // Max expected messages (generous upper bound)
231
232
)
0 commit comments