-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_calculator.rb
64 lines (52 loc) · 1.8 KB
/
test_calculator.rb
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
require 'test/unit'
require 'calculator'
class TestCalculator < Test::Unit::TestCase
def test_time
calc = Calculator.new [:t]
calc.in [48]
assert_equal [48], calc.out
end
def test_first_must_be_time
assert_raise(RuntimeError){
calc = Calculator.new [:v]
}
end
def test_integer_absolute
calc = Calculator.new [:t, :a]
calc.in [48,18]
assert_equal [48,18], calc.out
end
def test_values_absolute
calc = Calculator.new [:t, :a, :a, :a]
calc.in [32, "pepe", 23, 32.3]
assert_equal [32, "pepe", 23, 32.3], calc.out
end
def test_several_values_absolute
calc = Calculator.new [:t, :a, :a, :a]
calc.in [32, "pepe", 23, 32.3]
assert_equal [32, "pepe", 23, 32.3], calc.out
calc.in [42, "pepeX", 231, 332.33]
assert_equal [42, "pepeX", 231, 332.33], calc.out
end
def test_several_values_relative
calc = Calculator.new [:t, :a, :d, :d]
calc.in [42, "pepe", 23, 32.3]
calc.in [52, "pepeX", 231, 332.33]
assert_equal [52, "pepeX", 208, 300.03], calc.out
end
def test_several_values_relative_twice
calc = Calculator.new [:t, :a, :d, :d]
calc.in [42, "pepe", 23, 32.3]
calc.in [52, "pepeX", 231, 332.43333]
assert_equal [52, "pepeX", 208, 300.13], calc.out
calc.in [62, "pepeY", 241, 338.43]
assert_equal [62, "pepeY", 10, 6.0], calc.out
end
def test_values_relatives_per_second
calc = Calculator.new [:t, :a, :v, :d]
calc.in [42, "pepe", 23, 32.3]
calc.in [52, "pepeX", 231, 332.33] # remember put two decimals only
# and if integer and velocity past to float
assert_equal [52, "pepeX", 20, 300.03], calc.out
end
end