equality

How does an equal to expression work in a printf placeholder? [duplicate]

不想你离开。 提交于 2019-12-08 03:35:05
问题 This question already has answers here : Why are these constructs using pre and post-increment undefined behavior? (14 answers) Closed last year . I have the following code snippet: main( ) { int k = 35 ; printf ( "\n%d %d %d", k == 35, k = 50, k > 40 ) ; } which produces the following output 0 50 0 I'm not sure I understand how the first value of the printf comes to 0 . When the value of k is compared with 35 , it should ideally return (and thus print) 1, but how is it printing zero? The

How to compare two objects for equality in Scala?

▼魔方 西西 提交于 2019-12-07 21:03:17
问题 I have a very basic equality check between two objects but it fails. package foo import org.junit.Assert._ object Sandbox extends App{ class A val a = new A val b = new A assertEquals(a, b) } My use-case is more complex but I wanted to get my basics right. I get an assertion error when I run the code: Caused by: java.lang.AssertionError: expected:<foo.Sandbox$A@3f86d38b> but was:<foo.Sandbox$A@206d63fd> at org.junit.Assert.fail(Assert.java:88) at org.junit.Assert.failNotEquals(Assert.java:743

How to generate a unique hash for a collection of objects independent of their order [duplicate]

女生的网名这么多〃 提交于 2019-12-07 17:03:46
问题 This question already has answers here : Getting hash of a list of strings regardless of order (5 answers) Closed 5 years ago . Let's say I have a class public class MyClass { public string Type { get; set; } public int Id { get; set; } } and I have a collection class that is simply a strongly typed List public class MyClassList : List<MyClass> { public MyClassList(IEnumerable<MyClass> enumerable) : base (enumerable) {} } I want MyClassList to be able to generate a unique hash-code for

Is there a nice simple way to check if a variable in Javascript has a value?

你离开我真会死。 提交于 2019-12-07 14:45:43
问题 I want to check this: if ( typeof myVar != "undefined" && myVar != null ) ... In other words, I want to check if a variable has a defined value (including 0 or an empty string), but not undefined or null, which I interpret as valueless. Do I have to do the two-part check each time or is there a handy shortcut? 回答1: If you know the context of myVar , you should be able to do this: if (this.myVar != null) { ... } 回答2: If you want to allow 0 and "" as valid values and you want to cover the case

short-cutting equality checking in F#?

匆匆过客 提交于 2019-12-07 06:22:46
问题 In F#, the equality operator (=) is generally extensional, rather than intensional. That's great! Unfortunately, it appears to me that F# does not use pointer equality to short-cut these extensional comparisons. For instance, this code: type Z = MT | NMT of Z ref // create a Z: let a = ref MT // make it point to itself: a := NMT a // check to see whether it's equal to itself: printf "a = a: %A\n" (a = a) ... gives me a big fat segmentation fault[*], despite the fact that 'a' and 'a' both

Clojure equality of collections with sequences

泪湿孤枕 提交于 2019-12-07 05:19:19
问题 I noticed that Clojure (1.4) seems to be happy to consider vectors equal to the seq of the same vector, but that the same does not apply for maps: (= [1 2] (seq [1 2])) => true (= {1 2} (seq {1 2})) => false Why should the behaviour of = be different in this way? 回答1: Clojure's = can be thought of as performing its comparisons in two steps: Check if the types of the things being compared belong to the same "equality partition", that is a class of types whose members might potentially be equal

C# string equality operator returns false, but I'm pretty sure it should be true… What?

不想你离开。 提交于 2019-12-07 05:02:39
问题 I'm trying to write a unit test for a piece of code that generates a large amount of text. I've run into an issue where the "expected" and "actual" strings appear to be equal, but Assert.AreEqual throws, and both the equality operator and Equals() return false. The result of GetHashCode() is different for both values as well. However, putting both strings into text files and comparing with DiffMerge tells me they're the same. Additionally, using Encoding.ASCII.GetBytes() on both values and

Using CLOS class instances as hash-table keys?

孤人 提交于 2019-12-07 03:38:57
问题 I have the following class: (defclass category () ((cat-channel-name :accessor cat-channel-name :initarg :cat-channel-name :initform "" :type string :documentation "Name of the channel of this category") (cat-min :accessor cat-min :initarg :min :initform 0 :type number :documentation "Mininum value of category") (cat-max :accessor cat-max :initarg :max :initform 1 :type number :documentation "Maximum value of category")) (:documentation "A category")) Now, I would like to use this class as a

.NET delegate equality?

不羁的心 提交于 2019-12-07 01:34:26
I think this is the question, anyway. I am using a RelayCommand, which decorates an ICommand with two delegates. One is Predicate for the _canExecute and the other is Action for the _execute method. ---Background motivation -- The motivation has to do with unit testing ViewModels for a WPF presentation. A frequent pattern is that I have one ViewModel that has an ObservableCollection, and I want a unit test to prove the data in that collection is what I expect given some source data (which also needs to be converted into a collection of ViewModels). Even though the data in both collections

Value-equals and circular references: how to resolve infinite recursion?

Deadly 提交于 2019-12-07 01:12:03
问题 I have some classes that contain several fields. I need to compare them by value, i.e. two instances of a class are equal if their fields contain the same data. I have overridden the GetHashCode and Equals methods for that. It can happen that these classes contain circular references. Example: We want to model institutions (like government, sports clubs, whatever). An institution has a name. A Club is an institution that has a name and a list of members. Each member is a Person that has a