-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcalculator.rb
57 lines (51 loc) · 2.09 KB
/
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
require 'kata'
kata "Calculator" do
requirement "Create a calculator that is initialized with a string expression" do
detail %q{The expression is of the form digits separated by commas: "1,2"}
detail "The expression is accessed by a method named expr"
detail "The expression can be changed without require a new instance of the calculator"
example %q{Calculator.new "1,2"}
example %q{Text field to enter the expression}
end
context "Add Method" do
requirement "Create an add method that sums the string expression" do
detail "The method will return the sum of the digits"
detail "The expression can contain 0, 1 or 2 numbers"
detail "Then empty string will return 0"
example %q{"" computes to 0}
example %q{"1" computes to 1}
example %q{"1,2" computes to 3}
end
requirement "Allow the expression to contain an unknown amount of numbers" do
example %q{"1,2,3" computes to 6}
example %q{"1,2,5,8" computes to 16}
end
end
context "Diff Method" do
requirement "Create a diff method that computes the consecutive differences" do
detail "The expression must contain at least 2 digits"
example %q{"1,0" compues to 1}
example %q{"3,2,1" computes to 0}
example %q{"5,4,3,2,1 computes to -5}
detail "Expressions with less than 2 digits raise an exception"
example %q{"" or "5"}
end
end
context 'Prod Method' do
requirement 'Create a prod method that computes the multiples in the expression' do
detail 'The method will return the product of the numbers'
example %q{"0" computes to 0}
example %q{"2,1" computes to 2}
example %q{"3,2,1" computes to 6}
end
end
context 'Div Method' do
requirement 'Create a div method that computes the consecutive divisions in the expression' do
detail 'The method will return the final quotient of the numbers'
detail 'it will raise an exception if the expression contains the number 0'
example %q{"2,1" computes to 2}
example %q{"3,2,1" computes to 1}
example %q{"1,2,3" computes to 0}
end
end
end