# Commands covered: sound reverse
#

package require -exact snack 2.2

if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest
    namespace import ::tcltest::*
}

test reverse-1.1 {reverse command, ex1.wav} {
  set s [snack::sound snd -load ex1.wav]
  $s reverse -start 5000 -end 10000
  set res [list [$s sample 4999] [$s sample 5000] [$s sample 10000] [$s sample 10001]]
  $s destroy
  set res
} {6384 779 7443 514}

test reverse-1.2 {reverse command, stereo} {
  set s [snack::sound snd -channels 2]
  $s length 20000
  $s sample 5000 17 4711
  $s sample 10000 1 2
  $s reverse -start 5000 -end 10000
  set res [list [$s sample 4999] [$s sample 5000] [$s sample 10000] [$s sample 10001]]
  $s destroy
  set res
} {{0 0} {1 2} {17 4711} {0 0}}

test reverse-1.3 {reverse command, 3-channel} {
  set s [snack::sound snd -channels 3]
  $s length 20000
  $s sample 5000 17 4711 18
  $s sample 10000 1 2 3
  $s reverse -start 5000 -end 10000
  set res [list [$s sample 4999] [$s sample 5000] [$s sample 10000] [$s sample 10001]]
  $s destroy
  set res
} {{0 0 0} {1 2 3} {17 4711 18} {0 0 0}}

test reverse-1.4 {reverse command, even length} {
  set s [snack::sound snd -channels 2]
  $s length 4
  $s sample 0 1 2
  $s sample 1 3 4
  $s sample 2 5 6
  $s sample 3 7 8
  $s reverse -start 1 -end 2
  set res [list [$s sample 0] [$s sample 1] [$s sample 2] [$s sample 3]]
  $s destroy
  set res
} {{1 2} {5 6} {3 4} {7 8}}

test reverse-1.5 {reverse command, odd length} {
  set s [snack::sound snd -channels 2]
  $s length 5
  $s sample 0 1 2
  $s sample 1 3 4
  $s sample 2 5 6
  $s sample 3 7 8
  $s sample 4 9 0
  $s reverse -start 1 -end 3
  set res [list [$s sample 0] [$s sample 1] [$s sample 2] [$s sample 3] [$s sample 4]]
  $s destroy
  set res
} {{1 2} {7 8} {5 6} {3 4} {9 0}}

test reverse-1.6 {reverse command, missing -end option} {
  set s [snack::sound snd -load ex1.wav]
  catch {$s reverse -start 5000 -end} msg
  $s destroy
  set msg
} {No argument given for -end option}

test reverse-2.1 {reverse command, -progress option} {
  set res ""
  proc prog {msg frac} {
    lappend ::res $frac
  }
  set s [snack::sound snd -load ex1.wav]
  $s reverse -progress prog
  $s destroy
  set res
} {0.0 1.0}

# cleanup
::tcltest::cleanupTests
return
