10 x 5 != 50...

Part 1

Had a strange unit test a couple of weeks ago. It involved the following code snippet (simplified for the purposes of this blogpost):

 
   1:  public class Order
   2:  {
   3:      public decimal Cost;
   4:      public decimal Quantity;
   5:      public decimal GetTotal()
   6:      {
   7:          return Cost * Quantity;
   8:      }
   9:  }
  10:   
  11:  [TestMethod]
  12:  public void TestTotalPrice()
  13:  {
  14:      Order o = new Order();
  15:      o.Cost = 10;
  16:      o.Quantity = 5;
  17:      Assert.AreEqual(o.GetTotal(), 50);    
  18:  }

The test fails under Visual Studio 2005's unit test system, saying that the values do not match. However, the value passes under Visual Studio 2008's unit test system...

Any Ideas?

Published 04 February 2008 12:13 by Mat Steeples

Comments

# re: 10 x 5 != 50...@ 04 February 2008 22:02

Decimal compared to int? Does 50m work?

Jon Fowler

Leave a Comment

(required) 
(required) 
(optional)
(required)