diff options
author | Steve J Donovan <steve.j.donovan@gmail.com> | 2017-07-17 16:38:27 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-17 16:38:27 +0300 |
commit | 6d108e6a699fbafd5dace1019d03f4b4b18231fa (patch) | |
tree | 9bda889c6c7383be5f76d1214e9a7bcce4962409 /tests | |
parent | 9a2b772a0498e6a4f9eb99469037f4f32bd84e03 (diff) | |
parent | c978982cf83923bdcd6c0136e07d465be7418ef9 (diff) |
Merge pull request #254 from greatwolf/list_coverage1.5.4
List coverage
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-pylib.lua | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/tests/test-pylib.lua b/tests/test-pylib.lua index c90a955..0d7bb19 100644 --- a/tests/test-pylib.lua +++ b/tests/test-pylib.lua @@ -9,12 +9,16 @@ s = List{1,2,3,4,5} -- test using: lua pylist.lua local lst = List() -lst:append(10) -lst:extend{20,30,40,50} +lst:append(20) +lst:extend{30,40,50} +lst:put(10) asserteq (lst,List{10,20,30,40,50}) +asserteq (lst:len(),5) lst:insert(3,11) lst:remove_value(40) asserteq (lst,List{10,20,11,30,50}) +asserteq (lst:contains(11),true) +asserteq (lst:contains(40),false) local q=lst:pop() asserteq( lst:index(30),4 ) asserteq( lst:count(10),1 ) @@ -34,14 +38,26 @@ asserteq (lst:slice(-4,-2),{20,30,40}) lst = List.range(0,9) seq = List{0,1,2,3,4,5,6,7,8,9} +asserteq(List.range(4),{1,2,3,4}) asserteq(List.range(0,8,2),{0,2,4,6,8}) asserteq(List.range(0,1,0.2),{0,0.2,0.4,0.6,0.8,1},1e-9) - asserteq(lst, seq) +asserteq(lst:reduce '+', 45) + +local part = seq:partition(function(v) return v % 2 end) +asserteq (part[0], List{0,2,4,6,8}) +asserteq (part[1], List{1,3,5,7,9}) + asserteq (List('abcd'),List{'a','b','c','d'}) +local caps = List() +List('abcd'):foreach(function(v) caps:append(v:upper()) end) +asserteq (caps,List{'A','B','C','D'}) ls = List{10,20,30,40} ls:slice_assign(2,3,{21,31}) asserteq (ls , List{10,21,31,40}) +asserteq (ls:remove(2), List{10,31,40}) +asserteq (ls:clear(), List{}) +asserteq (ls:len(), 0) -- strings --- require 'pl.stringx'.import() ---> convenient! @@ -52,6 +68,8 @@ s = 'here the dog is just a dog' assert (s:startswith('here')) assert (s:endswith('dog')) assert (s:count('dog') == 2) +assert (List.split(s) == List{'here', 'the', 'dog', 'is', 'just', 'a', 'dog'}) +assert (List.split('foo;bar;baz', ';') == List{'foo', 'bar', 'baz'}) s = ' here we go ' asserteq (s:lstrip() , 'here we go ') asserteq (s:rstrip() , ' here we go') |