xref: /freebsd/contrib/bc/scripts/sqrt_random.sh (revision f4fbc49d201f81c481a33fac6ba28e19faf96260)
1*f4fbc49dSStefan Eßer#! /bin/sh
2*f4fbc49dSStefan Eßer#
3*f4fbc49dSStefan Eßer# SPDX-License-Identifier: BSD-2-Clause
4*f4fbc49dSStefan Eßer#
5*f4fbc49dSStefan Eßer# Copyright (c) 2018-2023 Gavin D. Howard and contributors.
6*f4fbc49dSStefan Eßer#
7*f4fbc49dSStefan Eßer# Redistribution and use in source and binary forms, with or without
8*f4fbc49dSStefan Eßer# modification, are permitted provided that the following conditions are met:
9*f4fbc49dSStefan Eßer#
10*f4fbc49dSStefan Eßer# * Redistributions of source code must retain the above copyright notice, this
11*f4fbc49dSStefan Eßer#   list of conditions and the following disclaimer.
12*f4fbc49dSStefan Eßer#
13*f4fbc49dSStefan Eßer# * Redistributions in binary form must reproduce the above copyright notice,
14*f4fbc49dSStefan Eßer#   this list of conditions and the following disclaimer in the documentation
15*f4fbc49dSStefan Eßer#   and/or other materials provided with the distribution.
16*f4fbc49dSStefan Eßer#
17*f4fbc49dSStefan Eßer# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18*f4fbc49dSStefan Eßer# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*f4fbc49dSStefan Eßer# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*f4fbc49dSStefan Eßer# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21*f4fbc49dSStefan Eßer# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22*f4fbc49dSStefan Eßer# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23*f4fbc49dSStefan Eßer# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*f4fbc49dSStefan Eßer# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25*f4fbc49dSStefan Eßer# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26*f4fbc49dSStefan Eßer# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27*f4fbc49dSStefan Eßer# POSSIBILITY OF SUCH DAMAGE.
28*f4fbc49dSStefan Eßer#
29*f4fbc49dSStefan Eßer
30*f4fbc49dSStefan Eßerscriptdir=$(dirname "$0")
31*f4fbc49dSStefan Eßer
32*f4fbc49dSStefan Eßergnu=/usr/bin/bc
33*f4fbc49dSStefan Eßergdh=/usr/local/bin/bc
34*f4fbc49dSStefan Eßer
35*f4fbc49dSStefan Eßerif [ "$#" -lt 1 ]; then
36*f4fbc49dSStefan Eßer	printf 'err: must provide path to new bc\n'
37*f4fbc49dSStefan Eßer	exit 1
38*f4fbc49dSStefan Eßerfi
39*f4fbc49dSStefan Eßer
40*f4fbc49dSStefan Eßernew="$1"
41*f4fbc49dSStefan Eßershift
42*f4fbc49dSStefan Eßer
43*f4fbc49dSStefan Eßerunset BC_LINE_LENGTH && unset BC_ENV_ARGS
44*f4fbc49dSStefan Eßer
45*f4fbc49dSStefan Eßergdh_fail_file="sqrt_fails.bc"
46*f4fbc49dSStefan Eßernew_fail_file="new_sqrt_fails.bc"
47*f4fbc49dSStefan Eßer
48*f4fbc49dSStefan Eßerrm -rf "$gdh_fail_file"
49*f4fbc49dSStefan Eßerrm -rf "$new_fail_file"
50*f4fbc49dSStefan Eßer
51*f4fbc49dSStefan Eßerwhile [ true ]; do
52*f4fbc49dSStefan Eßer
53*f4fbc49dSStefan Eßer	tst=$("$gdh" -l "$scriptdir/sqrt_random.bc")
54*f4fbc49dSStefan Eßer	err=$?
55*f4fbc49dSStefan Eßer
56*f4fbc49dSStefan Eßer	if [ "$err" -ne 0 ]; then
57*f4fbc49dSStefan Eßer		printf 'err: failed to create test\n'
58*f4fbc49dSStefan Eßer		exit 2
59*f4fbc49dSStefan Eßer	fi
60*f4fbc49dSStefan Eßer
61*f4fbc49dSStefan Eßer	good=$(printf '%s\n' "$tst" | "$gnu" -l)
62*f4fbc49dSStefan Eßer
63*f4fbc49dSStefan Eßer	gdh_out=$(printf '%s\n' "$tst" | "$gdh" -l)
64*f4fbc49dSStefan Eßer	new_out=$(printf '%s\n' "$tst" | "$new" -l)
65*f4fbc49dSStefan Eßer
66*f4fbc49dSStefan Eßer	gdh_good=$(printf '%s == %s\n' "$good" "$gdh_out" | "$gnu")
67*f4fbc49dSStefan Eßer	new_good=$(printf '%s == %s\n' "$good" "$new_out" | "$gnu")
68*f4fbc49dSStefan Eßer
69*f4fbc49dSStefan Eßer	if [ "$gdh_good" -eq 0 ]; then
70*f4fbc49dSStefan Eßer		printf '%s\n' "$tst" >> "$gdh_fail_file"
71*f4fbc49dSStefan Eßer	fi
72*f4fbc49dSStefan Eßer
73*f4fbc49dSStefan Eßer	if [ "$new_good" -eq 0 ]; then
74*f4fbc49dSStefan Eßer		printf '%s\n' "$tst" >> "$new_fail_file"
75*f4fbc49dSStefan Eßer	fi
76*f4fbc49dSStefan Eßer
77*f4fbc49dSStefan Eßerdone
78