needs assertion'
needs array'

with assertion'

[ [ "passed" ] [ "failed" ] if "%s\n" puts ] is postCond

variable a

^array'new{ 10 20 30 } !a
: a0 ( - )
  "Testing ^array'new{ : " puts
  @a     @  3 assert=
  @a 1 + @ 10 assert=
  @a 2 + @ 20 assert=
  @a 3 + @ 30 assert= ; assertion

: a1 ( - )
  "Testing ^array'fromQuote : " puts
  [ 10 20 30 ] ^array'fromQuote !a
  @a 1 + @ 10 assert=
  @a 2 + @ 20 assert=
  @a 3 + @ 30 assert= ; assertion

: a2 ( - )
  "Testing ^array'toQuote : " puts
  [ 10 20 30 ] ^array'fromQuote ^array'toQuote do
  30 assert=
  20 assert=
  10 assert= ; assertion

: a3 ( - )
  "Testing ^array'map : " puts
  [ 10 20 30 ] ^array'fromQuote !a
  @a [ 10 / 2 + ] ^array'map
  @a 1 + @ 3 assert=
  @a 2 + @ 4 assert=
  @a 3 + @ 5 assert= ; assertion

: a4 ( - )
  "Testing ^array'in? : " puts
  [ 10 20 30 ] ^array'fromQuote !a
   1 @a ^array'in? 0 assert=
  20 @a ^array'in? -1 assert= ; assertion

: a5 ( - )
  "Testing ^array'stringIn? : " puts
  [ "test" "for" "strings" ] ^array'fromQuote !a
      "foo" @a ^array'stringIn? 0 assert=
  "strings" @a ^array'stringIn? -1 assert= ; assertion

: a6 ( - )
  "Testing ^array'fromQuote : " puts
  [ 10 20 30 ] ^array'fromQuote !a
  @a ^array'reverse
  @a 1 + @ 30 assert=
  @a 2 + @ 20 assert=
  @a 3 + @ 10 assert= ; assertion

: a7 ( - )
  "Testing ^array'apply : " puts
  [ 10 20 30 ] ^array'fromQuote !a
  @a [ 2 - ] ^array'apply
  28 assert= 18 assert= 8 assert= ; assertion

: a8 ( - )
  "Testing ^array'append : " puts
  [ 10 20 30 ] ^array'fromQuote
  [ 40 50 60 ] ^array'fromQuote ^array'append !a
  @a 1 + @ 10 assert=
  @a 2 + @ 20 assert=
  @a 3 + @ 30 assert=
  @a 4 + @ 40 assert=
  @a 5 + @ 50 assert=
  @a 6 + @ 60 assert= ; assertion

: a9  ( - )
  "Testing ^array'sort: : " puts
  [ 30 10 20 ] ^array'fromQuote !a
  @a ^array'sort:bubble
  @a 1 + @ 10 assert=
  @a 2 + @ 20 assert=
  @a 3 + @ 30 assert=

  [ 0 -10 30 10 86 20 ] ^array'fromQuote !a
  @a ^array'sort:bubble
  @a 1 + @ -10 assert=
  @a 2 + @   0 assert=
  @a 3 + @  10 assert=
  @a 4 + @  20 assert=
  @a 5 + @  30 assert=
  @a 6 + @  86 assert= ; assertion

: go ( - )
  cr a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 bye ;

go
