惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threatpost
博客园 - 叶小钗
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
D
DataBreaches.Net
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
N
Netflix TechBlog - Medium
Microsoft Azure Blog
Microsoft Azure Blog
Microsoft Security Blog
Microsoft Security Blog
B
Blog
U
Unit 42
有赞技术团队
有赞技术团队
博客园 - 聂微东
GbyAI
GbyAI
宝玉的分享
宝玉的分享
F
Full Disclosure
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MyScale Blog
MyScale Blog
Jina AI
Jina AI
Martin Fowler
Martin Fowler
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Docker
P
Proofpoint News Feed
A
About on SuperTechFans
I
InfoQ
博客园 - 【当耐特】
C
Check Point Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
T
Threat Research - Cisco Blogs
Y
Y Combinator Blog
Project Zero
Project Zero
WordPress大学
WordPress大学
小众软件
小众软件
AWS News Blog
AWS News Blog
博客园 - 司徒正美
T
The Exploit Database - CXSecurity.com
L
LINUX DO - 热门话题
I
Intezer
Engineering at Meta
Engineering at Meta
C
CXSECURITY Database RSS Feed - CXSecurity.com
J
Java Code Geeks
T
Tenable Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Last Week in AI
Last Week in AI
C
CERT Recently Published Vulnerability Notes

RSS feed of yihong0618's gitblog

