30 lines
788 B
Bash
30 lines
788 B
Bash
#!/bin/sh
|
|
|
|
utest() {
|
|
PROGRAM="$PWD/build/dc"
|
|
EXPECTED="128"
|
|
ACTUAL=$("$PROGRAM" -e '256 2 / p')
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
|
|
# Test empty stack
|
|
EXPECTED="'/' requires two operands"
|
|
ACTUAL=$("$PROGRAM" -e '/' 2>&1) || true
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
|
|
# Test non numerical values
|
|
EXPECTED="'/' requires numeric values"
|
|
ACTUAL=$("$PROGRAM" -e '[ foo ] 5 /' 2>&1) || true
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
|
|
# Test division by zero
|
|
EXPECTED="Cannot divide by zero"
|
|
ACTUAL=$("$PROGRAM" -e '5 0 /' 2>&1) || true
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
|
|
# Test complex values
|
|
EXPECTED="(2.20,1.60)"
|
|
ACTUAL=$("$PROGRAM" -e '5 7 b 3 1 b / p')
|
|
assert_eq "$EXPECTED" "$ACTUAL"
|
|
}
|
|
# vim: ts=4 sw=4 softtabstop=4 expandtab:
|