]> git.proxmox.com Git - mirror_zfs.git/commitdiff
tests: include: math: simplify bc conditions, review $?
authorнаб <nabijaczleweli@nabijaczleweli.xyz>
Wed, 23 Mar 2022 16:54:07 +0000 (17:54 +0100)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Sat, 2 Apr 2022 00:59:24 +0000 (17:59 -0700)
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #13259

tests/zfs-tests/include/math.shlib

index 7ac59f279604052de074baf7e56c03d83fab1a47..38d9fecea7cfc7da4bda9a5b70aeac77de07e2bc 100644 (file)
@@ -30,17 +30,14 @@ function within_percent
        typeset percent=$3
 
        # Set $a or $b to $2 such that a >= b
-       [[ '1' = $(echo "if ($2 > $a) 1 else 0" | bc) ]] && a=$2 || b=$2
+       [ 1 -eq $(echo "$2 > $a" | bc) ] && a=$2 || b=$2
 
        # Prevent division by 0
        [[ $a =~ [1-9] ]] || return 1
 
        typeset p=$(echo "scale=2; $b * 100 / $a" | bc)
        log_note "Comparing $a and $b given $percent% (calculated: $p%)"
-       [[ '1' = $(echo "scale=2; if ($p >= $percent) 1 else 0" | bc) ]] && \
-           return 0
-
-       return 1
+       [ 1 -eq $(echo "scale=2; $p >= $percent" | bc) ]
 }
 
 #
@@ -61,9 +58,7 @@ function within_tolerance #value #target #tolerance
 
        typeset diff=$((abs(val - target)))
        log_note "Checking if $val is within +/-$tol of $target (diff: $diff)"
-       ((diff <= tol)) && return 0
-
-       return 1
+       ((diff <= tol))
 }
 
 #