about summary refs log tree commit diff
path: root/Test/V03mathfunc.ztst
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2004-06-09 12:05:35 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2004-06-09 12:05:35 +0000
commitbeb6d322948d9efd00546f93635a069411170031 (patch)
tree832f3023903cc158dec73d6be214d8ba3a2f5429 /Test/V03mathfunc.ztst
parented76bafc5e6a5f1d5bbea469f38e0798e7b86459 (diff)
downloadzsh-beb6d322948d9efd00546f93635a069411170031.tar.gz
zsh-beb6d322948d9efd00546f93635a069411170031.tar.xz
zsh-beb6d322948d9efd00546f93635a069411170031.zip
c.f. 20034: zsh/mathfunc tests
Diffstat (limited to 'Test/V03mathfunc.ztst')
-rw-r--r--Test/V03mathfunc.ztst106
1 files changed, 106 insertions, 0 deletions
diff --git a/Test/V03mathfunc.ztst b/Test/V03mathfunc.ztst
new file mode 100644
index 000000000..d011a1644
--- /dev/null
+++ b/Test/V03mathfunc.ztst
@@ -0,0 +1,106 @@
+# Tests for the module zsh/mathfunc
+
+%prep
+  if ( zmodload -i zsh/mathfunc ) >/dev/null 2>&1; then
+    zmodload -i zsh/mathfunc
+  else
+    ZTST_unimplemented="The module zsh/mathfunc is not available."
+  fi
+
+%test
+  # -g makes pi available in later tests
+  float -gF 5 pi
+  (( pi = 4 * atan(1.0) ))
+  print $pi
+0:Basic operation with atan
+>3.14159
+
+  float -F 5 result
+  (( result = atan(3,2) ))
+  print $result
+0:atan with two arguments
+>0.98279
+
+  print $(( atan(1,2,3) ))
+1:atan can't take three arguments
+?(eval):1: wrong number of arguments: atan(1,2,3)
+
+  float r1=$(( rand48() ))
+  float r2=$(( rand48() ))
+  float r3=$(( rand48() ))
+  # Yes, this is a floating point equality test like they tell
+  # you not to do.  As the pseudrandom sequence is deterministic,
+  # this is the right thing to do in this case.
+  if (( r1 == r2 )); then
+    print "Seed not updated correctly the first time"
+  else
+    print "First two random numbers differ, OK"
+  fi
+  if (( r2 == r3 )); then
+    print "Seed not updated correctly the second time"
+  else
+    print "Second two random numbers differ, OK"
+  fi
+0:rand48 with default initialisation
+F:This test fails if your math library doesn't have erand48().
+>First two random numbers differ, OK
+>Second two random numbers differ, OK
+
+  seed=f45677a6cbe4
+  float r1=$(( rand48(seed) ))
+  float r2=$(( rand48(seed) ))
+  seed2=$seed
+  float r3=$(( rand48(seed) ))
+  float r4=$(( rand48(seed2) ))
+  # Yes, this is a floating point equality test like they tell
+  # you not to do.  As the pseudrandom sequence is deterministic,
+  # this is the right thing to do in this case.
+  if (( r1 == r2 )); then
+    print "Seed not updated correctly the first time"
+  else
+    print "First two random numbers differ, OK"
+  fi
+  if (( r2 == r3 )); then
+    print "Seed not updated correctly the second time"
+  else
+    print "Second two random numbers differ, OK"
+  fi
+  if (( r3 == r4 )); then
+    print "Identical seeds generate identical numbers, OK"
+  else
+    print "Indeterminate result from identical seeds"
+  fi
+0:rand48 with pre-generated seed
+F:This test fails if your math library doesn't have erand48().
+>First two random numbers differ, OK
+>Second two random numbers differ, OK
+>Identical seeds generate identical numbers, OK
+
+  float -F 5 pitest
+  (( pitest = 4.0 * atan(1) ))
+  # This is a string test of the output to 5 digits.
+  if [[ $pi = $pitest ]]; then
+    print "OK, atan on an integer seemed to work"
+  else
+    print "BAD: got $pitest instead of $pi"
+  fi
+0:Conversion of arguments from integer
+>OK, atan on an integer seemed to work
+
+  float -F 5 result
+  typeset str
+  for str in 0 0.0 1 1.5 -1 -1.5; do
+    (( result = abs($str) ))
+    print $result
+  done
+0:Use of abs on various numbers
+>0.00000
+>0.00000
+>1.00000
+>1.50000
+>1.00000
+>1.50000
+
+   print $(( sqrt(-1) ))
+1:Non-negative argument checking for square roots.
+?(eval):1: math: argument to sqrt out of range