« Return to Thread: What is expected behavior on Assert.assertEquals on Number object?

Re: What is expected behavior on Assert.assertEquals on Number object?

by Nattapong Sirilappanich-2 :: Rate this Message:

Reply to Author | View in Thread






Hi,
I forgot to mention the version number of JUnit.

I'm using JUnit 4.3.1 which is part of Eclipse 3.3.2

Best regards,
Nattapong Sirilappanich
Engineer, National Language Development - GCoC & TSC Thailand
Software Group, IBM Thailand Co., Ltd.
National Phone: 02-273-4715, Fax: 02-619-2030
International Phone: +66 2 273 4715, Fax: +66 2 619 2030
e-mail: natta@...



                                                                           
             "J. B.                                                        
             Rainsberger"                                                  
             <jbrains762@gmail                                          To
             .com>                     junit@...              
             Sent by:                                                   cc
             junit@yahoogroups         Suwit                              
             .com                      Srivilairith/Thailand/IBM@IBMTH    
                                                                   Subject
                                       Re: [junit] What is expected        
             04/06/2008 21:34          behavior on Assert.assertEquals on  
                                       Number object?                      
                                                                           
             Please respond to                                            
             junit@yahoogroups                                            
                   .com                                                    
                                                                           
                                                                           




                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                                   
 On Jun 3, 2008, at 22:41 , Nattapong Sirilappanich wrote:                          
                                                                                   
 >                                                                                  
 >                                                                                  
 > Hi,                                                                              
 >                                                                                  
 > When i try to make an assertion on Number object, e.g. Double the                
 > result                                                                          
 > always assertion successful.                                                    
 > Even i try to compare by org.junit.Assert.assertEquals(123456789.345,            
 > 123456789.34), it still success. (I'm expecting failure)                        
 >                                                                                  
 Weird. assertEquals() appears only to compare the whole parts.                    
                                                                                   
 public class DoubleTest {                                                          
 @Test                                                                              
 public void unequalDoubleValueObjectsShouldBeUnequal() {                          
 Assert.assertFalse(new Double(3).equals(new Double(4)));                          
 Assert.assertFalse(new Double(3.1d).equals(new Double(3.2d)));                    
 Assert.assertFalse(new Double(123456789.345d).equals(new Double(                  
 123456789.34d)));                                                                  
 Assert.assertEquals(new Double(123456789.345d), new Double(                        
 123456789.34d));                                                                  
 Assert.assertEquals(new Double(3.1d), new Double(3.2d));                          
 Assert.assertEquals(new Double(3), new Double(4));                                
 }                                                                                  
 }                                                                                  
                                                                                   
 Only the last assertion fails.                                                    
 ----                                                                              
 J. B. (Joe) Rainsberger :: http://www.jbrains.ca                                   
 Your guide to software craftsmanship                                              
 JUnit Recipes: Practical Methods for Programmer Testing                            
 2005 Gordon Pask Award for contributions to Agile Software Practice                
                                                                                   
                                                                                   
                                                                                   
 

[Non-text portions of this message have been removed]

 « Return to Thread: What is expected behavior on Assert.assertEquals on Number object?

LightInTheBox - Buy quality products at wholesale price!