12 月,姥姥,以及大模型 · Issue #344 · yihong0618/gitblog 不要自动化你的情感链接 · Issue #343 · yihong0618/gitblog 那些幸福的瞬间 · Issue #342 · yihong0618/gitblog 12 年过去了,你过得还好么? · Issue #341 · yihong0618/gitblog Be a human, not a claw. · Issue #339 · yihong0618/gitblog 新年快乐以及一些近况 · Issue #338 · yihong0618/gitblog 偶得的佳句与 AI · Issue #337 · yihong0618/gitblog 确定性的丧失 · Issue #336 · yihong0618/gitblog Something Boring or Interesting · Issue #335 · yihong0618/gitblog 2025 年我提了 500 个 Pull Requests · Issue #334 · yihong0618/gitblog 网友 · Issue #333 · yihong0618/gitblog 如何判断一个项目是个好的开源项目并且想贡献? · Issue #331 · yihong0618/gitblog Things I don’t like · Issue #329 · yihong0618/gitblog Notes on Pycon2025 · Issue #327 · yihong0618/gitblog 从错误中学习 · Issue #326 · yihong0618/gitblog 一次艰难的 cpython issue 排查过程,以及我学到了什么 · Issue #325 · yihong0618/gitblog 八月 · Issue #324 · yihong0618/gitblog 从给 Greptime 贡献代码的过程中,我都学到了什么 · Issue #320 · yihong0618/gitblog Notes on May · Issue #318 · yihong0618/gitblog Things I like · Issue #311 · yihong0618/gitblog 我的 35 岁 · Issue #309 · yihong0618/gitblog 连续跑了 365 天 · Issue #306 · yihong0618/gitblog 最近给开源项目贡献的记录 · Issue #304 · yihong0618/gitblog 2020-2025 最喜欢的 12 篇文章和一张图 · Issue #302 · yihong0618/gitblog 断章 · Issue #301 · yihong0618/gitblog 这两个月 · Issue #299 · yihong0618/gitblog 从给 RisingWave 提 PR 说起,聊聊怎么快速切入一个复杂的开源项目 · Issue #296 · yihong0618/gitblog 能几日,又中秋 · Issue #294 · yihong0618/gitblog 第一次 AI 尝试,完全用 AI(MarsCode) 做个需求 · Issue #293 · yihong0618/gitblog 一件趣事儿 · Issue #292 · yihong0618/gitblog 这玩意不是就__ · Issue #291 · yihong0618/gitblog 六月 · Issue #290 · yihong0618/gitblog 跑了 10000km 花了 13 年 · Issue #289 · yihong0618/gitblog 抉择 · Issue #287 · yihong0618/gitblog 三月 · Issue #283 · yihong0618/gitblog About Me · Issue #282 · yihong0618/gitblog 用小爱加手指机器人实现传统开关语音关灯 · Issue #281 · yihong0618/gitblog 记忆碎片 · Issue #280 · yihong0618/gitblog 开源值得么? · Issue #279 · yihong0618/gitblog 聊聊读书 · Issue #275 · yihong0618/gitblog 旧文,移动端最好的游戏,《Dream Quest》以及其它 · Issue #274 · yihong0618/gitblog 微信好友 · Issue #272 · yihong0618/gitblog 如何写一个 PostgreSQL Extension · Issue #270 · yihong0618/gitblog 五月病 · Issue #268 · yihong0618/gitblog 杂感 · Issue #262 · yihong0618/gitblog vm.overcommit_memory 学习笔记 · Issue #261 · yihong0618/gitblog 开源四年的一些记录 · Issue #259 · yihong0618/gitblog 不用 root 使用小爱同学和 ChatGPT 交互折腾记 · Issue #258 · yihong0618/gitblog 用 eBPF trace PostgreSQL 的几种姿势 · Issue #257 · yihong0618/gitblog 2022 失落的一年 · Issue #255 · yihong0618/gitblog 写诗吧 · Issue #254 · yihong0618/gitblog 利用 GitHubPoster 和 GitHub Actions 备份任意用户推特 · Issue #252 · yihong0618/gitblog 一杯敬月光 · Issue #251 · yihong0618/gitblog 如何判断一个数字帐号来自中国大陆 · Issue #248 · yihong0618/gitblog Random Thoughts · Issue #242 · yihong0618/gitblog 反思 · Issue #241 · yihong0618/gitblog 今天的跑步电台 · Issue #239 · yihong0618/gitblog 新冠纪元 · Issue #235 · yihong0618/gitblog Postgres 需要学的东西 · Issue #234 · yihong0618/gitblog Postgres 中 GUC 的一些记录 · Issue #233 · yihong0618/gitblog 运交华盖欲何求 · Issue #231 · yihong0618/gitblog 年终岁尾 · Issue #230 · yihong0618/gitblog 二零二二的三个小目标 · Issue #229 · yihong0618/gitblog 经历了人生体验最棒的一次面试 · Issue #228 · yihong0618/gitblog 参加了《开源面对面》《ByteTalk》《枫言枫语》播客的一些记录 · Issue #223 · yihong0618/gitblog 有趣与无趣 · Issue #221 · yihong0618/gitblog running_page 开源一周年的总结 · Issue #220 · yihong0618/gitblog 接下来要写的东西 · Issue #219 · yihong0618/gitblog 一点思考 · Issue #218 · yihong0618/gitblog 友情链接 · Issue #217 · yihong0618/gitblog 朋友圈 · Issue #216 · yihong0618/gitblog 张小龙的饭否 · Issue #215 · yihong0618/gitblog 一件小事 · Issue #214 · yihong0618/gitblog 从 Rich 作者的一个问题说起 · Issue #212 · yihong0618/gitblog 如何用一个仓库记录自己的一年 · Issue #209 · yihong0618/gitblog 逃离 · Issue #208 · yihong0618/gitblog 近况 · Issue #207 · yihong0618/gitblog 年过完了 · Issue #206 · yihong0618/gitblog 力扣的程序是如何运行的 · Issue #205 · yihong0618/gitblog 生存守则 · Issue #204 · yihong0618/gitblog 沮丧 · Issue #203 · yihong0618/gitblog 今年的三个小目标 · Issue #202 · yihong0618/gitblog 新年碎碎念 · Issue #201 · yihong0618/gitblog 二零二一开始 · Issue #200 · yihong0618/gitblog 记住这一刻 · Issue #199 · yihong0618/gitblog 巧妙利用 iOS 的快捷指令配合 GitHub Actions 实现自动化 · Issue #198 · yihong0618/gitblog 如何获取悦跑圈数据 · Issue #197 · yihong0618/gitblog 生的对立面 · Issue #196 · yihong0618/gitblog 推荐一些我一直关注的觉得不错的和 Python 相关的独立博客 · Issue #195 · yihong0618/gitblog 2020 年 10 月总结 11 月计划 · Issue #194 · yihong0618/gitblog 写在 0x20 岁之前 · Issue #193 · yihong0618/gitblog 如何获取 keep 跑步数据 · Issue #191 · yihong0618/gitblog 2020 年 9 月总结 10 月计划 · Issue #190 · yihong0618/gitblog 决定把gitblog和kb结合起来 · Issue #189 · yihong0618/gitblog 感冒了,真是难受 · Issue #188 · yihong0618/gitblog 把running page 变得通用必须提上日程了 · Issue #187 · yihong0618/gitblog 我转行程序员的经历 · Issue #186 · yihong0618/gitblog 普通人和天才之间的巨大鸿沟 · Issue #185 · yihong0618/gitblog 月跑 250 km计划 · Issue #184 · yihong0618/gitblog 2020年八月总结九月月展望 · Issue #182 · yihong0618/gitblog
LeetCode 是如何运行的--测试篇 · Issue #237 · yihong0618/gitblog
yihong0618 · 2022-07-01 · via RSS feed of yihong0618's gitblog

