aboutsummaryrefslogtreecommitdiff
path: root/tests/infix-to-prefix-tests.scm
blob: 048732273ac6bab29c8eff51c728af20acbe70bd (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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")