assertEqual "toAssoc"
  (toAssoc [x, x, y, z])
  [(x, 2), (y, 1), (z, 1)]

assertEqual "toAssoc"
  (toAssoc [x, y, x])
  [(x, 1), (y, 1), (x, 1)]

assertEqual "fromAssoc"
  (fromAssoc [(x, 2), (y, 1)])
  [x, x, y]

assertEqual "assocList"
  (matchAll [(x, 2), (y, 1)] as assocList something with
    | $a :: _ -> a)
  [x]

assertEqual "assocList"
  (matchAll [(x, 3), (y, 2), (z, 1)] as assocList something with
    | ncons $a #2 $r -> (a, r))
  [(x, [(x, 1), (y, 2), (z, 1)])]

assertEqual "assocList"
  (matchAll [(x, 1), (y, 2), (z, 3)] as assocList something with
    | ncons $a #2 $r -> (a, r))
  []

assertEqual "assocList"
  (matchAll [(x, 3), (y, 2), (z, 1)] as assocList something with
    | ncons $a $n $r -> (a, n, r))
  [(x, 3, [(y, 2), (z, 1)])]

assertEqual "assocList"
  (matchAll [(x, 3), (y, 2), (z, 1)] as assocList something with
    | ncons $a $n $r -> (a, n, r))
  [(x, 3, [(y, 2), (z, 1)])]

assertEqual "assocMultiset"
  (matchAll [(x, 2), (y, 1)] as assocMultiset something with
    | $a :: _ -> a)
  [x, y]

assertEqual "assocMultiset"
  (matchAll [(x, 3), (y, 2), (z, 1)] as assocMultiset something with
    | ncons #z $n $r -> (n, r))
  [(1, [(x, 3), (y, 2)])]

assertEqual "assocMultiset"
  (matchAll [(x, 3), (y, 2), (z, 1)] as assocMultiset something with
    | ncons $a #2 $r -> (a, r))
  [(x, [(x, 1), (y, 2), (z, 1)]), (y, [(x, 3), (z, 1)])]

assertEqual "assocMultiset"
  (matchAll [(x, 3), (y, 2), (z, 1)] as assocMultiset something with
    | ncons #y #1 $r -> r)
  [[(x, 3), (y, 1), (z, 1)]]

assertEqual "assocMultiset"
  (matchAll [(x, 3), (y, 2), (z, 1)] as assocMultiset something with
    | ncons $a $n $r -> (a, n, r))
  [(x, 3, [(y, 2), (z, 1)]), (y, 2, [(x, 3), (z, 1)]), (z, 1, [(x, 3), (y, 2)])]

assertEqual "AC.intersect"
  (AC.intersect [(x, 2), (y, 1)] [(x, 1), (y, 2)])
  [(x, 1), (y, 1)]

assertEqual "AC.intersect"
  (AC.intersect [(x, 2), (y, 2)] [(x, 1), (y, 1)])
  [(x, 1), (y, 1)]

assertEqual "AC.intersect"
  (AC.intersect [(x, 1), (y, 1)] [(x, 2), (y, 2)])
  [(x, 1), (y, 1)]
