Skip to content

Instantly share code, notes, and snippets.

@sato11
Created October 31, 2020 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sato11/211bf716096d34dca5f7b5ac8184caf2 to your computer and use it in GitHub Desktop.
Save sato11/211bf716096d34dca5f7b5ac8184caf2 to your computer and use it in GitHub Desktop.
# test cases that i've used for the lesson below:
# https://app.codility.com/programmers/lessons/5-prefix_sums/count_div/
require 'minitest/autorun'
class CountDivTest < Minitest::Test
def test_solution
a, b, k = [6, 11, 2]
assert_equal 3, solution(a, b, k)
a, b, k = [7, 11, 2]
assert_equal 2, solution(a, b, k)
a, b, k = [6, 11, 3]
assert_equal 2, solution(a, b, k)
a, b, k = [7, 11, 3]
assert_equal 1, solution(a, b, k)
end
def test_minimal
a, b, k = [0, 0, 11]
assert_equal 1, solution(a, b, k)
end
def test_k_larger_than_b
a, b, k = [12, 15, 20]
assert_equal 0, solution(a, b, k)
end
def test_k_smaller_than_b
a, b, k = [12, 27, 20]
assert_equal 1, solution(a, b, k)
end
def test_extreme_ifempty
a, b, k = [10, 10, 5]
assert_equal 1, solution(a, b, k)
a, b, k = [10, 10, 7]
assert_equal 0, solution(a, b, k)
a, b, k = [10, 10, 20]
assert_equal 0, solution(a, b, k)
end
def test_medium_numbers
a, b, k = [100, 900, 32]
count = 0
100.upto(900) do |i|
count += 1 if i % k == 0
end
assert_equal count, solution(a, b, k)
end
def test_large_input
a, b, k = [101, 123_456_789, 10_000]
assert_equal 12345, solution(a, b, k)
a, b, k = [0, 2_000_000_000, 1]
assert_equal 2_000_000_001, solution(a, b, k)
end
def test_large_k
a, b, k = [0, 1_999_999_999, 2_000_000_000]
assert_equal 1, solution(a, b, k)
a, b, k = [1, 1_999_999_999, 2_000_000_000]
assert_equal 0, solution(a, b, k)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment