Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exercises/gigasecond/.meta/generator/gigasecond_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def want
end

def start_values
ts = Time.parse(birthdate)
ts = Time.parse(moment)
[ts.year, ts.month, ts.day, ts.hour, ts.min, ts.sec]
end

Expand Down
2 changes: 1 addition & 1 deletion exercises/gigasecond/gigasecond_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'minitest/autorun'
require_relative 'gigasecond'

# Common test data version: 1.1.0 5506bac
# Common test data version: 2.0.0 2e1c5ac
class GigasecondTest < Minitest::Test
def test_date_only_specification_of_time
# skip
Expand Down
2 changes: 1 addition & 1 deletion exercises/phone-number/phone_number_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'minitest/autorun'
require_relative 'phone_number'

# Common test data version: 1.6.1 fc57696
# Common test data version: 1.7.0 435b472
class PhoneNumberTest < Minitest::Test
def test_cleans_the_number
# skip
Expand Down
18 changes: 9 additions & 9 deletions exercises/space-age/space_age_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'minitest/autorun'
require_relative 'space_age'

# Common test data version: 1.1.0 8d4df79
# Common test data version: 1.2.0 28b3dac
class SpaceAgeTest < Minitest::Test
# assert_in_delta will pass if the difference
# between the values being compared is less
Expand All @@ -28,8 +28,8 @@ def test_age_on_venus

def test_age_on_mars
skip
age = SpaceAge.new(2_329_871_239)
assert_in_delta 39.25, age.on_mars, DELTA
age = SpaceAge.new(2_129_871_239)
assert_in_delta 35.88, age.on_mars, DELTA
end

def test_age_on_jupiter
Expand All @@ -40,19 +40,19 @@ def test_age_on_jupiter

def test_age_on_saturn
skip
age = SpaceAge.new(3_000_000_000)
assert_in_delta 3.23, age.on_saturn, DELTA
age = SpaceAge.new(2_000_000_000)
assert_in_delta 2.15, age.on_saturn, DELTA
end

def test_age_on_uranus
skip
age = SpaceAge.new(3_210_123_456)
assert_in_delta 1.21, age.on_uranus, DELTA
age = SpaceAge.new(1_210_123_456)
assert_in_delta 0.46, age.on_uranus, DELTA
end

def test_age_on_neptune
skip
age = SpaceAge.new(8_210_123_456)
assert_in_delta 1.58, age.on_neptune, DELTA
age = SpaceAge.new(1_821_023_456)
assert_in_delta 0.35, age.on_neptune, DELTA
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class SumOfMultiples
attr_reader :multiples
def initialize(*multiples)
@multiples = multiples
@multiples = multiples.reject(&:zero?)
end

def to(limit)
Expand Down
8 changes: 7 additions & 1 deletion exercises/sum-of-multiples/sum_of_multiples_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'minitest/autorun'
require_relative 'sum_of_multiples'

# Common test data version: 1.4.1 8f89751
# Common test data version: 1.5.0 bd2d4d9
class SumOfMultiplesTest < Minitest::Test
def test_no_multiples_within_limit
# skip
Expand Down Expand Up @@ -87,6 +87,12 @@ def test_the_only_multiple_of_0_is_0
assert_equal 0, sum_of_multiples.to(1)
end

def test_the_factor_0_does_not_affect_the_sum_of_multiples_of_other_factors
skip
sum_of_multiples = SumOfMultiples.new(3, 0)
assert_equal 3, sum_of_multiples.to(4)
end

def test_solutions_using_include_exclude_must_extend_to_cardinality_greater_than_3
skip
sum_of_multiples = SumOfMultiples.new(2, 3, 5, 7, 11)
Expand Down
28 changes: 7 additions & 21 deletions exercises/wordy/.meta/solutions/wordy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ def answer
end

unless @answer
@answer = n1.send(operation(2), n2)
@answer = @answer.send(operation(5), n3) if chain?
@answer = matches[1].to_i
matches[2..-1].compact.each_slice(2) do |op, number|
@answer = @answer.public_send(operation(op), number.to_i)
end
end

@answer
Expand All @@ -29,31 +31,15 @@ def matches

def pattern
operations = '(plus|minus|multiplied by|divided by)'
/What is (-?\d+) #{operations} (-?\d+)( #{operations} (-?\d+))?\?/
/What is (-?\d+)(?: #{operations} (-?\d+))?(?: #{operations} (-?\d+))?\?/
end

def operation(index)
case matches[index]
def operation(op)
case op
when 'plus' then :+
when 'minus' then :-
when 'multiplied by' then :*
when 'divided by' then :/
end
end

def n1
matches[1].to_i
end

def n2
matches[3].to_i
end

def n3
matches[6].to_i
end

def chain?
!!matches[4]
end
end
58 changes: 56 additions & 2 deletions exercises/wordy/wordy_test.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
require 'minitest/autorun'
require_relative 'wordy'

# Common test data version: 1.2.0 86d0069
# Common test data version: 1.5.0 51c9b0b
class WordyTest < Minitest::Test
def test_addition
def test_just_a_number
# skip
problem = WordProblem.new("What is 5?")
assert_equal(5, problem.answer)
end

def test_addition
skip
problem = WordProblem.new("What is 1 plus 1?")
assert_equal(2, problem.answer)
end
Expand Down Expand Up @@ -103,4 +109,52 @@ def test_non_math_question
problem.answer
end
end

def test_reject_problem_missing_an_operand
skip
problem = WordProblem.new("What is 1 plus?")
assert_raises(ArgumentError) do
problem.answer
end
end

def test_reject_problem_with_no_operands_or_operators
skip
problem = WordProblem.new("What is?")
assert_raises(ArgumentError) do
problem.answer
end
end

def test_reject_two_operations_in_a_row
skip
problem = WordProblem.new("What is 1 plus plus 2?")
assert_raises(ArgumentError) do
problem.answer
end
end

def test_reject_two_numbers_in_a_row
skip
problem = WordProblem.new("What is 1 plus 2 1?")
assert_raises(ArgumentError) do
problem.answer
end
end

def test_reject_postfix_notation
skip
problem = WordProblem.new("What is 1 2 plus?")
assert_raises(ArgumentError) do
problem.answer
end
end

def test_reject_prefix_notation
skip
problem = WordProblem.new("What is plus 1 2?")
assert_raises(ArgumentError) do
problem.answer
end
end
end