core_testing3/postfix_test3.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Wed, 06 Mar 2024 18:20:25 +0000
changeset 484 c4561fc667b7
parent 474 b528d1d3d3c3
permissions -rw-r--r--
test



def urbanmain() = {
  import C3b._


  assert(syard(split("3 + 4 * ( 2 - 1 )")) == List("3", "4", "2", "1", "-", "*", "+"))
  assert(syard(split("( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )")) == List("3", "4", "5", "+", "+"))
  assert(syard(split("5 + 7 / 2")) == List("5", "7", "2", "/", "+"))
  assert(syard(split("5 * 7 / 2")) == List("5", "7", "*", "2", "/"))
  assert(syard(split("3 + 4 * 8 / ( 5 - 1 ) ^ 2 ^ 3")) == List("3", "4", "8", "*", "5", "1", "-", "2", "3", "^", "^", "/", "+"))

  assert(compute(syard(split("3 + 4 * ( 2 - 1 )"))) == 7)
  assert(compute(syard(split("10 + 12 * 33"))) == 406)
  assert(compute(syard(split("( 5 + 7 ) * 2"))) == 24)
  assert(compute(syard(split("5 + 7 / 2"))) == 8)
  assert(compute(syard(split("5 * 7 / 2"))) == 17)
  assert(compute(syard(split("9 + 24 / ( 7 - 3 )"))) == 15)
  assert(compute(syard(split("4 ^ 3 ^ 2"))) == 262144)
  assert(compute(syard(split("4 ^ ( 3 ^ 2 )"))) == 262144)
  assert(compute(syard(split("( 4 ^ 3 ) ^ 2"))) == 4096)
  assert(compute(syard(split("( 3 + 1 ) ^ 2 ^ 3"))) == 65536)
}