有段日子没写博客了。
一般情况,四张图加上 140 字能表达的内容我就直接发推了,想到这个可能会超过这个长度,就写在这里吧。
当然有个前情提要,感恩 GitHub Issues 的双向链接,

  • 我只需要 力扣的程序是如何运行的 #205 大家就可以直接看到上一篇的相关文章了 --《力扣的程序是如何运行的》,我昨天自己也看了一遍哈哈。所以这篇的格式也会跟上一篇一样。

起因

最近心血来潮决定去刷几道题,上一次也是第一次刷题还是 3 年前了。
image

刷题的过程中感觉到了自己的不足。写完代码就直接提交了,结果很多时候是错的。也发现了 LeetCode 有先测试功能,需要自己写测试用例。
编了几个之后突然想,为什么我不能用官方的测试用例呢?那样不是更方便。搜了一下发现是没有的,并且这个需求还是有人提过的

  1. https://leetcode.com/discuss/general-discussion/635684/option-to-view-all-the-testcases
  2. https://www.quora.com/How-do-I-get-all-the-test-cases-of-problems-posted-on-LeetCode/answer/Vipin-Sharma-83

那么我能不能用我之前那篇文章的方法拿到 test case 呢?

探索

继续探索

  • 那么我能不能写个脚本把这些测试都拿下来直接生成所有测试用例呢?看起来很简单,但其实栽了
  • 因为 LeetCode 的测试非常严谨,到后面的测试,比如字符串,它会用一个非常长的字符串,len(s) > 500000 print 根本是打不下的,LeetCode 也只会截取前面的,后面用 ... 代替
  • 如果整个测试太长,最后面的也会被截掉,用还剩多少个字符代替,如图
    image
  • 尝试用 zlib compress + base64 给字符串压缩,同样失败,有一点点效果
  • 继续尝试用 urllib.request.urlopen 能不能把 data.in 发出去?不行,这个 docker 内部网是不通的
  • 有其它方法么?有的,把长的字符串收集到 --> 分 n 次拿到 --> 最后保存。但是对普通刷题的朋友太麻烦了没有意义,感兴趣的同学可以自己尝试

意义呢

  1. 不想多次提交,我可以建一个小号,第一次去拿测试,然后复制粘贴到测试用例里,这样能保证大部分测试是可以的。
  2. 本地测试通过了再提交就 OK 了,也不用自己写符合 LeetCode 的测试了
  3. 今天我就用这个方式搞定了每日一题哈哈哈
    image
  4. 周赛貌似会很有用

启示呢

  • 做类似业务的朋友大多数也是 docker 起一个的方案,一定要小心,如果用户好奇会拿到你们许多信息的,连逆向都不用的。还有一定要小心 docker 逃逸的问题,LeetCode 能做到安全不代表所有公司能做到
  • 以后自己也要多写测试
  • 写代码,研究背后的原理,探索未知可比刷题有意思多了,我每次刷题最后都走偏。。。
  • LeetCode 不去公布所有测试也是有原因的,通过这次我明白了
  • 其实通过这个方式还能拿到一些 LeetCode setting 的限制,大家自己探索~
  • 其它语言其实同理,我跑通了 go 的,大家可以用自己习惯的编程语言测试