1# SPDX-License-Identifier: BSD-2-Clause 2# 3# Copyright (c) 2017 Alan Somers 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions 7# are met: 8# 1. Redistributions of source code must retain the above copyright 9# notice, this list of conditions and the following disclaimer. 10# 2. Redistributions in binary form must reproduce the above copyright 11# notice, this list of conditions and the following disclaimer in the 12# documentation and/or other materials provided with the distribution. 13# 14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24# SUCH DAMAGE. 25# 26 27atf_test_case base16_input 28base16_input_head() 29{ 30 atf_set "descr" "Input hexadecimal numbers" 31} 32base16_input_body() 33{ 34 cat > input.dc << EOF 354k # set scale to 4 decimal places 3616i # switch to base 16 370 p 3810 p 391 p 401. p # The '.' should have no effect 411.0 p # Unlike with decimal, should not change the result's scale 42.8 p # Can input fractions 43# Check that we can input fractions that need more scale in base 10 than in 16 44# See PR 206230 45.1 p 46.10 p # Result should be .0625, with scale=4 47.01 p # Result should be truncated to scale=4 488k # Increase scale to 8 places 49.01 p # Result should be exact again 500.1 p # Leading zeros are ignored 5100.1 p # Leading zeros are ignored 52EOF 53 dc input.dc > output.txt 54 cat > expect.txt << EOF 550 5616 571 581 591 60.5 61.0625 62.0625 63.0039 64.00390625 65.0625 66.0625 67EOF 68 atf_check cmp expect.txt output.txt 69} 70 71atf_test_case base3_input 72base3_input_head() 73{ 74 atf_set "descr" "Input ternary numbers" 75} 76base3_input_body() 77{ 78 cat > input.dc << EOF 794k # 4 digits of precision 803i # Base 3 input 810 p 821 p 8310 p 84.1 p # Repeating fractions get truncated 85EOF 86dc input.dc > output.txt 87cat > expect.txt << EOF 880 891 903 91.3333 92EOF 93 atf_check cmp expect.txt output.txt 94} 95 96atf_init_test_cases() 97{ 98 atf_add_test_case base16_input 99 atf_add_test_case base3_input 100} 101