This commit is contained in:
parent
f7932f9566
commit
e61a7debfa
10
tests/test_clear
Normal file
10
tests/test_clear
Normal file
@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
utest() {
|
||||
PROGRAM="$PWD/build/dc"
|
||||
EXPECTED="Cannot print empty stack"
|
||||
ACTUAL=$("$PROGRAM" -e '5 4 c p' 2>&1) || true
|
||||
assert_eq "$EXPECTED" "$ACTUAL"
|
||||
}
|
||||
|
||||
# vim: ts=4 sw=4 softtabstop=4 expandtab:
|
21
tests/test_count_digits
Normal file
21
tests/test_count_digits
Normal file
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
utest() {
|
||||
PROGRAM="$PWD/build/dc"
|
||||
EXPECTED="4"
|
||||
ACTUAL=$("$PROGRAM" -e '5430 Z p')
|
||||
assert_eq "$EXPECTED" "$ACTUAL"
|
||||
|
||||
# Test with floats
|
||||
PROGRAM="$PWD/build/dc"
|
||||
EXPECTED="4"
|
||||
ACTUAL=$("$PROGRAM" -e '54.30 Z p')
|
||||
assert_eq "$EXPECTED" "$ACTUAL"
|
||||
|
||||
# Test with strings
|
||||
PROGRAM="$PWD/build/dc"
|
||||
EXPECTED="11"
|
||||
ACTUAL=$("$PROGRAM" -e '[ Hello World ] Z p')
|
||||
assert_eq "$EXPECTED" "$ACTUAL"
|
||||
}
|
||||
# vim: ts=4 sw=4 softtabstop=4 expandtab:
|
9
tests/test_dump
Normal file
9
tests/test_dump
Normal file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
utest() {
|
||||
PROGRAM="$PWD/build/dc"
|
||||
EXPECTED="25 20 15 10 5"
|
||||
ACTUAL=$("$PROGRAM" -e '5 10 15 20 25 f' | tr '\n' ' ' | sed 's/ $/\n/')
|
||||
assert_eq "$EXPECTED" "$ACTUAL"
|
||||
}
|
||||
# vim: ts=4 sw=4 softtabstop=4 expandtab:
|
9
tests/test_dup
Normal file
9
tests/test_dup
Normal file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
utest() {
|
||||
PROGRAM="$PWD/build/dc"
|
||||
EXPECTED="2"
|
||||
ACTUAL=$("$PROGRAM" -e '5 d z p')
|
||||
assert_eq "$EXPECTED" "$ACTUAL"
|
||||
}
|
||||
# vim: ts=4 sw=4 softtabstop=4 expandtab:
|
9
tests/test_pop
Normal file
9
tests/test_pop
Normal file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
utest() {
|
||||
PROGRAM="$PWD/build/dc"
|
||||
EXPECTED="5"
|
||||
ACTUAL=$("$PROGRAM" -e '5 10 R p')
|
||||
assert_eq "$EXPECTED" "$ACTUAL"
|
||||
}
|
||||
# vim: ts=4 sw=4 softtabstop=4 expandtab:
|
95
tests/test_prt
Normal file
95
tests/test_prt
Normal file
@ -0,0 +1,95 @@
|
||||
#!/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_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"
|
||||
}
|
||||
|
||||
utest() {
|
||||
test_print
|
||||
test_print_no_newline
|
||||
test_print_bin
|
||||
test_print_hex
|
||||
test_print_oct
|
||||
}
|
||||
# vim: ts=4 sw=4 softtabstop=4 expandtab:
|
15
tests/test_stack_size
Normal file
15
tests/test_stack_size
Normal file
@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
|
||||
utest() {
|
||||
PROGRAM="$PWD/build/dc"
|
||||
EXPECTED="4"
|
||||
ACTUAL=$("$PROGRAM" -e '5 4 3 1 z p')
|
||||
assert_eq "$EXPECTED" "$ACTUAL"
|
||||
|
||||
# Test empty stack
|
||||
PROGRAM="$PWD/build/dc"
|
||||
EXPECTED="0"
|
||||
ACTUAL=$("$PROGRAM" -e 'z p')
|
||||
assert_eq "$EXPECTED" "$ACTUAL"
|
||||
}
|
||||
# vim: ts=4 sw=4 softtabstop=4 expandtab:
|
9
tests/test_swap
Normal file
9
tests/test_swap
Normal file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
utest() {
|
||||
PROGRAM="$PWD/build/dc"
|
||||
EXPECTED="5"
|
||||
ACTUAL=$("$PROGRAM" -e '5 10 r p')
|
||||
assert_eq "$EXPECTED" "$ACTUAL"
|
||||
}
|
||||
# vim: ts=4 sw=4 softtabstop=4 expandtab:
|
Loading…
Reference in New Issue
Block a user