Skip to content

Commit 3ed5d0a

Browse files
authored
python test suite example change array to list (#256)
1 parent f3463a8 commit 3ed5d0a

File tree

1 file changed

+11
-11
lines changed
  • content/languages/python/authoring

1 file changed

+11
-11
lines changed

content/languages/python/authoring/index.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ The Codewars runner provides a set of preinstalled packages, which are available
165165

166166
### Reference solution
167167

168-
If the test suite happens to use a reference solution to calculate expected values (which [should be avoided](/authoring/guidelines/submission-tests/#reference-solution) when possible), or some kind of reference data like precalculated arrays, etc., it must not be possible for the user to redefine, overwrite or directly access its contents. To prevent this, it should be defined in a scope local to the testing function, a `it` or a `describe` block.
168+
If the test suite happens to use a reference solution to calculate expected values (which [should be avoided](/authoring/guidelines/submission-tests/#reference-solution) when possible), or some kind of reference data like precalculated lists, etc., it must not be possible for the user to redefine, overwrite or directly access its contents. To prevent this, it should be defined in a scope local to the testing function, a `it` or a `describe` block.
169169

170170
The reference solution or data ___must not___ be defined in the top-level scope of the test suite or in the [Preloaded code](/authoring/guidelines/preloaded/).
171171

@@ -206,8 +206,8 @@ def fixed_tests():
206206

207207
@test.it('Edge cases')
208208
def edge_cases():
209-
test.assert_equals(user_solution([]), 0, "Invalid answer for empty array")
210-
test.assert_equals(user_solution([2]), 2, "Invalid answer for one element array")
209+
test.assert_equals(user_solution([]), 0, "Invalid answer for empty list")
210+
test.assert_equals(user_solution([2]), 2, "Invalid answer for one element list")
211211

212212
@test.it('Input should not be modified')
213213
def do_not_mutate_input():
@@ -217,7 +217,7 @@ def fixed_tests():
217217
#call user solution and ignore the result
218218
user_solution(arr_copy)
219219
#arr_copy should not be modified
220-
test.assert_equals(arr_copy, source_arr, 'Input array was modified')
220+
test.assert_equals(arr_copy, source_arr, 'Input list was modified')
221221

222222

223223
@test.describe('Random tests')
@@ -233,20 +233,20 @@ def random_tests():
233233
def generate_small_inputs():
234234
test_cases = []
235235

236-
#first type of input: regular array of small inputs (many of them)
236+
#first type of input: regular list of small inputs (many of them)
237237
for _ in range(50):
238238
test_cases.append(generate_small_test_case())
239239

240-
#another type of input: array with potentially tricky numbers
240+
#another type of input: list with potentially tricky numbers
241241
#(possibly many of them)
242242
for _ in range(50):
243243
test_cases.append(generate_small_tricky_test_case())
244244

245-
#potential edge case of single element array (a few of them)
245+
#potential edge case of single element list (a few of them)
246246
for _ in range(10):
247247
test_cases.append(generate_single_element_edge_case())
248248

249-
#another edge case: empty array
249+
#another edge case: empty list
250250
#Not always necessary, usually fixed test is enough.
251251
#If present, there's no need for more than one.
252252
test_cases.append([])
@@ -270,7 +270,7 @@ def random_tests():
270270
for input in inputs:
271271

272272
#call reference solution first, in separate statement.
273-
#we know it does not mutate the array, so no copy is needed
273+
#we know it does not mutate the list, so no copy is needed
274274
expected = reference_solution(input)
275275

276276
#call user solution and get actual answer.
@@ -294,8 +294,8 @@ def random_tests():
294294
expected = reference_solution(input)
295295

296296
#assertion message composed before the user solution has a chance
297-
#to mutate the input array
298-
message = f'Invalid answer for array of length {len(input)}'
297+
#to mutate the input list
298+
message = f'Invalid answer for list of length {len(input)}'
299299

300300
#actual answer calculated as second.
301301
#no copy is made because input is not used anymore

0 commit comments

Comments
 (0)