TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Structural Equality for Better Tests

22 点作者 algui91大约 4 年前

3 条评论

chriswarbo大约 4 年前
Probably worth mentioning that we sometimes need a normalisation step. The most common example is comparing two lists for equality, when their order doesn&#x27;t actually matter; this can produce false-positives if some later refactor changes the order of the elements. In this case we can normalise the values by sorting them before comparing.<p>One example I keep hitting is a widely used JSON library for Haskell, whose test suite checks a pair of values for equality, when they just-so-happen to be in the opposite order on 32bit x86. Since I do lots of dependency pinning, this same bug keeps cropping up in different contexts :(
评论 #27059851 未加载
评论 #27051868 未加载
评论 #27052096 未加载
slver大约 4 年前
I write all my tests by first extracting aspects of the compared items to values that are then compared structurally. Nothing else makes sense.
cigaser大约 4 年前
very easy is to serialize both objects and compare binary data.
评论 #27051467 未加载