Tasmota/lib/libesp32/berry/tests/map.be

33 lines
521 B
Python
Raw Normal View History

2022-01-18 21:13:40 +00:00
m = { 'a':1, 'b':3.5, 'c': "foo", 0:1}
assert(type(m) == 'instance')
assert(classname(m) == 'map')
# accessor
assert(m['a'] == 1)
assert(m['b'] == 3.5)
assert(m['c'] == 'foo')
assert(m[0] == 1)
# find
assert(m.find('a') == 1)
assert(m.find('z') == nil)
assert(m.find('z', 4) == 4)
# contains
assert(m.contains('a'))
assert(m.contains(0))
assert(!m.contains('z'))
assert(!m.contains())
# set
m['y'] = -1
assert(m['y'] == -1)
# remove
m={1:2}
m.remove(2)
assert(str(m) == '{1: 2}')
m.remove(1)
assert(str(m) == '{}')