Skip to content

Commit

Permalink
Restore identity, add hint messages
Browse files Browse the repository at this point in the history
re: #10
Changes per discussion at PR: #170
  • Loading branch information
kotp committed Jun 17, 2015
1 parent 9176851 commit 7e52f2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
9 changes: 3 additions & 6 deletions largest-series-product/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ def initialize(numeric_string)
def largest_product(length)
@length = length
validate_length
analyzer
return 1 if @digits.empty?
collection_of_digits
select_max { reduce_to_product { validate { separate } } }
end

private
Expand All @@ -19,11 +21,6 @@ def validate_length
fail(ArgumentError.new 'Not enough digits')
end

def analyzer
collection_of_digits
select_max { reduce_to_product { validate { separate } } }
end

def validate
yield.take_while { |array| array.size == @length }
end
Expand Down
14 changes: 12 additions & 2 deletions largest-series-product/largest_series_product_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# Rubocop directives
# rubocop:disable Lint/ParenthesesAsGroupedExpression
# rubocop:disable Style/AlignParameters:
#
class Seriestest < Minitest::Test
def test_largest_product_of_a_tiny_number
Expand All @@ -21,13 +22,15 @@ def test_another_tiny_number
def test_largest_product_of_2
skip
series = Series.new('0123456789')
assert_equal 72, series.largest_product(2)
assert_equal 72, series.largest_product(2),
'Largest product of all sets of 2 result from 8 and 9'
end

def test_largest_product_of_2_shuffled
skip
series = Series.new('576802143')
assert_equal 48, series.largest_product(2)
assert_equal 48, series.largest_product(2),
'Largest product of all sets of 2 result from 6 and 8'
end

def test_largest_product_of_3
Expand Down Expand Up @@ -62,6 +65,13 @@ def test_some_other_big_number
assert_equal 28_350, series.largest_product(6)
end

def test_identity
skip
series = Series.new('')
assert_equal 1, series.largest_product(0),
'Identity of an empty group is 1'

This comment has been minimized.

Copy link
@markijbema

markijbema Jun 17, 2015

Contributor

strictly seen 'empty group over multiplication', since the identity for a 'default' group (integers over addition) would be zero.

end

def test_slices_bigger_than_number
skip
series = Series.new('123')
Expand Down

0 comments on commit 7e52f2d

Please sign in to comment.