news 2026/6/9 11:26:59

(100分)- 测试用例执行计划(Java JS Python C)

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
(100分)- 测试用例执行计划(Java JS Python C)

(100分)- 测试用例执行计划(Java & JS & Python & C)

题目描述

某个产品当前迭代周期内有 N 个特性(F1,F2,......FN)需要进行覆盖测试,每个特性都被评估了对应的优先级,特性使用其 ID 作为下标进行标识。

设计了 M 个测试用例(T1,T2,......,TM),每个测试用例对应一个覆盖特性的集合,测试用例使用其 ID 作为下标进行标识,测试用例的优先级定义为其覆盖的特性的优先级之和。

在开展测试之前,需要制定测试用例的执行顺序,规则为:优先级大的用例先执行,如果存在优先级相同的用例,用例 ID 小的先执行。

输入描述

第一行输入为 N 和 M,

  • N 表示特性的数量,0 < N ≤ 100
  • M 表示测试用例的数量,0 < M ≤ 100

之后 N 行表示特性 ID=1 到特性 ID=N 的优先级,

再接下来 M 行表示测试用例 ID=1 到测试用例 ID=M 关联的特性的 ID 的列表。

输出描述

按照执行顺序(优先级从大到小)输出测试用例的 ID,每行一个ID。

测试用例覆盖的 ID 不重复。

用例
输入5 4
1
1
2
3
5
1 2 3
1 4
3 4 5
2 3 4
输出3
4
1
2
说明

测试用例的优先级计算如下:

T1 = Pf1 + Pf2 + Pf3 = 1 + 1 + 2 = 4
T2 = Pf1 + Pf4 = 1 + 3 = 4
T3 = Pf3 + Pf4 + Pf5 = 2 + 3 + 5 = 10
T4 = Pf2 + Pf3 + Pf4 = 1 + 2 + 3 = 6

按照优先级从小到大,以及相同优先级,ID小的先执行的规则,执行顺序为T3,T4,T1,T2

输入3 3
3
1
5
1 2 3
1 2 3
1 2 3
输出1
2
3
说明

测试用例的优先级计算如下:

T1 = Pf1 + Pf2 + Pf3 = 3 + 1 + 5 = 9
T2 = Pf1 + Pf2 + Pf3 = 3 + 1 + 5 = 9
T3 = Pf1 + Pf2 + Pf3 = 3 + 1 + 5 = 9

每个优先级一样,按照 ID 从小到大执行,执行顺序为T1,T2,T3

题目解析

简单的自定义排序问题。

