← 返回 amazon 的题目列表Sort and Run Tests
类型:online_judge
Given a Test class which includes multiple test cases, each with different fields, your task is to sort the list of test cases by a specified field and then execute each test concurrently while handling any errors. The requirements are:
Implement a Test class with the following example fields:
name (string)
priority (integer)
duration (float)
Implement sort_tests(tests, field) function to sort the test cases by the given field.
Implement run_tests_concurrently(tests) to run the tests concurrently. During execution, any errors must be logged and the remaining tests should continue to run.
Provide sample input and output:
Test Case 1:
Input:
[{"name": "test1", "priority": 3, "duration": 1.5}, {"name": "test2", "priority": 1, "duration": 2.0}, {"name": "test3", "priority": 2, "duration": 1.0}]
Sorting Field: priority
Expected Output: [{"name": "test2", "priority": 1, "duration": 2.0}, {"name": "test3", "priority": 2, "duration": 1.0}, {"name": "test1", "priority": 3, "duration": 1.5}]
Scale of Data: Test cases will not exceed 1000, and field lengths will not exceed 100.
Example
Input
[{"name": "test1", "priority": 3, "duration": 1.5}, {"name": "test2", "priority": 1, "duration": 2.0}, {"name": "test3", "priority": 2, "duration": 1.0}]