C#中:你将如何单元测试的GetHashCode? [英] C#: How would you unit test GetHashCode?

查看:107
本文介绍了C#中:你将如何单元测试的GetHashCode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

测试等于方法是非常简单的(据我所知)。但是,如何在地球上测试该的GetHashCode 方法?

Testing the Equals method is pretty much straight forward (as far as I know). But how on earth do you test the GetHashCode method?

推荐答案

测试这两个不同的对象哪些相等具有相同的散列码(为各种值)。检查不相等的对象给予不同的散列码,变化的一个方面/属性在同一时间。而散列码没有的有无的有所不同,你会真的倒霉到挑选不同的值,它的发生的给予相同的散列码除非您已性质得到了一个错误。

Test that two distinct objects which are equal have the same hash code (for various values). Check that non-equal objects give different hash codes, varying one aspect/property at a time. While the hash codes don't have to be different, you'd be really unlucky to pick different values for properties which happen to give the same hash code unless you've got a bug.

这篇关于C#中:你将如何单元测试的GetHashCode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