Skip to content

Commit

Permalink
[palindrome-products] Add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
themetar committed Oct 1, 2024
1 parent 493eb2d commit f58de12
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
24 changes: 24 additions & 0 deletions exercises/practice/palindrome-products/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[5cff78fe-cf02-459d-85c2-ce584679f887]
description = "find the smallest palindrome from single digit factors"

[0853f82c-5fc4-44ae-be38-fadb2cced92d]
description = "find the largest palindrome from single digit factors"

Expand All @@ -23,3 +26,24 @@ description = "find the smallest palindrome from triple digit factors"

[edab43e1-c35f-4ea3-8c55-2f31dddd92e5]
description = "find the largest palindrome from triple digit factors"

[4f802b5a-9d74-4026-a70f-b53ff9234e4e]
description = "find the smallest palindrome from four digit factors"

[787525e0-a5f9-40f3-8cb2-23b52cf5d0be]
description = "find the largest palindrome from four digit factors"

[58fb1d63-fddb-4409-ab84-a7a8e58d9ea0]
description = "empty result for smallest if no palindrome in the range"

[9de9e9da-f1d9-49a5-8bfc-3d322efbdd02]
description = "empty result for largest if no palindrome in the range"

[12e73aac-d7ee-4877-b8aa-2aa3dcdb9f8a]
description = "error result for smallest if min is more than max"

[eeeb5bff-3f47-4b1e-892f-05829277bd74]
description = "error result for largest if min is more than max"

[16481711-26c4-42e0-9180-e2e4e8b29c23]
description = "smallest product does not use the smallest factor"
74 changes: 74 additions & 0 deletions exercises/practice/palindrome-products/palindrome_products_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
require_relative 'palindrome_products'

class PalindromesTest < Minitest::Test
def test_smallest_palindrome_from_single_digit_factors
palindromes = Palindromes.new(max_factor: 9)
palindromes.generate
smallest = palindromes.smallest
assert_equal 1, smallest.value
assert_equal [[1, 1]], smallest.factors
end

def test_largest_palindrome_from_single_digit_factors
skip
palindromes = Palindromes.new(max_factor: 9)
palindromes.generate
largest = palindromes.largest
Expand Down Expand Up @@ -45,4 +54,69 @@ def test_smallest_palindrome_from_triple_digit_factors
assert_equal 10_201, smallest.value
assert_equal [[101, 101]], smallest.factors
end

def test_smallest_palindrome_from_four_digit_factors
skip
palindromes = Palindromes.new(min_factor: 1000, max_factor: 9999)
palindromes.generate
smallest = palindromes.smallest
assert_equal 1_002_001, smallest.value
assert_equal [[1001, 1001]], smallest.factors
end

def test_largest_palindrome_from_four_digit_factors
skip
palindromes = Palindromes.new(min_factor: 1000, max_factor: 9999)
palindromes.generate
largest = palindromes.largest
assert_equal 99_000_099, largest.value
assert_equal [[9901, 9999]], largest.factors
end

def test_empty_for_smallest_if_no_palindrome_in_range
skip
palindromes = Palindromes.new(min_factor: 1002, max_factor: 1003)
palindromes.generate
smallest = palindromes.smallest
assert_nil smallest.value
assert_empty smallest.factors
end

def test_empty_for_largest_if_no_palindrome_in_range
skip
palindromes = Palindromes.new(min_factor: 15, max_factor: 15)
palindromes.generate
largest = palindromes.largest
assert_nil largest.value
assert_empty largest.factors
end

def test_error_for_smallest_if_min_more_than_max
skip
error = assert_raises(ArgumentError) do
palindromes = Palindromes.new(min_factor: 10_000, max_factor: 1)
palindromes.generate
palindromes.smallest
end
assert_equal "min must be <= max", error.message
end

def test_error_for_largest_if_min_more_than_max
skip
error = assert_raises(ArgumentError) do
palindromes = Palindromes.new(min_factor: 2, max_factor: 1)
palindromes.generate
palindromes.smallest
end
assert_equal "min must be <= max", error.message
end

def test_smallest_palindrome_does_not_use_smallest_factors
skip
palindromes = Palindromes.new(min_factor: 3215, max_factor: 4000)
palindromes.generate
smallest = palindromes.smallest
assert_equal 10_988_901, smallest.value
assert_equal [[3297, 3333]], smallest.factors
end
end

0 comments on commit f58de12

Please sign in to comment.