Skip to content

Instantly share code, notes, and snippets.

@sherpc
Last active December 16, 2015 11:19
Show Gist options
  • Save sherpc/5426678 to your computer and use it in GitHub Desktop.
Save sherpc/5426678 to your computer and use it in GitHub Desktop.
# Метод, который хотим тестировать
def det(matrix)
# fake implementation
0
end
def do_det_test(test_case)
result = det(test_case[:data])
assert_equal(result, test_case[:expected])
end
def test_det
cases = [
{data: MATRIX_2, expected: -6},
{data: MATRIX_3, expected: 946},
{data: Data::LU_A, expected: 1867}
]
cases.each { |test_case| do_det_test test_case }
end
# Хочется вместо 2х методов писать так:
test_method(det, [
{args: MATRIX_2, expected: -6},
{args: MATRIX_3, expected: 946},
{args: Data::LU_A, expected: 1867}
])
# Еще пример:
def f(a, b)
a + b
end
test_method(f,[
{args: [1, 2], expected: 3},
{args: [-1, 2], expected: 1},
{args: [0, 0], expected: 0},
{args: [0, 2], expected: 2},
])
# Или:
test_method(f,[
[[1, 2], 3],
[[-1, 2], 1],
[[0, 0], 0],
[[0, 2], 2]
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment