Advertisement
Guest User

Untitled

a guest
May 8th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 4.40 KB | None | 0 0
  1. package grading
  2.  
  3. import calculator.controller._
  4. import calculator.model.Calculator
  5. import org.scalatest._
  6.  
  7. class TestSubmission extends FunSuite {
  8.   val EPSILON: Double = 0.0001
  9.  
  10.   def equalDoubles(d1: Double, d2: Double): Boolean = {
  11.     (d1 - d2).abs < EPSILON
  12.   }
  13.  
  14.   test("Sample test from assignment - Multiple Operations") {
  15.     val calculator: Calculator = new Calculator()
  16.  
  17.     new NumberAction(calculator, 3).handle(null)
  18.  
  19.     new MultiplicationAction(calculator).handle(null)
  20.  
  21.     new NumberAction(calculator, 5).handle(null)
  22.  
  23.     new AdditionAction(calculator).handle(null)
  24.  
  25.     new NumberAction(calculator, 1).handle(null)
  26.     new NumberAction(calculator, 0).handle(null)
  27.     new DecimalAction(calculator).handle(null)
  28.     new NumberAction(calculator, 5).handle(null)
  29.  
  30.     new EqualAction(calculator).handle(null)
  31.  
  32.  
  33.     val expected: Double = 25.5
  34.     val actual: Double = calculator.displayNumber()
  35.     assert(equalDoubles(actual, expected), actual)
  36.   }
  37.  
  38.   test("Sample test from assignment - Consecutive operations") {
  39.     val calculator: Calculator = new Calculator()
  40.     new NumberAction(calculator, 3).handle(null)
  41.  
  42.     new MultiplicationAction(calculator).handle(null)
  43.     new AdditionAction(calculator).handle(null)
  44.  
  45.     new NumberAction(calculator, 5).handle(null)
  46.  
  47.     new EqualAction(calculator).handle(null)
  48.  
  49.  
  50.     val expected: Double = 8.0
  51.     val actual: Double = calculator.displayNumber()
  52.     assert(equalDoubles(actual, expected), actual)
  53.   }
  54.  
  55.   test("Test Repeat Operations") {
  56.     val calculator: Calculator = new Calculator()
  57.     new NumberAction(calculator, 3).handle(null)
  58.  
  59.     new AdditionAction(calculator).handle(null)
  60.  
  61.     new NumberAction(calculator, 5).handle(null)
  62.  
  63.     new EqualAction(calculator).handle(null)
  64.     new EqualAction(calculator).handle(null)
  65.     new EqualAction(calculator).handle(null)
  66.  
  67.  
  68.     val expected: Double = 18.0
  69.     val actual: Double = calculator.displayNumber()
  70.     assert(equalDoubles(actual, expected), actual)
  71.   }
  72.  
  73.   test("The big test") {
  74.     val calculator: Calculator = new Calculator()
  75.  
  76.     // 12+7=-20.6=c10.3*8.8=/2.25+11.....3..8=
  77.  
  78.     new NumberAction(calculator, 1).handle(null)
  79.     new NumberAction(calculator, 2).handle(null)
  80.  
  81.     new AdditionAction(calculator).handle(null)
  82.  
  83.     new NumberAction(calculator, 7).handle(null)
  84.  
  85.     new EqualAction(calculator).handle(null)
  86.     assert(equalDoubles(calculator.displayNumber(), 19.0), calculator.displayNumber())
  87.  
  88.  
  89.     new SubtractionAction(calculator).handle(null)
  90.  
  91.     new NumberAction(calculator, 2).handle(null)
  92.     new NumberAction(calculator, 0).handle(null)
  93.     new DecimalAction(calculator).handle(null)
  94.     new NumberAction(calculator, 6).handle(null)
  95.  
  96.     new EqualAction(calculator).handle(null)
  97.     assert(equalDoubles(calculator.displayNumber(), -1.6), calculator.displayNumber())
  98.  
  99.  
  100.     new ClearAction(calculator).handle(null)
  101.  
  102.     new NumberAction(calculator, 1).handle(null)
  103.     new NumberAction(calculator, 0).handle(null)
  104.     new DecimalAction(calculator).handle(null)
  105.     new NumberAction(calculator, 3).handle(null)
  106.  
  107.     new MultiplicationAction(calculator).handle(null)
  108.  
  109.     new NumberAction(calculator, 8).handle(null)
  110.     new DecimalAction(calculator).handle(null)
  111.     new NumberAction(calculator, 8).handle(null)
  112.  
  113.     new EqualAction(calculator).handle(null)
  114.     assert(equalDoubles(calculator.displayNumber(), 90.64), calculator.displayNumber())
  115.  
  116.  
  117.     new DivisionAction(calculator).handle(null)
  118.  
  119.     new NumberAction(calculator, 2).handle(null)
  120.     new DecimalAction(calculator).handle(null)
  121.     new NumberAction(calculator, 2).handle(null)
  122.     new NumberAction(calculator, 5).handle(null)
  123.  
  124.     new AdditionAction(calculator).handle(null)
  125.  
  126.     new NumberAction(calculator, 1).handle(null)
  127.     new NumberAction(calculator, 1).handle(null)
  128.     new DecimalAction(calculator).handle(null)
  129.     new DecimalAction(calculator).handle(null)
  130.     new DecimalAction(calculator).handle(null)
  131.     new DecimalAction(calculator).handle(null)
  132.     new DecimalAction(calculator).handle(null)
  133.     new NumberAction(calculator, 3).handle(null)
  134.     new DecimalAction(calculator).handle(null)
  135.     new DecimalAction(calculator).handle(null)
  136.     new NumberAction(calculator, 8).handle(null)
  137.  
  138.     new EqualAction(calculator).handle(null)
  139.     assert(equalDoubles(calculator.displayNumber(), 51.6644444444444), calculator.displayNumber())
  140.  
  141.   }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement