Advertisement
Guest User

jontlar testler

a guest
Feb 27th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 2.76 KB | None | 0 0
  1.   test("cond test 1"){
  2.     assertResult(NumV(1)){
  3.       interp(desugar(parse("(cond((num< 1 0) 0)(else 1))")))
  4.     }
  5.   }
  6.  
  7.   test("interp cond test 2 "){
  8.     assertResult(NumV(15)){
  9.       interp(desugar(parse("(cond((num> 5 1) 15)((num< 1 0) 2))")))
  10.     }
  11.   }
  12.  
  13.   test("interp cond test 3 "){
  14.     assertResult(NumV(100)){
  15.       interp(desugar(parse("(cond((num> 0 1) 15)((num< 1 0) 2)(else 100))")))
  16.     }
  17.   }
  18.  
  19.   test("interp cond test 4 "){
  20.     assertResult(NumV(2)){
  21.       interp(desugar(parse("(cond((num> 0 1) 15)((num< -5 0) 2)(else 100))")))
  22.     }
  23.   }
  24.  
  25.   test("condExt") {
  26.     assertResult(CondExt(List((BinOpExt("num>", NumExt(1), NumExt(0)), NumExt(1))))) {
  27.       parse("(cond ((num> 1 0) 1))")
  28.     }
  29.     intercept[InterpException] {
  30.       interp(desugar(parse("(cond ((num< 1 0) 1))")))
  31.     }
  32.     intercept[PException] {
  33.       interp(desugar(parse("(cond ((else 1)))")))
  34.     }
  35.     intercept[PException] {
  36.       interp(desugar(parse("(cond ((num< 0 1) ))")))
  37.     }
  38.     intercept[PException] {
  39.       interp(desugar(parse("(cond (()))")))
  40.     }
  41.     intercept[PException] {
  42.       interp(desugar(parse("(cond ((nil) 1) (else 0))")))
  43.     }
  44.     intercept[PException] {
  45.       interp(desugar(parse("(cond (else 0))")))
  46.     }
  47.     intercept[PException] {
  48.       interp(desugar(parse("(cond ((num< 1 0) 0) (else 1) ((num> 1 0) 2))")))
  49.     }
  50.     intercept[PException] {
  51.       interp(desugar(parse("(cond((5) 0))")))
  52.     }
  53.     intercept[ParseException]{
  54.       interp(desugar(parse("(cond((num< 5 0)))")))
  55.     }
  56.     intercept[ParseException]{
  57.       interp(desugar(parse("(cond((else 1)))")))
  58.     }
  59.     intercept[ParseException]{
  60.       interp(desugar(parse("(cond((else 1)((num< 5 0) 2)))")))
  61.     }
  62.     intercept[PException] {
  63.       interp(desugar(parse("(cond ((num< 1 0) 0) (else omae 1))")))
  64.     }
  65.   }
  66.  
  67.   test("condExt multiple conditions") {
  68.     assertResult(NumV(0)) {
  69.       interp(desugar(parse("(cond ((num< 0 1) 0))")))
  70.     }
  71.     assertResult(NumV(1)) {
  72.       interp(desugar(parse("(cond ((num> 0 1) 0) ((and true false) 50) ((and true true) 1))")))
  73.     }
  74.     intercept[InterpException] {
  75.       interp(desugar(parse("(cond ((num> 0 1) 0) ((and true false) 50) ((or false false) 1))")))
  76.     }
  77.   }
  78.  
  79.   test("condEExt") {
  80.     assertResult(CondEExt(List((BinOpExt("num>", NumExt(1), NumExt(0)), NumExt(1))), NumExt(1))) {
  81.       parse("(cond ((num> 1 0) 1) (else 1))")
  82.     }
  83.     assertResult(NumV(1)) {
  84.       interp(desugar(parse("(cond ((num< 1 0) 0) (else 1))")))
  85.     }
  86.     assertResult(NumV(1)) {
  87.       interp(desugar(parse("(cond ((num< 1 0) 0) ((num= 1 0) -1) ((num> 1 2) 2) (else 1))")))
  88.     }
  89.     assertResult(NumV(2)) {
  90.       interp(desugar(parse("(cond ((num< 1 0) 0) ((num= 1 0) -1) ((num> 3 2) 2) (else 1))")))
  91.     }
  92.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement