天道酬勤,学无止境

equivalence

如何在 Golang 中测试地图的等价性?(How to test the equivalence of maps in Golang?)

问题 我有一个像这样的表驱动测试用例: func CountWords(s string) map[string]int func TestCountWords(t *testing.T) { var tests = []struct { input string want map[string]int }{ {"foo", map[string]int{"foo":1}}, {"foo bar foo", map[string]int{"foo":2,"bar":1}}, } for i, c := range tests { got := CountWords(c.input) // TODO test whether c.want == got } } 我可以检查长度是否相同并编写一个循环来检查每个键值对是否相同。 但是当我想将它用于另一种类型的地图(比如map[string]string )时,我必须再次编写此检查。 我最终做的是,我将地图转换为字符串并比较字符串: func checkAsStrings(a,b interface{}) bool { return fmt.Sprintf("%v", a) != fmt.Sprintf("%v", b) } //... if checkAsStrings(got, c.want) { t.Errorf("Case #%v

2021-06-10 15:25:18    分类:技术分享    testing   maps   go   equivalence   table-driven

“冲突可序列化”和“冲突等效”有什么区别?(What is the difference between “conflict serializable” and “conflict equivalent”?)

问题 在数据库理论中,“冲突可序列化”和“冲突等效”有什么区别? 我的教科书中有一节是关于可序列化冲突的,但忽略了冲突等价性。 大概这两个概念我都很熟悉,但是我对术语不熟悉,所以我正在寻找解释。 回答1 仅用两个术语以不同的方式描述一件事。 冲突等价:您需要说附表 A 与附表 B 的冲突等价。它必须涉及两个时间表 Conflict serializable : 仍然使用 Schedule A 和 B。我们可以说 Schedule A 是冲突可序列化的。 附表 B 是冲突可序列化的。 我们没有说 Schedule A/B 是冲突等价的 我们没有说 Schedule A 与 Schedule B 发生冲突 回答2 DBMS 中的冲突可以定义为两个或多个不同的事务访问同一变量,并且其中至少一个是写操作。 例如: T1: Read(X) T2: Read (X) 在这种情况下没有冲突,因为两个事务都只执行读取操作。 但在以下情况下: T1: Read(X) T2: Write(X) 有冲突。 假设我们有一个时间表S ,我们可以重新排列其中的指令。 并创建另外 2 个计划S1和S2 。 冲突等效:指的是调度S1和S2 ,它们在两个调度中维护冲突指令的顺序。 例如,如果T1在T2将X写入S1之前必须读取X ,那么它在S2也应该相同。 (应该只为冲突的操作维护排序)。 冲突可串行化

2021-06-09 09:47:35    分类:技术分享    database   conflict   serializable   equivalence

What is the difference between equivalence and equality?

What is the difference between equivalence and equality in C++? There is a very similar question here. However, this question is tagged with math, while I am interested in the meaning in C++ context. To see the terms in context: Scott Meyers uses them in an example in this video.

2021-05-24 12:27:06    分类:问答    c++   equality   equivalence

How should one proceed to prove (or find) if two regular expressions are same or equivalent?

For example, in an assignment given to me, we were asked to find out if two regular expressions are equal or not. (a+b+c)* and ((ab)**c*)* My question is how is one supposed to do that? If I draw the transition graphs for both and then run a few strings through it and show that both of the TGs are able to accept it, is that a sufficient proof ? If not, how do I do it? Is there a mathematical/axiomatic approach towards this? Thanks in advance. EDIT: There is another thing that I'd like to clear which is kind of related to this question. Are the two FAs depicted in the photo below the same? i.e

2021-05-18 01:04:27    分类:问答    regex   finite-automata   regular-language   equivalence

What is the difference between “conflict serializable” and “conflict equivalent”?

In database theory, what is the difference between "conflict serializable" and "conflict equivalent"? My textbook has a section on conflict serializable but glosses over conflict equivalence. These are probably both concepts I am familiar with, but I am not familiar with the terminology, so I am looking for an explanation.

2021-05-17 04:22:04    分类:问答    database   conflict   serializable   equivalence

How to test the equivalence of maps in Golang?

I have a table-driven test case like this one: func CountWords(s string) map[string]int func TestCountWords(t *testing.T) { var tests = []struct { input string want map[string]int }{ {"foo", map[string]int{"foo":1}}, {"foo bar foo", map[string]int{"foo":2,"bar":1}}, } for i, c := range tests { got := CountWords(c.input) // TODO test whether c.want == got } } I could check whether the lengths are the same and write a loop that checks if every key-value pair is the same. But then I have to write this check again when I want to use it for another type of map (say map[string]string). What I ended

2021-05-15 07:55:56    分类:问答    testing   maps   go   equivalence   table-driven

Overloading equivalence (==) operator for custom class in Swift

Is it possible to overload equivalence (==) operator for a custom class inside that custom class. However I know that it is possible to have this operator overloaded outside class scope. Appreciate any sample code. Thanks in advance.

2021-05-01 03:57:38    分类:问答    ios   swift   operator-overloading   equivalence

盒装原语和对等(Boxed Primitives and Equivalence)

问题 所以今天有人问我这个问题。 Integer a = 3; Integer b = 2; Integer c = 5; Integer d = a + b; System.out.println(c == d); 该程序将输出什么? 它返回true。 我回答说,由于我对自动装箱(和自动装箱)的了解,它总是会打印出false。 我的印象是,为Integer分配a = 3将创建一个新的Integer(3),以便an ==将对引用而不是原始值进行评估。 谁能解释一下? 回答1 缓存在-128到127之间的框值。 装箱使用Integer.valueOf方法,该方法使用缓存。 超出范围的值不会被缓存,并且始终创建为新实例。 由于您的值属于缓存范围,因此使用==运算符可以使值相等。 引用Java语言规范: 如果要装箱的值p为true,false,一个字节,\ u0000到\ u007f范围内的char或-128和127之间的整数或短数,则令r1和r2为任何两次装箱转换的结果的p。 r1 == r2总是这样。 http://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.7 回答2 这是真正发生的事情: Integer c = Integer.valueOf(5); Integer d = Integer

2021-04-29 09:07:00    分类:技术分享    java   autoboxing   equivalence

等效类测试与边界值测试(Equivalence Class Testing vs. Boundary Value Testing)

问题 我了解等效测试的工作原理。 它与边界值测试有何相同或不同? 回答1 等效类测试 EC测试是指您有多个要测试的测试项目(例如值),但是由于成本(时间/金钱)而您没有时间测试所有项目。 因此,您将测试项目分组到类中,其中每个类中的所有项目都假定行为完全相同。 从理论上讲,您只需测试每个项目之一即可确保系统正常运行。 例子1 2岁以下的儿童免费乘坐巴士。 年轻人支付10美元,成人支付15美元,老年人支付5美元。 班级: 价格:0->年龄:0-1 价格:10->年龄:2-14 价格:15->年龄:15-64 价格:5->年龄:65-无穷大 示例2(多个参数) 手机K80,J64和J54运行Java5。K90和J99运行Java6。但是有两种可能的浏览器是FireFox和Opera,J模型运行FF,K模型运行O。 班级: 浏览器:FF,Java:5->手机:J64,J54 浏览器:FF,Java:6->手机:J99 浏览器:O,Java:5->电话:K80 浏览器:O,Java:6->手机:K90 等值类考试的危险使用EC测试存在一种危险,在测试手册中很少提到,但要记住这一点非常重要。 仅仅因为两个项目/值被假定在同一类中并且具有相同的行为,并不意味着它们确实具有相同的行为。 这意味着仅仅因为您在类中测试一个值,该类中的所有值都表现相同。 我的现实世界的例子是拥有特定Java平台的手机

2021-04-28 16:31:05    分类:技术分享    testing   equivalence   black-box

Is JavaScript's double equals (==) always symmetric?

There are many cases in which JavaScript's type-coercing equality operator is not transitive. For example, see "JavaScript equality transitivity is weird." However, are there any cases in which == isn't symmetric? That is, where a == b is true and b == a is false?

2021-04-24 12:58:19    分类:问答    javascript   ecma262   comparison-operators   equivalence   symmetric