All pastes #729872 Raw Edit

Something

public text v1 · immutable
·published 2007-10-08 15:09 UTC
rendered paste body
alias mid_test {
  var %error 0,%x 1
  while (%x < 1000) {
    var %1 $(,$!+ $str($!rand(1,5) $!+ $chr(32),10)),%2 $r(1,10),%3 $r(1,10)
    if $mid_(%1,%2,%3) != $mid(%1,%2,%3) { echo $color(info) -a $!$mid_(%1,%2,%3) returns $v1 -- It should return $v2 | inc %error }
    inc %x
  }
  if ($mid_(hello,85943580934,0) != 0) { echo $color(info) -a * $!$mid_(hello,85943580934,0) returns $v1 -- It should return $v2 | inc %error }
  if ($mid_(hello,2,0) != 4) { echo $color(info) -a * $!$mid_(hello,2,0) returns $v1 -- It should return $v2 | inc %error }
  if ($mid_(hello,1,0) != 5) { echo $color(info) -a * $!$mid_(hello,1,0) returns $v1 -- It should return $v2 | inc %error }
  if ($mid_(00000,1,1) != 0) { echo $color(info) -a * $!$mid_(00000,1,1) returns $v1 -- It should return $v2 | inc %error }
  echo $iif(%error,4,3) -a * $!Mid_ test completed with %error errors 
}
alias filter_test {
  var %error 0
  if ($filter(hello,he) != he) { echo $color(info) -a * $!$filter(hello,he) returns $v1 -- It should return $v2 | inc %error }
  if ($filter(hello,he,h) != he)  { echo $color(info) -a * $!$filter(hello,he,h) returns $v1 -- It should return $v2 | inc %error }
  if ($filter(hello,l) != ll)  { echo $color(info) -a * $!$filter(hello,l) returns $v1 -- It should return $v2 | inc %error }
  if ($filter(hello,h,e) != he)  { echo $color(info) -a * $!$filter(hello,h,e) returns $v1 -- It should return $v2 | inc %error }
  if ($filter(hello,a,b,c) != $null)  { echo $color(info) -a * $!filter(hello,a,b,c) returns $v1 -- It should return $v2 | inc %error }
  if ($filter(hello,l,l) != ll)  { echo $color(info) -a * $!filter(hello,l,l) returns $v1 -- It should return $v2 | inc %error }
  if ($filter(test,rt,r,o) != $null)  { echo $color(info) -a * $!filter(test,rt,r,o) returns $v1 -- It should return $v2 | inc %error }
  if ($filter(t e o,te,oo) != $null)  { echo $color(info) -a * $!filter(t e o,te,oo) returns $v1 -- It should return $v2 | inc %error }
  echo $iif(%error,4,3) -a * $!filter test completed with %error errors 
}
alias whatday_test {
  var %error 0
  if ($whatday(1) != Monday) { echo $color(info) -a * $!whatday(1) returns $v1 -- It should return $v2 | inc %error }
  if ($whatday(2) != Tuesday) { echo $color(info) -a * $!whatday(2) returns $v1 -- It should return $v2 | inc %error }
  if ($whatday(3) != Wednesday) { echo $color(info) -a * $!whatday(3) returns $v1 -- It should return $v2 | inc %error }
  if ($whatday(4) != Thursday) { echo $color(info) -a * $!whatday(4) returns $v1 -- It should return $v2 | inc %error }
  if ($whatday(5) != Friday) { echo $color(info) -a * $!whatday(5) returns $v1 -- It should return $v2 | inc %error }
  if ($whatday(6) != Saturday) { echo $color(info) -a * $!whatday(6) returns $v1 -- It should return $v2 | inc %error }
  if ($whatday(7) != Sunday) { echo $color(info) -a * $!whatday(7) returns $v1 -- It should return $v2 | inc %error }
  if ($whatday(8) != Monday) { echo $color(info) -a * $!whatday(8) returns $v1 -- It should return $v2 | inc %error }
  if ($whatday(364) != Sunday) { echo $color(info) -a * $!whatday(364) returns $v1 -- It should return $v2 | inc %error }
  if ($whatday(365) != Monday) { echo $color(info) -a * $!whatday(365) returns $v1 -- It should return $v2 | inc %error }
  echo $iif(%error,4,3) -a * $!Whatday test completed with %error errors 
}
alias randomtok_test {
  var %x 0,%y 1
  unset %randomtok.*
  while (%x < 1000) {
    inc %rt. $+ $replace($randomtok(hello.how.are.you today,46),$chr(32),+)
    inc %x
  }
  var %analyse $calc((%rt.hello - 250) ^ 2 + (%rt.how - 250) ^ 2 + (%rt.are - 250) ^ 2 + (%rt.you+today - 250) ^ 2)
  echo $iif(%analyse > 2500,7,$iif(%analyse > 3500,4,3)) -a * $!randomtok Results (should be approx 250 per word) - Hello: %rt.hello - How: %rt.how - are: %rt.are - you today: %rt.you+today 
  unset %rt.hello %rt.how %rt.are %rt.you+today
  while ($var(%rt.*,%y)) {
    var %invalid $mid($v1,12) $+ : $(,$v1)
    inc %y
  }
  if (%invalid) echo 4 -a * $!randomtok Invalid Results (Should not have occured) - %invalid
}

alias ascii_test {
  var %error 0
  if ($ascii(a) != 97) { echo $color(info) -a * $!ascii(a) returns $v1 -- It should return $v2 | inc %error }
  if ($ascii(A) != 65) { echo $color(info) -a * $!ascii(A) returns $v1 -- It should return $v2 | inc %error }
  if ($ascii(hellohowareyou) != 10410110810811110411111997114101121111117) { echo $color(info) -a * $!ascii(hellohowareyou) returns $v1 -- It should return $v2 | inc %error }
  echo $iif(%error,4,3) -a * $!ascii test completed with %error errors  
}
alias hex_test {
  var %error 0
  if ($hex(0) != 0) { echo $color(info) -a * $!hex(0) returns $v1 -- It should return $v2 | inc %error }
  if ($hex(9) != 9) { echo $color(info) -a * $!hex(9) returns $v1 -- It should return $v2 | inc %error }
  if ($hex(11) != 17) { echo $color(info) -a * $!hex(11) returns $v1 -- It should return $v2 | inc %error }
  if ($hex(F) != 15) { echo $color(info) -a * $!hex(F) returns $v1 -- It should return $v2 | inc %error }
  if ($hex(A) != 10) { echo $color(info) -a * $!hex(A) returns $v1 -- It should return $v2 | inc %error }
  if ($hex(10F) != 271) { echo $color(info) -a * $!hex(10F) returns $v1 -- It should return $v2 | inc %error }
  if ($hex(ABCDEF) != 11259375) { echo $color(info) -a * $!hex(ABCDEF) returns $v1 -- It should return $v2 | inc %error }
  echo $iif(%error,4,3) -a * $!hex test completed with %error errors 
}


alias test {
  mid_test
  filter_test
  whatday_test
  randomtok_test
  ascii_test
  hex_test
}