-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator_test.rb
More file actions
66 lines (54 loc) · 1.67 KB
/
Copy pathcalculator_test.rb
File metadata and controls
66 lines (54 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'test/unit'
require './calculate.rb'
class CalcTest < Test::Unit::TestCase
# Called before every test method runs. Can be used
# to set up fixture information.
def setup
@calc = Calculate.new()
end
# Called after every test method runs. Can be used to tear
# down fixture information.
def teardown
# Do nothing
end
def test_division_by_zero
assert_raise ZeroDivisionError do
@calc.calculate_expression("10 / 0")
end
end
def test_validations_letter
assert_raise StandardError do
@calc.validate_expression("1234k")
end
end
def test_validations_two_decimal
assert_raise StandardError do
@calc.validate_expression("1234.6.7")
end
end
def test_validations_ok
assert_nothing_thrown do
@calc.validate_expression("1234.60")
@calc.validate_expression("123")
end
end
def test_calculations
assert_equal("10",@calc.calculate_expression("10"))
@calc = Calculate.new()
assert_equal("10.0",@calc.calculate_expression("10.0"))
@calc = Calculate.new()
assert_equal("20.0",@calc.calculate_expression("10 * 2"))
@calc = Calculate.new()
assert_equal("20.0",@calc.calculate_expression("10.0 * 2.0"))
@calc = Calculate.new()
assert_equal("10.0",@calc.calculate_expression("2 + 8"))
@calc = Calculate.new()
assert_equal("10.0",@calc.calculate_expression("2.0 + 8.0"))
@calc = Calculate.new()
assert_equal("10.0",@calc.calculate_expression("5 * 2"))
@calc = Calculate.new()
assert_equal("10.0",@calc.calculate_expression("5.0 * 2.0"))
@calc = Calculate.new()
assert_equal("10.0",@calc.calculate_expression("5.0 * 3.0 - 5 * 1"))
end
end