Commit 43cffb1

mo k <mo@mokhan.ca>
2012-04-24 03:01:48
fix the unit of measure conversions and add specs for when checking if a quantity is greater than another.
1 parent 497942c
src/domain/BOED.cs
@@ -4,7 +4,7 @@ namespace domain
   {
     public decimal Convert(decimal amount, IUnitOfMeasure units)
     {
-      return ( units is MCF ) ? amount * 6: amount;
+      return ( units is MCF ) ? amount / 6: amount;
     }
 
     public bool Equals(BOED other)
@@ -34,13 +34,4 @@ namespace domain
 
     readonly string name = "BOED";
   }
-
-  public class MCF : IUnitOfMeasure
-  {
-    public decimal Convert(decimal amount, IUnitOfMeasure units)
-    {
-      if(units is BOED) return amount/6;
-      return amount;
-    }
-  }
 }
src/domain/domain.csproj
@@ -50,6 +50,7 @@
     <Compile Include="DrillSchedule.cs" />
     <Compile Include="EstimatedNetProductionFor.cs" />
     <Compile Include="GasPlant.cs" />
+    <Compile Include="MCF.cs" />
     <Compile Include="Month.cs" />
     <Compile Include="Months.cs" />
     <Compile Include="Oppurtunity.cs" />
src/domain/MCF.cs
@@ -0,0 +1,16 @@
+namespace domain
+{
+  public class MCF : IUnitOfMeasure
+  {
+    public decimal Convert(decimal amount, IUnitOfMeasure units)
+    {
+      if(units is BOED) return amount*6;
+      return amount;
+    }
+
+    public override string ToString()
+    {
+      return "MCF";
+    }
+  }
+}
src/domain/Quantity.cs
@@ -34,7 +34,7 @@ namespace domain
 
     public bool IsGreaterThan(IQuantity other)
     {
-      return true;
+      return this.Amount > other.ConvertTo(this.Units).Amount;
     }
 
     public override string ToString()
src/domain/Well.cs
@@ -31,7 +31,7 @@ namespace domain
 
   public interface IWell
   {
-    IQuantity GrossProductionFor<T>(Month month) where T : ICommodity, new();
-    IQuantity NetProductionFor<T>(Month month) where T : ICommodity, new();
+    IQuantity GrossProductionFor<Commodity>(Month month) where Commodity : ICommodity, new();
+    IQuantity NetProductionFor<Commodity>(Month month) where Commodity : ICommodity, new();
   }
 }
src/test/BOEDSpecs.cs
@@ -12,16 +12,16 @@ namespace test
 
     static IUnitOfMeasure sut;
 
-    public class when_converting_one_BOE_to_MCF
+    public class when_converting_6_MCF_to_BOE
     {
-      It should_return_6_MCF=()=>
+      It should_return_1_BOE=()=>
       {
-        result.ShouldEqual(6m);
+        result.ShouldEqual(1m);
       };
 
       Because of = ()=>
       {
-        result = sut.Convert(1, new MCF());
+        result = sut.Convert(6, new MCF());
       };
 
       static decimal result;
src/test/MCFSpecs.cs
@@ -2,7 +2,9 @@ namespace test
 {
   using Machine.Specifications;
   using domain;
-  public class MCFSpecs{
+
+  public class MCFSpecs
+  {
     Establish context = ()=>
     {
       sut = new MCF();
@@ -10,16 +12,16 @@ namespace test
 
     static MCF sut;
 
-    public class when_converting_6_mcf_to_boed
+    public class when_converting_1_BOED_to_MCF
     {
-      It should_return_one_boed=()=>
+      It should_return_6_BOED=()=>
       {
-        result.ShouldEqual(1m);
+        result.ShouldEqual(6m);
       };
 
       Because of = ()=>
       {
-        result = sut.Convert(6m, new BOED());
+        result = sut.Convert(1m, new BOED());
       };
 
       static decimal result;
src/test/QuantitySpecs.cs
@@ -0,0 +1,48 @@
+namespace test
+{
+  using Machine.Specifications;
+  using domain;
+
+  public class QuantitySpecs
+  {
+    public class when_using_the_same_unit_of_measure
+    {
+      public class when_one_quantity_is_greater_than_another
+      {
+        It should_return_true=()=>
+        {
+          var result = new Quantity(2, new BOED()).IsGreaterThan(new Quantity(1, new BOED()));
+          result.ShouldBeTrue();
+        };
+      }
+      public class when_one_quantity_is_less_than_another
+      {
+        It should_return_false=()=>
+        {
+          var result = new Quantity(1, new BOED()).IsGreaterThan(new Quantity(2, new BOED()));
+          result.ShouldBeFalse();
+        };
+      }
+    }
+
+    public class when_using_different_unit_of_measures
+    {
+      public class when_one_quantity_is_greater_than_another
+      {
+        It should_return_true=()=>
+        {
+          var result = new Quantity(2, new BOED()).IsGreaterThan(new Quantity(6, new MCF()));
+          result.ShouldBeTrue();
+        };
+      }
+      public class when_one_quantity_is_less_than_another
+      {
+        It should_return_false=()=>
+        {
+          var result = new Quantity(1, new BOED()).IsGreaterThan(new Quantity(7, new MCF()));
+          result.ShouldBeFalse();
+        };
+      }
+    }
+  }
+}
src/test/test.csproj
@@ -54,8 +54,9 @@
     <Compile Include="Mock.cs" />
     <Compile Include="MonthSpecs.cs" />
     <Compile Include="ProductionScheduleSpecs.cs" />
+    <Compile Include="QuantitySpecs.cs" />
     <Compile Include="RangeSpecs.cs" />
-    <Compile Include="GasPlantSpecs.cs" />
+    <!--<Compile Include="GasPlantSpecs.cs" />-->
   </ItemGroup>
   <ItemGroup>
     <None Include="packages.config" />