Unanswered How does object.Equals work?

  • Thursday, July 05, 2012 6:48 PM
     
     

    I'm doing unit testing, and the following assert keeps failing:

    Assert.IsTrue(inflater.Equals(new InflaterInputStream(data)));

    inflater contains the object grabbed from new InflaterInputStream(_data) in the code I'm testing and data contains the stream I grabbed from _data.

    Is this failing because the two objects have different references?

    Thanks for all replies.

All Replies

  • Thursday, July 05, 2012 7:46 PM
     
     
    You might want to ask this question in the appropriate MSDN forum.  This forum is for questions on Microsoft certification and related training.
  • Thursday, July 05, 2012 11:05 PM
    Moderator
     
     
    This is a training and certification forum.  As your question relates to neither of these, it will be moved to a more appropriate forum.

    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer

    Jeff Wharton
    MSysDev (C.Sturt), MDbDsgnMgt (C.Sturt), MCT, MCPD, MCSD, MCITP, MCDBA
    Blog: Mr. Wharty's Ramblings
    Twitter: @Mr_Wharty
    MC ID: Microsoft Transcript

  • Monday, July 09, 2012 6:19 AM
     
     

    Hi m4ss,

    Thank you for posting in the MSDN forum.

    Would you mind sharing us more information about this issue? Did you get any error message when you run your unit test?

    About how to use the Assert.IsTrue() method in unit tests, you could see “Assert::IsTrue Method”.

    In addition, which kind of app are you testing? Do you mean that you are using the “Class Inflater”?  

    Since this forum is to discuss the unit test, if still no help, I suggest you share us a simple sample, we will try to check it in our machine.

    Please attach your Visual Studio project, you can upload it to the sky driver, and then share the download link in your post. If you got error messages, please also show the whole error messages in your post.

    If there's any concern, please feel free to let me know.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

  • Tuesday, July 10, 2012 3:56 PM
     
      Has Code

    You don't really need my exact code; it's more of a conceptual question.

    For example,

                Deflater deflater = new Deflater(2);
                Deflater def = new Deflater(2);
                bool @bool = def.Equals(deflater);   // returns false

    but the examples on msdn : http://msdn.microsoft.com/en-us/library/bsc2ak47.aspx

    Point3D point3Da = new Point3D(5, 5, 2); Point3D point3Db = new Point3D(5, 5, 2); // point3Da and point3Db are equal

    Why do they work the way they do? What's the difference between them?

  • Wednesday, July 11, 2012 6:08 AM
     
     

    Hi m4ss,

    Glad to receive your reply.

    It seems that it is the C# issue, I did some research about it, and I found that you have posted this issue in the correct C# forum. It has been resolved here, am I right? If so, I will move this thread to Off-topic forum. Thanks for your understanding.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us