def test_to(): stm = Array.range(5, 8).to_stream() assert type(stm) is Stream assert stm.to_list() == [5, 6, 7]
def test_slice(): alist = Array.range(10, 20) assert alist[:5] == Array.range(10, 15) assert alist[-3:] == Array.range(17, 20) assert alist.take(5) == Array.range(10, 15) assert alist.drop(3) == Array.range(13, 20) assert alist.drop(10) == Array() assert alist.drop(20) == Array() assert alist.takeright(3) == Array.range(17, 20) assert alist.dropright(3) == Array.range(10, 17) assert alist.tail() == Array.range(11, 20) assert alist.butlast() == Array.range(10, 19) assert alist.slice(3, 5) == Array.range(13, 15) assert alist[3:5] == Array.range(13, 15) def less_than_15(n): return n < 15 assert alist.takewhile(less_than_15) == Array.range(10, 15) assert alist.dropwhile(less_than_15) == Array.range(15, 20)
def test_init(): alist = Array([1, 2, 3]) assert alist == Array.range(1, 4) alist = Array((1, 2, 3)) assert alist == Array.range(1, 4)