120 lines
3.0 KiB
Bash
120 lines
3.0 KiB
Bash
#!/bin/sh
|
|
|
|
test_print() {
|
|
PROGRAM="$PWD/build/dc"
|
|
EXPECTED="5"
|
|
ACTUAL=$("$PROGRAM" -e '5 p')
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
|
|
# Test empty stack
|
|
EXPECTED="Cannot print empty stack"
|
|
ACTUAL=$("$PROGRAM" -e 'p' 2>&1) || true
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
|
|
# Test non numerical values
|
|
EXPECTED="foo"
|
|
ACTUAL=$("$PROGRAM" -e '[ foo ] p' 2>&1) || true
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
}
|
|
|
|
test_print_bin() {
|
|
PROGRAM="$PWD/build/dc"
|
|
EXPECTED="1111b"
|
|
ACTUAL=$("$PROGRAM" -e '15 pb')
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
|
|
# Test empty stack
|
|
EXPECTED="Cannot print empty stack"
|
|
ACTUAL=$("$PROGRAM" -e 'pb' 2>&1) || true
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
|
|
# Test non numerical values
|
|
EXPECTED="This output radix requires integer values"
|
|
ACTUAL=$("$PROGRAM" -e '[ foo ] pb' 2>&1) || true
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
|
|
# Test negative number
|
|
EXPECTED="1111111111111111111111111111111111111111111111111111111111110001b"
|
|
ACTUAL=$("$PROGRAM" -e "-15 pb")
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
}
|
|
|
|
test_print_hex() {
|
|
PROGRAM="$PWD/build/dc"
|
|
EXPECTED="Fh"
|
|
ACTUAL=$("$PROGRAM" -e '15 ph')
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
|
|
# Test empty stack
|
|
EXPECTED="Cannot print empty stack"
|
|
ACTUAL=$("$PROGRAM" -e 'ph' 2>&1) || true
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
|
|
# Test non numerical values
|
|
EXPECTED="This output radix requires integer values"
|
|
ACTUAL=$("$PROGRAM" -e '[ foo ] ph' 2>&1) || true
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
}
|
|
|
|
test_print_oct() {
|
|
PROGRAM="$PWD/build/dc"
|
|
EXPECTED="17o"
|
|
ACTUAL=$("$PROGRAM" -e '15 po')
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
|
|
# Test empty stack
|
|
EXPECTED="Cannot print empty stack"
|
|
ACTUAL=$("$PROGRAM" -e 'po' 2>&1) || true
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
|
|
# Test non numerical values
|
|
EXPECTED="This output radix requires integer values"
|
|
ACTUAL=$("$PROGRAM" -e '[ foo ] po' 2>&1) || true
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
}
|
|
|
|
test_print_no_newline() {
|
|
PROGRAM="$PWD/build/dc"
|
|
EXPECTED="5"
|
|
ACTUAL=$("$PROGRAM" -e '5 P')
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
|
|
# Test empty stack
|
|
EXPECTED="Cannot print empty stack"
|
|
ACTUAL=$("$PROGRAM" -e 'P' 2>&1) || true
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
|
|
# Test non numerical values
|
|
EXPECTED="foo"
|
|
ACTUAL=$("$PROGRAM" -e '[ foo ] P' 2>&1) || true
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
}
|
|
|
|
test_print_space() {
|
|
PROGRAM="$PWD/build/dc"
|
|
EXPECTED="0 1"
|
|
ACTUAL=$("$PROGRAM" -e '1 0 p. R P')
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
|
|
# Test empty stack
|
|
EXPECTED="Cannot print empty stack"
|
|
ACTUAL=$("$PROGRAM" -e 'p.' 2>&1) || true
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
|
|
# Test non numerical values
|
|
EXPECTED="foo "
|
|
ACTUAL=$("$PROGRAM" -e '[ foo ] p.' 2>&1) || true
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
}
|
|
|
|
|
|
utest() {
|
|
test_print
|
|
test_print_no_newline
|
|
test_print_space
|
|
test_print_bin
|
|
test_print_hex
|
|
test_print_oct
|
|
}
|
|
# vim: ts=4 sw=4 softtabstop=4 expandtab:
|