@@ -108,4 +108,38 @@ defmodule MapSetTest do
108108 list = MapSet . to_list ( MapSet . new ( 5 .. 120 ) )
109109 assert Enum . sort ( list ) == Enum . to_list ( 5 .. 120 )
110110 end
111+
112+ test "MapSet v1 compatibility" do
113+ result = 1 .. 5 |> map_set_v1 ( ) |> MapSet . new ( )
114+ assert MapSet . equal? ( result , MapSet . new ( 1 .. 5 ) )
115+
116+ result = MapSet . put ( map_set_v1 ( 1 .. 5 ) , 6 )
117+ assert MapSet . equal? ( result , MapSet . new ( 1 .. 6 ) )
118+
119+ result = MapSet . union ( map_set_v1 ( 1 .. 5 ) , MapSet . new ( 6 .. 10 ) )
120+ assert MapSet . equal? ( result , MapSet . new ( 1 .. 10 ) )
121+
122+ result = MapSet . intersection ( map_set_v1 ( 1 .. 10 ) , MapSet . new ( 6 .. 15 ) )
123+ assert MapSet . equal? ( result , MapSet . new ( 6 .. 10 ) )
124+
125+ result = MapSet . difference ( map_set_v1 ( 1 .. 10 ) , MapSet . new ( 6 .. 50 ) )
126+ assert MapSet . equal? ( result , MapSet . new ( 1 .. 5 ) )
127+
128+ result = MapSet . delete ( map_set_v1 ( 1 .. 10 ) , 1 )
129+ assert MapSet . equal? ( result , MapSet . new ( 2 .. 10 ) )
130+
131+ assert MapSet . size ( map_set_v1 ( 1 .. 5 ) ) == 5
132+ assert MapSet . to_list ( map_set_v1 ( 1 .. 5 ) ) == Enum . to_list ( 1 .. 5 )
133+
134+ assert MapSet . disjoint? ( map_set_v1 ( 1 .. 5 ) , MapSet . new ( 10 .. 15 ) )
135+ refute MapSet . disjoint? ( map_set_v1 ( 1 .. 5 ) , MapSet . new ( 5 .. 10 ) )
136+
137+ assert MapSet . subset? ( map_set_v1 ( 3 .. 7 ) , MapSet . new ( 1 .. 10 ) )
138+ refute MapSet . subset? ( map_set_v1 ( 7 .. 12 ) , MapSet . new ( 1 .. 10 ) )
139+ end
140+
141+ defp map_set_v1 ( enumerable ) do
142+ map = Map . new ( 1 .. 5 , & { & 1 , true } )
143+ % { __struct__: MapSet , map: map }
144+ end
111145end
0 commit comments