def test_sets(): """ Ensure that we can tokenize a set. """ objs = tokenize("#{1 2}") assert objs == [HySet([HyInteger(1), HyInteger(2)])] objs = tokenize("(bar #{foo bar baz})") assert objs == [ HyExpression([HySymbol("bar"), HySet(["foo", "bar", "baz"])]) ] objs = tokenize("#{(foo bar) (baz quux)}") assert objs == [ HySet([ HyExpression([HySymbol("foo"), HySymbol("bar")]), HyExpression([HySymbol("baz"), HySymbol("quux")]) ]) ] # Duplicate items in a literal set should be okay (and should # be preserved). objs = tokenize("#{1 2 1 1 2 1}") assert objs == [HySet([HyInteger(n) for n in [1, 2, 1, 1, 2, 1]])] assert len(objs[0]) == 6 # https://github.com/hylang/hy/issues/1120 objs = tokenize("#{a 1}") assert objs == [HySet([HySymbol("a"), HyInteger(1)])]
def test_sets(): """ Ensure that we can tokenize a set. """ objs = tokenize("#{1 2}") assert objs == [HySet([HyInteger(1), HyInteger(2)])] objs = tokenize("(bar #{foo bar baz})") assert objs == [ HyExpression([HySymbol("bar"), HySet(["foo", "bar", "baz"])]) ] objs = tokenize("#{(foo bar) (baz quux)}") assert objs == [ HySet([ HyExpression([HySymbol("foo"), HySymbol("bar")]), HyExpression([HySymbol("baz"), HySymbol("quux")]) ]) ]
def empty_set(p): return HySet([])
def t_set(p): return HySet(p[1])
from hy.models.set import HySet hyset = HySet([3, 1, 2, 2]) def test_set(): assert hyset == [1, 2, 3]