JS算法源码
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; void (async function () { const [n, m] = (await readline()).split(" ").map(Number); const features = new Array(n + 1); for (let i = 1; i <= n; i++) { features[i] = parseInt(await readline()); } const cases = []; for (let i = 1; i <= m; i++) { const priority = (await readline()) .split(" ") .map((id) => features[id - 0]) // id-0是为了将字符串id转为数值id .reduce((a, b) => a + b); cases.push([priority, i]); } cases .sort((a, b) => (a[0] != b[0] ? b[0] - a[0] : a[1] - b[1])) .forEach(([_, id]) => console.log(id)); // forEach入参使用了数组解构语法 })();
Java算法源码
import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Main { static class TestCase { int id; int priority; public TestCase(int id, int priority) { this.id = id; this.priority = priority; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] tmp = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray(); int n = tmp[0]; int m = tmp[1]; int[] features = new int[n + 1]; for (int i = 1; i <= n; i++) { features[i] = Integer.parseInt(sc.nextLine()); } ArrayList<TestCase> cases = new ArrayList<>(); for (int i = 1; i <= m; i++) { int priority = Arrays.stream(sc.nextLine().split(" ")) .map(Integer::parseInt) .map(id -> features[id]) .reduce(Integer::sum) .orElse(0); cases.add(new TestCase(i, priority)); } cases.stream() .sorted((a, b) -> a.priority != b.priority ? b.priority - a.priority : a.id - b.id) .map(testcase -> testcase.id) .forEach(System.out::println); } }
Python算法源码
# 输入获取 n, m = map(int, input().split()) features = [0] * (n + 1) for i in range(1, n+1): features[i] = int(input()) cases = [] for i in range(1, m+1): priority = sum(map(lambda x: features[int(x)], input().split())) cases.append([priority, i]) cases.sort(key=lambda x: (-x[0], x[1])) for _, idx in cases: print(idx)
C算法源码
#include <stdio.h> #include <stdlib.h> typedef struct { int priority; int id; } TestCase; TestCase *new_TestCase(int id) { TestCase *testcase = (TestCase *) malloc(sizeof(TestCase)); testcase->priority = 0; testcase->id = id; return testcase; } int cmp(const void *a, const void *b) { TestCase *A = *((TestCase **) a); TestCase *B = *((TestCase **) b); return A->priority != B->priority ? B->priority - A->priority : A->id - B->id; } int main() { int n, m; scanf("%d %d", &n, &m); int features[n + 1]; for (int i = 1; i <= n; i++) { scanf("%d", &features[i]); } TestCase *cases[m]; for (int i = 0; i < m; i++) { cases[i] = new_TestCase(i + 1); int feature_id; while (scanf("%d", &feature_id)) { cases[i]->priority += features[feature_id]; if (getchar() != ' ') break; } } qsort(cases, m, sizeof(TestCase *), cmp); for (int i = 0; i < m; i++) { printf("%d\n", cases[i]->id); } return 0; }
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/6/9 19:47:20

智慧铁路之受电弓接触点识别 铁路输电线路鸟巢识别 铁路异物入侵巡检识别 铁路风筝识别 列车绝缘子检测 轨道交通场景下异物识别 户外线缆及附属部件的智能监测 10325期

智慧铁路识别类别介绍 Classes (19) 类别&#xff08;19&#xff09; CJumper C型 jumper ClothesHanging 挂着的衣服 GJumper 跳线 baloon 气球 bird_nest 鸟巢 bird_strike 鸟击 cantilever 悬臂 crossover 交叉线 damage_insulator 损坏的绝缘子 drop_wire 引入线 dropper 吊…

作者头像 李华
网站建设 2026/6/9 23:40:39

生成式视频技术商业化加速

生成式视频技术商业化现状 生成式视频技术通过AI模型自动创建或编辑视频内容&#xff0c;已在多个领域实现商业化落地。典型应用包括广告制作、影视预演、电商短视频生成、虚拟主播等。OpenAI的Sora模型展示了文本到视频生成的潜力&#xff0c;Meta、谷歌等公司也在推进类似技术…

作者头像 李华
网站建设 2026/6/9 19:48:01

【读书笔记】《苏格拉底的申辩》

苏格拉底的申辩&#xff1a;解读柏拉图经典著作 一、引言&#xff1a;苏格拉底与哲学史的重大转向 苏格拉底是西方哲学史上最著名的人物之一。他的重要性不仅在于名气&#xff0c;更在于他标志着哲学从“自然”转向“人生”的关键转折。 苏格拉底之前&#xff1a;前苏格拉底哲学…

作者头像 李华
网站建设 2026/6/9 22:37:08

Thinkphp和Laravel时光音乐播放下载平台的设计与实现-vue

目录具体实现截图项目开发技术介绍PHP核心代码部分展示系统结论源码获取/同行可拿货,招校园代理具体实现截图 本系统&#xff08;程序源码数据库调试部署讲解&#xff09;带文档1万字以上 同行可拿货,招校园代理 Thinkphp和Laravel时光音乐播放下载平台的设计与实现-vue …

作者头像 李华
网站建设 2026/6/9 22:33:17

vn_pwn_easyTHeap PWN tcache_perthread_struct利用

因为本机是ubuntu22所以先把libc依赖改回2.27 IDA分析main函数这里有个alarm时间限制目录安全写这是一个添加chunk&#xff0c;但是这里面只能有7个chunk&#xff0c;所以不能用普通的把tcache填满放入unsoredbin从来算libc这是编辑read(0, (void *)s_[n6], s__0[n6]) - 从标准…

作者头像 李华
网站建设 2026/6/9 21:06:58

延凡智慧水库系统:数字孪生+AI驱动水库安全与智能调度

延凡智慧水库系统是专为中小型水库、灌区水库及流域管理单位打造的轻量化智能管控解决方案&#xff0c;深度契合水利部《推进水库运行管理数字孪生的指导意见》及《水库大坝安全监测管理办法》核心要求&#xff0c;聚焦“安全防控、防汛抗旱、水资源优化、合规管理”核心目标&a…

作者头像 李华