numtools

perform numerical operations on vectors and matrices in unix pipes
git clone git://src.adamsgaard.dk/numtools # fast
git clone https://src.adamsgaard.dk/numtools.git # slow
Log | Files | Refs | README | LICENSE Back to index

commit 9f42d7162848c39ca7c71a57aa9e2d9a5fd3c5e3
parent 8787e852ca96ee9c18d4ed1a45016996e464940a
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Wed, 11 May 2022 15:57:48 +0200

add regression tests and sync man examples to current output

Diffstat:
Acondfail | 7+++++++
Mmax.1 | 2+-
Mmean.1 | 2+-
Mmin.1 | 2+-
Mrandcounts.1 | 2+-
Mrandnum.1 | 2+-
Mrange.1 | 2+-
Mrangetest.1 | 8++++----
Mstddev.1 | 2+-
Mstdvar.1 | 2+-
Msum.1 | 2+-
Atest.sh | 95+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12 files changed, 115 insertions(+), 13 deletions(-)

diff --git a/condfail b/condfail @@ -0,0 +1,7 @@ +#!/usr/bin/awk -f +BEGIN { + if (ARGV[1] < 1.5) + exit 0 + else + exit 1 +} diff --git a/max.1 b/max.1 @@ -24,7 +24,7 @@ Separate output values by The default delimiter is tab characters. .It Fl n Do not print a newline after the final value. -.It Fl p prec +.It Fl p Ar prec Print the output values with .Ar prec digits of precision. diff --git a/mean.1 b/mean.1 @@ -23,7 +23,7 @@ Separate output values by The default delimiter is tab characters. .It Fl n Do not print a newline after the final value. -.It Fl p prec +.It Fl p Ar prec Print the output values with .Ar prec digits of precision. diff --git a/min.1 b/min.1 @@ -24,7 +24,7 @@ Separate output values by The default delimiter is tab characters. .It Fl n Do not print a newline after the final value. -.It Fl p prec +.It Fl p Ar prec Print the output values with .Ar prec digits of precision. diff --git a/randcounts.1 b/randcounts.1 @@ -46,7 +46,7 @@ The default is 1. Repeat the binning several times, with one realization per line of output. .It Fl R Show the output as ratios (in the range [0;1]) instead of counts. -.It Fl p prec +.It Fl p Ar prec Print the output values with .Ar prec digits of precision. diff --git a/randnum.1 b/randnum.1 @@ -49,7 +49,7 @@ The default delimiter is newlines. Do not print a newline after the final value. .It Fl N num Number of random points to generate. -.It Fl p prec +.It Fl p Ar prec Print the output values with .Ar prec digits of precision. diff --git a/range.1 b/range.1 @@ -66,7 +66,7 @@ Do not print a newline after the final value. .It Fl N Ar num Number of values to produce within the specified range. The default is 10. -.It Fl p prec +.It Fl p Ar prec Print the output values with .Ar prec digits of precision. diff --git a/rangetest.1 b/rangetest.1 @@ -54,8 +54,8 @@ shows all parameter values which result in a successful invocation: .Dl 0 .Dl 1.25 .Dl 1.40625 -.Dl 1.48438 -.Dl 1.49414 +.Dl 1.484375 +.Dl 1.494140625 .Pp The values associated with failed invocations are printed in standard error: .Dl $ rangetest './condfail @VAL@' 0.0 10.0 >/dev/null @@ -64,8 +64,8 @@ The values associated with failed invocations are printed in standard error: .Dl 2.5 .Dl 1.875 .Dl 1.5625 -.Dl 1.52344 -.Dl 1.50391 +.Dl 1.5234375 +.Dl 1.50390625 .Pp While the above values all result in a successful invocation of .Ar cmd , diff --git a/stddev.1 b/stddev.1 @@ -26,7 +26,7 @@ Separate output values by The default delimiter is tab characters. .It Fl n Do not print a newline after the final value. -.It Fl p prec +.It Fl p Ar prec Print the output values with .Ar prec digits of precision. diff --git a/stdvar.1 b/stdvar.1 @@ -26,7 +26,7 @@ Separate output values by The default delimiter is tab characters. .It Fl n Do not print a newline after the final value. -.It Fl p prec +.It Fl p Ar prec Print the output values with .Ar prec digits of precision. diff --git a/sum.1 b/sum.1 @@ -23,7 +23,7 @@ Separate output values by The default delimiter is tab characters. .It Fl n Do not print a newline after the final value. -.It Fl p prec +.It Fl p Ar prec Print the output values with .Ar prec digits of precision. diff --git a/test.sh b/test.sh @@ -0,0 +1,95 @@ +#!/bin/sh + +strtest() +{ + if ! test "$2" = "$3" + then + printf 'FAIL: %s: %s != %s\n' "$1" "$2" "$3" + fi +} + +strtest range_man "0.20000000000000001 +0.40000000000000002 +0.60000000000000009 +0.80000000000000004" "$(./range -be -N 4)" +strtest range_man "1 2 3" "$(./range -d' ' -N 3 1 3)" +strtest range_man "1 +10 +100" "$(./range -l -N 3 0 2)" +strtest range_man "-2 +-1.5 +-1" "$(./range -N 3 -- -2 -1)" +strtest range "0 +0.1111111111111111 +0.22222222222222221 +0.33333333333333331 +0.44444444444444442 +0.55555555555555558 +0.66666666666666663 +0.77777777777777768 +0.88888888888888884 +1" "$(./range)" +strtest range "0 0.33333333333333331 0.66666666666666663 1" "$(./range -n -d' ' -N 4)" +strtest range "0 0.33 0.67 1" "$(./range -n -p 2 -d' ' -N 4)" +strtest range "0.25 0.5 0.75 1" "$(./range -b -p 2 -d' ' -N 4)" +strtest range "0 0.25 0.5 0.75" "$(./range -e -p 2 -d' ' -N 4)" +strtest range_man "0 +0.33333333333333331 +0.66666666666666663 +1" "$(./range -N 4)" + +strtest max_man "4 5 6" "$(printf '1\t2\t3\n4\t5\t6\n' | ./max)" +strtest max "4,5,6" "$(printf '1\t2\t3\n4\t5\t6\n' | ./max -d',')" +strtest max "1" "$(./range | ./max)" +strtest max "0.90909090909090917" "$(./range -be | ./max)" +strtest max "0.909" "$(./range -be | ./max -p 3 )" + +strtest mean_man "2.5 3.5 4.5" "$(printf '1\t2\t3\n4\t5\t6\n' | ./mean)" +strtest mean "2.5,3.5,4.5" "$(printf '1\t2\t3\n4\t5\t6\n' | ./mean -d',')" +strtest mean "0.5" "$(./range | ./mean)" +strtest mean "0.5" "$(./range -be | ./mean)" +strtest mean "0.5" "$(./range -be | ./mean -p 3 )" + +strtest min_man "1 2 3" "$(printf '1\t2\t3\n4\t5\t6\n' | ./min)" +strtest min "1,2,3" "$(printf '1\t2\t3\n4\t5\t6\n' | ./min -d',')" +strtest min "0" "$(./range | ./min)" +strtest min "0.090909090909090912" "$(./range -be | ./min)" +strtest min "0.0909" "$(./range -be | ./min -p 3 )" + +strtest rangetest_man "0 +1.25 +1.40625 +1.484375 +1.494140625" "$(./rangetest './condfail @VAL@' 0.0 10.0 2>/dev/null)" + +strtest rangetest_man "10 +5 +2.5 +1.875 +1.5625 +1.5234375 +1.50390625" "$(./rangetest './condfail @VAL@' 0.0 10.0 2>&1 >/dev/null)" + +strtest stddev_man "2.1908902300206643" "$(printf '10\n8\n10\n8\n8\n4\n' | ./stddev)" +strtest stddev_man "2" "$(printf '10\n8\n10\n8\n8\n4\n' | ./stddev -u)" +strtest stddev "2.2" "$(printf '10\n8\n10\n8\n8\n4\n' | ./stddev -p 2)" +strtest stddev "2.1213203435596424 2.1213203435596424 2.1213203435596424" "$(printf '1\t2\t3\n4\t5\t6\n' | ./stddev)" +strtest stddev "2.1 2.1 2.1" "$(printf '1\t2\t3\n4\t5\t6\n' | ./stddev -p 2)" +strtest stddev "2.1,2.1,2.1" "$(printf '1\t2\t3\n4\t5\t6\n' | ./stddev -p 2 -d',' )" + +strtest stdvar_man "4.7999999999999998" "$(printf '10\n8\n10\n8\n8\n4\n' | ./stdvar)" +strtest stdvar_man "4" "$(printf '10\n8\n10\n8\n8\n4\n' | ./stdvar -u)" +strtest stdvar "4.8" "$(printf '10\n8\n10\n8\n8\n4\n' | ./stdvar -p 2)" +strtest stdvar "4.5 4.5 4.5" "$(printf '1\t2\t3\n4\t5\t6\n' | ./stdvar)" +strtest stdvar "4.5 4.5 4.5" "$(printf '1\t2\t3\n4\t5\t6\n' | ./stdvar -p 2)" +strtest stdvar "4.5,4.5,4.5" "$(printf '1\t2\t3\n4\t5\t6\n' | ./stdvar -p 2 -d',' )" + +strtest sum_man "5 7 9" "$(printf '1\t2\t3\n4\t5\t6\n' | ./sum)" +strtest sum "48" "$(printf '10\n8\n10\n8\n8\n4\n' | ./sum)" +strtest sum "5e+01" "$(printf '10\n8\n10\n8\n8\n4\n' | ./sum -p 1)" +strtest sum "5 7 9" "$(printf '1\t2\t3\n4\t5\t6\n' | ./sum)" +strtest sum "5,7,9" "$(printf '1\t2\t3\n4\t5\t6\n' | ./sum -d',' )" + +strtest transpose_man "1 4 +2 5 +3 6" "$(printf '1\t2\t3\n4\t5\t6\n' | ./transpose)"