aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasaya Tojo <masaya@tojo.tokyo>2024-09-22 02:00:16 +0900
committerMasaya Tojo <masaya@tojo.tokyo>2024-09-22 02:00:16 +0900
commit24079eaaae8fe2b4978c659549a466f7323f39bb (patch)
tree29b1c5ba4ae9218ab1dd557bfaf660446f4012d4
parentc80bf53a05d63e7419bf941ede95250b25daed05 (diff)
Add infix-to-prefix-tests file
-rw-r--r--tests/infix-to-prefix-tests.scm60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/infix-to-prefix-tests.scm b/tests/infix-to-prefix-tests.scm
new file mode 100644
index 0000000..0487322
--- /dev/null
+++ b/tests/infix-to-prefix-tests.scm
@@ -0,0 +1,60 @@
+(import (scheme base)
+ (infix-to-prefix rule-set)
+ (infix-to-prefix)
+ (srfi 64))
+
+(current-operator-rule-set
+ (rule-set
+ (list
+ (operator '= 0)
+ (operator '+ 1 (direction 'left #t) (identity 0))
+ (operator '- 1 (direction 'left) (identity 0 #t #t 3))
+ (operator '* 2 (direction 'left #t) (identity 1))
+ (operator '/ 2 (direction 'left) (identity 1 #t))
+ (operator '^ 4 (direction 'right) #f (prefix #t 'expt)))))
+
+(test-begin "infix-to-prefix")
+
+(test-equal '(+ a b)
+ (infix->prefix '(a + b)))
+
+(test-equal '(+ a b c)
+ (infix->prefix '(a + b + c)))
+
+(test-equal '(+ a (* b c))
+ (infix->prefix '(a + b * c)))
+
+(test-equal '(+ a b c)
+ (infix->prefix '((a + b) + c)))
+
+(test-equal '(+ a b c)
+ (infix->prefix '(a + (b + c))))
+
+(test-equal '(- a b c)
+ (infix->prefix '(a - b - c)))
+
+(test-equal '(- a b c)
+ (infix->prefix '((a - b) - c)))
+
+(test-equal '(- a (- b c))
+ (infix->prefix '(a - (b - c))))
+
+(test-equal '(+ (- a b) (- c d))
+ (infix->prefix '(a - b + c - d)))
+
+(test-equal '(- (+ (- a b) c) d)
+ (infix->prefix '(a - b + c - d)))
+
+(test-equal '(+ (* a b) (* c d))
+ (infix->prefix '(a * b + c * d)))
+
+(test-equal '(- a)
+ (infix->prefix '(- a)))
+
+(test-equal '(* (- a) b)
+ (infix->prefix '(- a * b)))
+
+(test-equal '(- (expt a 2))
+ (infix->prefix '(- a ^ 2)))
+
+(test-end "infix-to-prefix")