Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package grading
- import calculator.controller._
- import calculator.model.Calculator
- import org.scalatest._
- class TestSubmission extends FunSuite {
- val EPSILON: Double = 0.0001
- def equalDoubles(d1: Double, d2: Double): Boolean = {
- (d1 - d2).abs < EPSILON
- }
- test("Sample test from assignment - Multiple Operations") {
- val calculator: Calculator = new Calculator()
- new NumberAction(calculator, 3).handle(null)
- new MultiplicationAction(calculator).handle(null)
- new NumberAction(calculator, 5).handle(null)
- new AdditionAction(calculator).handle(null)
- new NumberAction(calculator, 1).handle(null)
- new NumberAction(calculator, 0).handle(null)
- new DecimalAction(calculator).handle(null)
- new NumberAction(calculator, 5).handle(null)
- new EqualAction(calculator).handle(null)
- val expected: Double = 25.5
- val actual: Double = calculator.displayNumber()
- assert(equalDoubles(actual, expected), actual)
- }
- test("Sample test from assignment - Consecutive operations") {
- val calculator: Calculator = new Calculator()
- new NumberAction(calculator, 3).handle(null)
- new MultiplicationAction(calculator).handle(null)
- new AdditionAction(calculator).handle(null)
- new NumberAction(calculator, 5).handle(null)
- new EqualAction(calculator).handle(null)
- val expected: Double = 8.0
- val actual: Double = calculator.displayNumber()
- assert(equalDoubles(actual, expected), actual)
- }
- test("Test Repeat Operations") {
- val calculator: Calculator = new Calculator()
- new NumberAction(calculator, 3).handle(null)
- new AdditionAction(calculator).handle(null)
- new NumberAction(calculator, 5).handle(null)
- new EqualAction(calculator).handle(null)
- new EqualAction(calculator).handle(null)
- new EqualAction(calculator).handle(null)
- val expected: Double = 18.0
- val actual: Double = calculator.displayNumber()
- assert(equalDoubles(actual, expected), actual)
- }
- test("The big test") {
- val calculator: Calculator = new Calculator()
- // 12+7=-20.6=c10.3*8.8=/2.25+11.....3..8=
- new NumberAction(calculator, 1).handle(null)
- new NumberAction(calculator, 2).handle(null)
- new AdditionAction(calculator).handle(null)
- new NumberAction(calculator, 7).handle(null)
- new EqualAction(calculator).handle(null)
- assert(equalDoubles(calculator.displayNumber(), 19.0), calculator.displayNumber())
- new SubtractionAction(calculator).handle(null)
- new NumberAction(calculator, 2).handle(null)
- new NumberAction(calculator, 0).handle(null)
- new DecimalAction(calculator).handle(null)
- new NumberAction(calculator, 6).handle(null)
- new EqualAction(calculator).handle(null)
- assert(equalDoubles(calculator.displayNumber(), -1.6), calculator.displayNumber())
- new ClearAction(calculator).handle(null)
- new NumberAction(calculator, 1).handle(null)
- new NumberAction(calculator, 0).handle(null)
- new DecimalAction(calculator).handle(null)
- new NumberAction(calculator, 3).handle(null)
- new MultiplicationAction(calculator).handle(null)
- new NumberAction(calculator, 8).handle(null)
- new DecimalAction(calculator).handle(null)
- new NumberAction(calculator, 8).handle(null)
- new EqualAction(calculator).handle(null)
- assert(equalDoubles(calculator.displayNumber(), 90.64), calculator.displayNumber())
- new DivisionAction(calculator).handle(null)
- new NumberAction(calculator, 2).handle(null)
- new DecimalAction(calculator).handle(null)
- new NumberAction(calculator, 2).handle(null)
- new NumberAction(calculator, 5).handle(null)
- new AdditionAction(calculator).handle(null)
- new NumberAction(calculator, 1).handle(null)
- new NumberAction(calculator, 1).handle(null)
- new DecimalAction(calculator).handle(null)
- new DecimalAction(calculator).handle(null)
- new DecimalAction(calculator).handle(null)
- new DecimalAction(calculator).handle(null)
- new DecimalAction(calculator).handle(null)
- new NumberAction(calculator, 3).handle(null)
- new DecimalAction(calculator).handle(null)
- new DecimalAction(calculator).handle(null)
- new NumberAction(calculator, 8).handle(null)
- new EqualAction(calculator).handle(null)
- assert(equalDoubles(calculator.displayNumber(), 51.6644444444444), calculator.displayNumber())
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement