marking4/postfix_test9.scala
author Christian Urban <urbanc@in.tum.de>
Fri, 22 Nov 2019 16:41:45 +0000
changeset 323 1f8005b4cdf6
parent 288 65731df141a5
child 329 8a34b2ebc8cc
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
288
65731df141a5 updated
Christian Urban <urbanc@in.tum.de>
parents: 257
diff changeset
     1
import CW9b._
65731df141a5 updated
Christian Urban <urbanc@in.tum.de>
parents: 257
diff changeset
     2
257
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
assert(syard(split("3 + 4 * ( 2 - 1 )")) == List("3", "4", "2", "1", "-", "*", "+"))
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
assert(syard(split("( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )")) == List("3", "4", "5", "+", "+"))
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
assert(syard(split("5 + 7 / 2")) == List("5", "7", "2", "/", "+"))
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
assert(syard(split("5 * 7 / 2")) == List("5", "7", "*", "2", "/"))
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
assert(syard(split("3 + 4 * 8 / ( 5 - 1 ) ^ 2 ^ 3")) == List("3", "4", "8", "*", "5", "1", "-", "2", "3", "^", "^", "/", "+"))
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
assert(compute(syard(split("3 + 4 * ( 2 - 1 )"))) == 7)
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
assert(compute(syard(split("10 + 12 * 33"))) == 406)
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
assert(compute(syard(split("( 5 + 7 ) * 2"))) == 24)
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
assert(compute(syard(split("5 + 7 / 2"))) == 8)
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
assert(compute(syard(split("5 * 7 / 2"))) == 17)
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
assert(compute(syard(split("9 + 24 / ( 7 - 3 )"))) == 15)
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
assert(compute(syard(split("4 ^ 3 ^ 2"))) == 262144)
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
assert(compute(syard(split("4 ^ ( 3 ^ 2 )"))) == 262144)
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
assert(compute(syard(split("( 4 ^ 3 ) ^ 2"))) == 4096)
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
assert(compute(syard(split("( 3 + 1 ) ^ 2 ^ 3"))) == 65536)