summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2003-12-09 12:46:33 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2003-12-09 12:46:33 +0000
commitca9cca296a75d6ec551ed6d989d5dda291cf8ce5 (patch)
treea74485751a841c156a886e56b0a8547318e695bd
parent4b33a28b85c8b5108563569f31c858827a61fa93 (diff)
Towers of Hanoi regression test.
BSD license with permission from author Amit Singh <amit_s at acm dot org>.
-rw-r--r--regress/usr.bin/dc/Makefile5
-rw-r--r--regress/usr.bin/dc/t20.in100
-rw-r--r--regress/usr.bin/dc/t20.out31
3 files changed, 134 insertions, 2 deletions
diff --git a/regress/usr.bin/dc/Makefile b/regress/usr.bin/dc/Makefile
index 10b24f5c051..8aa81497130 100644
--- a/regress/usr.bin/dc/Makefile
+++ b/regress/usr.bin/dc/Makefile
@@ -1,9 +1,9 @@
-# $OpenBSD: Makefile,v 1.9 2003/12/01 09:15:51 otto Exp $
+# $OpenBSD: Makefile,v 1.10 2003/12/09 12:46:32 otto Exp $
DC=dc -x
REGRESS_TARGETS=t1 t2 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 \
- t19
+ t19 t20
# .in: input file
# .out: desired result
@@ -26,6 +26,7 @@ REGRESS_TARGETS=t1 t2 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 \
# t17: test R (drop)
# t18: read uninitialized and initialized array locations
# t19: test extended registers
+# t20: towers of hanoi
all: clean ${REGRESS_TARGET}
diff --git a/regress/usr.bin/dc/t20.in b/regress/usr.bin/dc/t20.in
new file mode 100644
index 00000000000..9e4a6e6a861
--- /dev/null
+++ b/regress/usr.bin/dc/t20.in
@@ -0,0 +1,100 @@
+# $OpenBSD: t20.in,v 1.1 2003/12/09 12:46:32 otto Exp $
+#
+# Copyright (c) 2003 Amit Singh <amit_s@acm.org>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+#
+# The Towers Of Hanoi
+# dc (Unix Desk Calculator) version
+# http://hanoi.kernelthread.com
+#
+
+[ # move(from, to)
+ n # print from
+ [ --> ]n # print " --> "
+ p # print to\n
+ sw # p doesn't pop, so get rid of the value
+]sm
+
+[ # init(n)
+ sw # tuck n away temporarily
+ 9 # sentinel as bottom of stack
+ lw # bring n back
+ 1 # "from" tower's label
+ 3 # "to" tower's label
+ 0 # processed marker
+]si
+
+[ # Move()
+ lt # push to
+ lf # push from
+ lmx # call move(from, to)
+]sM
+
+[ # code block <d>
+ ln # push n
+ lf # push from
+ lt # push to
+ 1 # push processed marker 1
+ ln # push n
+ 1 # push 1
+ - # n - 1
+ lf # push from
+ ll # push left
+ 0 # push processed marker 0
+]sd
+
+[ # code block <e>
+ ln # push n
+ 1 # push 1
+ - # n - 1
+ ll # push left
+ lt # push to
+ 0 # push processed marker 0
+]se
+
+[ # code block <x>
+ ln 1 =M
+ ln 1 !=d
+]sx
+
+[ # code block <y>
+ lMx
+ lex
+]sy
+
+[ # quit()
+ q # exit the program
+]sq
+
+[ # run()
+ d 9 =q # if stack empty, quit()
+ sp # processed
+ st # to
+ sf # from
+ sn # n
+ 6 #
+ lf #
+ - #
+ lt #
+ - # 6 - from - to
+ sl #
+ lp 0 =x #
+ lp 0 !=y #
+ lrx # loop
+]sr
+
+5lix # init(n)
+lrx # run()
+
diff --git a/regress/usr.bin/dc/t20.out b/regress/usr.bin/dc/t20.out
new file mode 100644
index 00000000000..3e7cb2592e9
--- /dev/null
+++ b/regress/usr.bin/dc/t20.out
@@ -0,0 +1,31 @@
+1 --> 3
+1 --> 2
+3 --> 2
+1 --> 3
+2 --> 1
+2 --> 3
+1 --> 3
+1 --> 2
+3 --> 2
+3 --> 1
+2 --> 1
+3 --> 2
+1 --> 3
+1 --> 2
+3 --> 2
+1 --> 3
+2 --> 1
+2 --> 3
+1 --> 3
+2 --> 1
+3 --> 2
+3 --> 1
+2 --> 1
+2 --> 3
+1 --> 3
+1 --> 2
+3 --> 2
+1 --> 3
+2 --> 1
+2 --> 3
+1 --> 3