Advertisement
devinteske

More bash float testing

Jan 17th, 2016
592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.25 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. . float.subr || exit
  4.     # https://raw.githubusercontent.com/FrauBSD/FrauBSD/master/usr.sbin/bsdconfig/share/float.subr
  5.  
  6. N=1
  7. EXIT=${SUCCESS:-0}
  8. HR="--------------------"
  9. VERBOSE=
  10.  
  11. hrprint() { printf "%s #%03u %s\n" "$HR" "$N" "$HR"; }
  12. hr() { [ "$VERBOSE" ] && hrprint; }
  13.  
  14. xt()
  15. {
  16.     local float1="$1" float2="$3" testvalue="$5" result=
  17.     hr
  18.     f_float "$float1" + "$float2" result
  19.     if [ "$result" = "$testvalue" ]; then
  20.         [ "$VERBOSE" ] && echo "$float1 + $float2 == $result"
  21.     else
  22.         [ "$VERBOSE" ] || hrprint
  23.         echo "$float1 + $float2 == $result [bad; expected $testvalue]"
  24.         EXIT=${FAILURE:-1}
  25.     fi
  26.     N=$(( $N + 1 ))
  27. }
  28.  
  29. : 001 ; xt 0.009 + 0.019 == 0.028
  30. : 002 ; xt 0.001 + 0.019 == 0.02
  31. : 003 ; xt 0.090 + 0.019 == 0.109
  32. : 004 ; xt 0.990 + 0.019 == 1.009
  33. : 005 ; xt 0.990 + 0.01 == 1.0
  34. : 006 ; xt 0.99 + 0.01 == 1.0
  35. : 007 ; xt 0.990 + 0.01 == 1.0
  36. : 008 ; xt 0.090 + 0.019 == 0.109
  37. : 009 ; xt 0.001 + 0.019 == 0.02
  38. : 010 ; xt 0.009 + 0.019 == 0.028
  39. : 011 ; xt 0.009 + 0.09 == 0.099
  40. : 012 ; xt 0.005 + 0.01 == 0.015
  41. : 013 ; xt 0.005 + 0.010 == 0.015
  42. : 014 ; xt 0.05 + 0.010 == 0.06
  43. : 015 ; xt 0.5 + 0.010 == 0.51
  44. : 016 ; xt 0.5 + 0.01 == 0.51
  45. : 017 ; xt 0.5 + 0.25 == 0.75
  46. : 018 ; xt 0.1 + 0.5 == 0.6
  47. : 019 ; xt 768614336404564650 + 1 == 768614336404564651
  48. : 020 ; xt 0.768614336404564650 + 0.300000000000000001 == 1.068614336404564651
  49. : 021 ; xt 58924.2049 + 123.66 == 59047.8649
  50. : 022 ; xt 1 + 1 == 2
  51. : 023 ; xt -1 + -2 == -3
  52. : 024 ; xt -2 + 1 == -1
  53. : 025 ; xt -1 + 1 == 0
  54. : 026 ; xt 1 + -1 == 0
  55. : 027 ; xt 1 + -2 == -1
  56. : 028 ; xt -2 + -1 == -3
  57. : 029 ; xt 0 + 0 == 0
  58. : 030 ; xt 0.0 + 1 == 1.0
  59. : 031 ; xt .0 + 1 == 1.0
  60. : 032 ; xt .0 + 0 == 0.0
  61. : 033 ; xt .0 + .0 == 0.0
  62. : 034 ; xt . + . == 0
  63. : 035 ; xt a + b == 0
  64. : 036 ; xt a + . == 0
  65. : 037 ; xt a + 0.0 == 0.0
  66. : 038 ; xt a + .0 == 0.0
  67. : 039 ; xt 0 + 0.00 = 0.0
  68. : 040 ; xt -2 + -1 == -3
  69. : 041 ; xt 1 + -2 == -1
  70. : 042 ; xt 1 + -1 == 0
  71. : 043 ; xt -1 + 1 == 0
  72. : 044 ; xt -2 + 1 == -1
  73. : 045 ; xt -1 + -2 == -3
  74. : 046 ; xt 1 + 0.0 == 1.0
  75. : 047 ; xt 1 + .0 == 1.0
  76. : 048 ; xt 0 + .0 == 0.0
  77. : 049 ; xt . + a == 0
  78. : 050 ; xt 0.0 + a == 0.0
  79. : 051 ; xt .0 + a == 0.0
  80. : 052 ; xt 0.00 + 0 = 0.0
  81. : 053 ; xt 0.01 + 256.000000000000000000010 == 256.01000000000000000001
  82.  
  83. exit $EXIT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement