equality

C++ enforce conditions on inherited classes

I would like to define an abstract base class X and enforce the following: a) every concrete class Y that inherits from X define a constructor Y(int x) b) it should be possible to test whether two Y objects are equal. For a, one not very good solution is to put a pure virtual fromInt method in X which concrete class will have to defi...

short-cutting equality checking in F#?

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 ...

Object equality in context of hibernate / webapp

How do you handle object equality for java objects managed by hibernate? In the 'hibernate in action' book they say that one should favor business keys over surrogate keys. Most of the time, i do not have a business key. Think of addresses mapped to a person. The addresses are keeped in a Set and displayed in a Wicket RefreshingView (wit...

Does -eq keyword in power shell test reference equality or use Object.Equals()

Does "-eq" in Powershell test reference equality (like "==" in c#) or does it do the equivalent of calling Object.Equals() ...

Simple Question:Output of below Java program

public class abc1 { private String s; public abc1(String s){this.s=s;} public static void main(String args[]) { HashSet<Object> hs=new HashSet<Object>(); abc1 a1= new abc1("abc"); abc1 a2= new abc1("abc"); String s1= new String("abc"); String s2= new String("abc"); hs.add(a1); hs.add(a2); hs.add(s1); hs.add(s2); ...

What's the difference between IEquatable and just overriding Object.Equals() ?

I want my Food class to be able to test whenever it is equal to another class. I will later use it against a List, and I want to use its List.Contains() method. Should I implement IEquatable or just override Object.Equals()? From MSDN: This method determines equality by using the default equality comparer, as defined by the objec...

In C#, how do I check if a type is a subtype OR the type of an object?

To check if a type is a subclass of another type in C#, it's easy: typeof (SubClass).IsSubclassOf(typeof (BaseClass)); // returns true However, this will fail: typeof (BaseClass).IsSubclassOf(typeof (BaseClass)); // returns false Is there any way to check whether a type is either a subclass OR of the base class itself, without usin...

Is this possible somehow in C# : if (a==b==c==d) {...}

Hi, Is there a quick way to compare equality of more than one values in C#? something like: if (5==6==2==2){ //do something } Thanks ...

Comparing two objects that are the same in MbUnit

From MBUnit I am trying to check if the values of two objects are the same using Assert.AreSame(RawDataRow, result); However I am getting the following fail: Expected Value & Actual Value : {RawDataRow: CentreID = "CentreID1", CentreLearnerRef = "CentreLearnerRef1", ContactID = 1, DOB = 2010-05-05T00:00:00.0000000, Email = "Email1",...

Python: Why "is" keyword has different behavior when there is dot in the string?

>>> x = "google" >>> x is "google" True >>> x = "google.com" >>> x is "google.com" False >>> Can someone give me some hints why its like that? Edit: to make sure above, I have just tested on python 2.5.4, 2.6.5, 2.7b2, python 3.1 on windows and python 2.7b1 on linux Looks its consistence across all, so its by design and Am I missing ...

C# == operator in Immediate window behaves differently than at run-time

Try the following in the Immediate window: object a1 = "a"; object a2 = "a"; a1==a2 // outputs false and you'll see that a1 == a2 outputs false. However, at runtime in either a window app or console, you'll get true: object t1 = "a"; object t2 = "a"; MessageBox.Show((t1 == t2).ToString()); // outputs true The runtime behavior is c...

Interesting AS3 hash situation. Is it really using strict equality as the documentation says?

AS3 Code: import flash.utils.Dictionary; var num1:Number = Number.NaN; var num2:Number = Math.sqrt(-1); var dic:Dictionary = new Dictionary( true ); trace(num1); //NaN trace(num2); //NaN dic[num1] = "A"; trace( num1 == num2 ); //false trace( num1 === num2 ); //false trace( dic[num1] ); //A trace( dic[num2] ); //A Concerning the key co...

How do I ignore the UTF-8 Byte Order Marker in String comparisons?

I'm having a problem comparing strings in a Unit Test in C# 4.0 using Visual Studio 2010. This same test case works properly in Visual Studio 2008 (with C# 3.5). Here's the relevant code snippet: byte[] rawData = GetData(); string data = Encoding.UTF8.GetString(rawData); Assert.AreEqual("Constant", data, false, CultureInfo.InvariantCu...

Comparing XmlDocument for equality (content wise)

If I want to compare the contents of a XMlDocument, is it just like this? XmlDocument doc1 = GetDoc1(); XmlDocument doc2 = GetDoc2(); if(doc1 == doc2) { } I am not checking if they are both the same object reference, but if the CONTENTS of the xml are the same. ...

Comparing strings that contain formatting in C#

I'm working on a function that given some settings - such as line spacing, the output (in string form) is modified. In order to test such scenarios, I'm using string literals, as shown below for the expected result. The method, using a string builder, (AppendLine) generates the said output. One issue I have run into is that of comparing...

PHP compare doubt

if(0 == ('Pictures')) { echo 'true'; } why it's giving me 'true' ? ...

Using scanf in a while loop

Probably an extremely simple answer to this extremely simple question: I'm reading "C Primer Plus" by Pratta and he keeps using the example while (scanf("%d", &num) == 1)... Is the == 1 really necessary? It seems like one could just write: while (scanf("%d", &num)) It seems like the equality test is unnecessary since scanf returns...

How to Determine Equality of Two Very Large Tables

Hey guys, I'm using DB2 and I have two tables that have a million+ rows in them. Is there a query I can create that will check the two tables to see if all the values in the two are the same? Or, what is the best way to do this? Thanks, Tyler ...

Why hashCode() returns the same value for a object in all consecutive executions?

Hi, I am trying some code around object equality in java. As I have read somewhere hashCode() is a number which is generated by applying the hash function. Hash Function can be different for each object but can also be same. At the object level, it returns the memory address of the object. Now, I have sample program, which I run ...

Does MS Test provide a default value equals comparison?

I want to test for example int orderId = myRepository.SubmitOrder(orderA); orderB = myRepository.GetOrder(orderId); Assert.AreEqual(orderA, orderB); // fail Obviously I need a value comparison here, but I don't want to have to provide an overridden Equals implementation for all of my classes purely for the sake of testing (it wouldn...