@@ -2128,6 +2128,135 @@ end
21282128 @test b1 == b2 && b2 == b5 && b1 == b5
21292129end
21302130
2131+ @testitem " Equality for NamedColumn" tags= [:ring1 , :unit ] begin
2132+ using LogicalQueryProtocol: NamedColumn, var"#Type" , IntType, StringType
2133+ using ProtoBuf: OneOf
2134+
2135+ tint = var"#Type" (var"#type" = OneOf (:int_type , IntType ()))
2136+ tstr = var"#Type" (var"#type" = OneOf (:string_type , StringType ()))
2137+
2138+ c1 = NamedColumn (name= " src" , var"#type" = tint)
2139+ c2 = NamedColumn (name= " src" , var"#type" = tint)
2140+ c3 = NamedColumn (name= " dst" , var"#type" = tint) # different name
2141+ c4 = NamedColumn (name= " src" , var"#type" = tstr) # different type
2142+ c5 = NamedColumn (name= " src" , var"#type" = tint)
2143+
2144+ # Equality and inequality
2145+ @test c1 == c2
2146+ @test c1 != c3
2147+ @test c1 != c4
2148+ @test isequal (c1, c2)
2149+
2150+ # Hash consistency
2151+ @test hash (c1) == hash (c2)
2152+
2153+ # Reflexivity
2154+ @test c1 == c1
2155+ @test isequal (c1, c1)
2156+
2157+ # Symmetry
2158+ @test c1 == c2 && c2 == c1
2159+
2160+ # Transitivity
2161+ @test c1 == c2 && c2 == c5 && c1 == c5
2162+
2163+ # Works in collections
2164+ @test length (Set ([c1, c2, c3])) == 2
2165+ end
2166+
2167+ @testitem " Equality for TargetRelation" tags= [:ring1 , :unit ] begin
2168+ using LogicalQueryProtocol: TargetRelation, NamedColumn, RelationId, var"#Type" , FloatType
2169+ using ProtoBuf: OneOf
2170+
2171+ t1 = var"#Type" (var"#type" = OneOf (:float_type , FloatType ()))
2172+ v1 = NamedColumn (name= " weight" , var"#type" = t1)
2173+ v2 = NamedColumn (name= " label" , var"#type" = t1)
2174+ r1 = RelationId (id_low= 1 , id_high= 0 )
2175+ r2 = RelationId (id_low= 2 , id_high= 0 )
2176+
2177+ tr1 = TargetRelation (target_id= r1, values= [v1])
2178+ tr2 = TargetRelation (target_id= r1, values= [v1])
2179+ tr3 = TargetRelation (target_id= r2, values= [v1]) # different target
2180+ tr4 = TargetRelation (target_id= r1, values= [v2]) # different values
2181+ tr5 = TargetRelation (target_id= r1, values= []) # no value columns (e.g. keys-only delete)
2182+ tr6 = TargetRelation (target_id= r1, values= [v1])
2183+
2184+ # Equality and inequality
2185+ @test tr1 == tr2
2186+ @test tr1 != tr3
2187+ @test tr1 != tr4
2188+ @test tr1 != tr5
2189+ @test isequal (tr1, tr2)
2190+
2191+ # Hash consistency
2192+ @test hash (tr1) == hash (tr2)
2193+
2194+ # Reflexivity
2195+ @test tr1 == tr1
2196+ @test isequal (tr1, tr1)
2197+
2198+ # Symmetry
2199+ @test tr1 == tr2 && tr2 == tr1
2200+
2201+ # Transitivity
2202+ @test tr1 == tr2 && tr2 == tr6 && tr1 == tr6
2203+ end
2204+
2205+ @testitem " Equality for TargetRelations" tags= [:ring1 , :unit ] begin
2206+ using LogicalQueryProtocol: TargetRelations, TargetRelation, NamedColumn, RelationId, var"#Type" , IntType, FloatType
2207+ using ProtoBuf: OneOf
2208+
2209+ tint = var"#Type" (var"#type" = OneOf (:int_type , IntType ()))
2210+ tflt = var"#Type" (var"#type" = OneOf (:float_type , FloatType ()))
2211+ key = NamedColumn (name= " id" , var"#type" = tint)
2212+ val = NamedColumn (name= " weight" , var"#type" = tflt)
2213+ r1 = RelationId (id_low= 1 , id_high= 0 )
2214+ r2 = RelationId (id_low= 2 , id_high= 0 )
2215+ rel1 = TargetRelation (target_id= r1, values= [val])
2216+ rel2 = TargetRelation (target_id= r2, values= [val])
2217+
2218+ # Non-CDC shape: keys + the `relations` group populated.
2219+ g1 = TargetRelations (keys= [key], relations= [rel1], inserts= [], deletes= [])
2220+ g2 = TargetRelations (keys= [key], relations= [rel1], inserts= [], deletes= [])
2221+ g3 = TargetRelations (keys= [], relations= [rel1], inserts= [], deletes= []) # different keys
2222+ g4 = TargetRelations (keys= [key], relations= [rel2], inserts= [], deletes= []) # different relations
2223+ g5 = TargetRelations (keys= [key], relations= [rel1], inserts= [], deletes= [])
2224+
2225+ # Equality and inequality
2226+ @test g1 == g2
2227+ @test g1 != g3
2228+ @test g1 != g4
2229+ @test isequal (g1, g2)
2230+
2231+ # Hash consistency
2232+ @test hash (g1) == hash (g2)
2233+
2234+ # Reflexivity
2235+ @test g1 == g1
2236+ @test isequal (g1, g1)
2237+
2238+ # Symmetry
2239+ @test g1 == g2 && g2 == g1
2240+
2241+ # Transitivity
2242+ @test g1 == g2 && g2 == g5 && g1 == g5
2243+
2244+ # CDC shape: the `inserts`/`deletes` groups populated; each group participates in equality.
2245+ cdc1 = TargetRelations (keys= [key], relations= [], inserts= [rel1], deletes= [rel1])
2246+ cdc2 = TargetRelations (keys= [key], relations= [], inserts= [rel1], deletes= [rel1])
2247+ cdc3 = TargetRelations (keys= [key], relations= [], inserts= [rel2], deletes= [rel1]) # different inserts
2248+ cdc4 = TargetRelations (keys= [key], relations= [], inserts= [rel1], deletes= [rel2]) # different deletes
2249+
2250+ @test cdc1 == cdc2
2251+ @test cdc1 != cdc3
2252+ @test cdc1 != cdc4
2253+ @test hash (cdc1) == hash (cdc2)
2254+ @test isequal (cdc1, cdc2)
2255+
2256+ # A non-CDC grouping differs from a CDC grouping even when they share a relation.
2257+ @test g1 != cdc1
2258+ end
2259+
21312260@testitem " Equality for CSVData" tags= [:ring1 , :unit ] begin
21322261 using LogicalQueryProtocol: CSVData, CSVLocator, CSVConfig, GNFColumn, RelationId, var"#Type" , IntType
21332262 using ProtoBuf: OneOf
0 commit comments