diff options
| author | mo k <mo@mokhan.ca> | 2012-04-16 16:40:35 -0600 |
|---|---|---|
| committer | mo k <mo@mokhan.ca> | 2012-04-16 16:40:35 -0600 |
| commit | 5b5905137b3d70d76eb134a0ed5febeebd8958b6 (patch) | |
| tree | e94dcee6d1b77037542a2a10543e0fd41de9cced | |
| parent | d04bc81d093a9ff5db247c154a649e91653964b8 (diff) | |
refactor tests to something that looks less of a spike.
| -rw-r--r-- | src/domain/Month.cs | 50 | ||||
| -rw-r--r-- | src/domain/Percent.cs | 55 | ||||
| -rw-r--r-- | src/domain/Well.cs | 98 | ||||
| -rwxr-xr-x | src/domain/domain.csproj | 2 | ||||
| -rw-r--r-- | src/test/WellSpecs.cs | 103 |
5 files changed, 178 insertions, 130 deletions
diff --git a/src/domain/Month.cs b/src/domain/Month.cs new file mode 100644 index 0000000..6ca47ab --- /dev/null +++ b/src/domain/Month.cs @@ -0,0 +1,50 @@ +namespace domain +{ + using System; + + public class Month + { + int year; + int month; + + public Month(int year, int month) + { + this.year = year; + this.month = month; + } + + public bool Equals(Month other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return other.year == year && other.month == month; + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != typeof (Month)) return false; + return Equals((Month) obj); + } + + public override int GetHashCode() + { + unchecked + { + return (year*397) ^ month; + } + } + + public Month Plus(int months) + { + var newMonth = new DateTime(year, month, 01).AddMonths(months); + return new Month(newMonth.Year, newMonth.Month); + } + + public override string ToString() + { + return string.Format("{0} {1}", year, month); + } + } +} diff --git a/src/domain/Percent.cs b/src/domain/Percent.cs new file mode 100644 index 0000000..b8fea7e --- /dev/null +++ b/src/domain/Percent.cs @@ -0,0 +1,55 @@ +namespace domain +{ + using System; + + public class Percent + { + public static Percent Zero = new Percent(0); + decimal percentage; + + public Percent(decimal percentage) + { + this.percentage = percentage; + } + + public bool Equals(Percent other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return other.percentage == percentage; + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != typeof (Percent)) return false; + return Equals((Percent) obj); + } + + public override int GetHashCode() + { + return percentage.GetHashCode(); + } + + public IQuantity Reduce(IQuantity original) + { + return new Quantity(PortionOf(original.Amount), original.Units); + } + + public Percent Plus(Percent other) + { + return new Percent(percentage + other.percentage); + } + + public decimal PortionOf(decimal amount) + { + return amount*percentage; + } + + public override string ToString() + { + return string.Format("{0} %", percentage); + } + } +} diff --git a/src/domain/Well.cs b/src/domain/Well.cs index 69b5cd5..209cb34 100644 --- a/src/domain/Well.cs +++ b/src/domain/Well.cs @@ -28,110 +28,12 @@ namespace domain } } - public class Month - { - readonly int year; - readonly int month; - - public Month(int year, int month) - { - this.year = year; - this.month = month; - } - - public bool Equals(Month other) - { - if (ReferenceEquals(null, other)) return false; - if (ReferenceEquals(this, other)) return true; - return other.year == year && other.month == month; - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != typeof (Month)) return false; - return Equals((Month) obj); - } - - public override int GetHashCode() - { - unchecked - { - return (year*397) ^ month; - } - } - - public Month Plus(int months) - { - var newMonth = new DateTime(year, month, 01).AddMonths(months); - return new Month(newMonth.Year, newMonth.Month); - } - - public override string ToString() - { - return string.Format("{0} {1}", year, month); - } - } - public interface IWell { IQuantity GrossProductionFor<T>(Month month) where T : ICommodity, new(); IQuantity NetProductionFor<T>(Month month) where T : ICommodity, new(); } - public class Percent - { - readonly decimal percentage; - public static Percent Zero = new Percent(0); - - public Percent(decimal percentage) - { - this.percentage = percentage; - } - - public bool Equals(Percent other) - { - if (ReferenceEquals(null, other)) return false; - if (ReferenceEquals(this, other)) return true; - return other.percentage == percentage; - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != typeof (Percent)) return false; - return Equals((Percent) obj); - } - - public override int GetHashCode() - { - return percentage.GetHashCode(); - } - - public IQuantity Reduce(IQuantity original) - { - //return new ProratedQuantity(original, this); - return new Quantity(PortionOf(original.Amount), original.Units); - } - - public Percent Plus(Percent other) - { - return new Percent(percentage + other.percentage); - } - - public decimal PortionOf(decimal amount) - { - return amount*percentage; - } - - public override string ToString() - { - return string.Format("{0} %", percentage); - } - } - public static class Units { public static Percent Percent(this decimal percentage) diff --git a/src/domain/domain.csproj b/src/domain/domain.csproj index 857af06..f6041ae 100755 --- a/src/domain/domain.csproj +++ b/src/domain/domain.csproj @@ -45,7 +45,9 @@ <Compile Include="CommoditySplits.cs" />
<Compile Include="DeclineCurve.cs" />
<Compile Include="DrillSchedule.cs" />
+ <Compile Include="Month.cs" />
<Compile Include="Oppurtunity.cs" />
+ <Compile Include="Percent.cs" />
<Compile Include="Production.cs" />
<Compile Include="Quantity.cs" />
<Compile Include="TypeCurve.cs" />
diff --git a/src/test/WellSpecs.cs b/src/test/WellSpecs.cs index c6a8a7b..1d84399 100644 --- a/src/test/WellSpecs.cs +++ b/src/test/WellSpecs.cs @@ -10,42 +10,81 @@ {
public class when_estimating_production
{
- It should_be_able_to_tell_the_estimated_total_production_for_any_month= () =>
+ Establish context = () =>
{
- var parkland100Percent = new Oppurtunity();
- parkland100Percent.WorkingInterest(100m.Percent());
- var declineCurve = new DeclineCurve();
- declineCurve.Composition<Gas>(100m.Percent());
- declineCurve.Add(0, 100.BOED());
- parkland100Percent.DeclinesUsing(declineCurve);
-
- var schedule = new DrillSchedule();
- var jan2013 = new Month(2013, 01);
- schedule.Include(parkland100Percent.BringOnlineOn(jan2013));
- schedule.EstimatedGrossProductionFor<All>(jan2013).ShouldEqual(100.BOED());
- schedule.EstimatedGrossProductionFor<Gas>(jan2013).ShouldEqual(100.BOED());
- schedule.EstimatedGrossProductionFor<Oil>(jan2013).ShouldEqual(0.BOED());
- schedule.EstimatedGrossProductionFor<NGL>(jan2013).ShouldEqual(0.BOED());
- schedule.EstimatedGrossProductionFor<Condensate>(jan2013).ShouldEqual(0.BOED());
+ sut = new DrillSchedule();
};
- It should_be_able_to_tell_the_estimated_net_total_production_for_any_month = () =>
+ static DrillSchedule sut;
+
+ public class when_100_percent_working_interest
{
- var parkland75Percent = new Oppurtunity();
- parkland75Percent.WorkingInterest(75m.Percent());
- var declineCurve = new DeclineCurve();
- declineCurve.Composition<Gas>(50m.Percent());
- declineCurve.Composition<Oil>(50m.Percent());
- declineCurve.Add(0, 100.BOED());
- parkland75Percent.DeclinesUsing(declineCurve);
-
- var schedule = new DrillSchedule();
- var jan2013 = new Month(2013, 01);
- schedule.Include(parkland75Percent.BringOnlineOn(jan2013));
- schedule.EstimatedNetProductionFor<All>(jan2013).ShouldEqual(75.BOED());
- schedule.EstimatedNetProductionFor<Gas>(jan2013).ShouldEqual(37.5m.BOED());
- schedule.EstimatedNetProductionFor<Oil>(jan2013).ShouldEqual(37.5m.BOED());
- };
+ Establish context = ()=>
+ {
+ parkland100Percent = new Oppurtunity();
+ parkland100Percent.WorkingInterest(100m.Percent());
+ var declineCurve = new DeclineCurve();
+ declineCurve.Composition<Gas>(100m.Percent());
+ declineCurve.Add(0, 100.BOED());
+ parkland100Percent.DeclinesUsing(declineCurve);
+
+ jan2013 = new Month(2013, 01);
+ };
+
+ Because of = ()=>
+ {
+ sut.Include(parkland100Percent.BringOnlineOn(jan2013));
+ };
+
+ It should_be_able_to_tell_the_estimated_total_production_for_any_month= () =>
+ {
+ sut.EstimatedGrossProductionFor<All>(jan2013).ShouldEqual(100.BOED());
+ };
+
+ It should_be_able_to_tell_the_estimated_production_for_gas=()=>
+ {
+ sut.EstimatedGrossProductionFor<Gas>(jan2013).ShouldEqual(100.BOED());
+ };
+
+ It should_be_able_to_tell_the_estimated_production_for_oil=()=>
+ {
+ sut.EstimatedGrossProductionFor<Oil>(jan2013).ShouldEqual(0.BOED());
+ };
+
+ It should_be_able_to_tell_the_estimated_production_for_ngl=()=>
+ {
+ sut.EstimatedGrossProductionFor<NGL>(jan2013).ShouldEqual(0.BOED());
+ };
+
+ It should_be_able_to_tell_the_estimated_production_for_condensate=()=>
+ {
+ sut.EstimatedGrossProductionFor<Condensate>(jan2013).ShouldEqual(0.BOED());
+ };
+
+ static Oppurtunity parkland100Percent;
+ static Month jan2013;
+ }
+
+ public class when_reduced_working_interest
+ {
+ It should_be_able_to_tell_the_estimated_net_total_production_for_any_month = () =>
+ {
+ var parkland75Percent = new Oppurtunity();
+ parkland75Percent.WorkingInterest(75m.Percent());
+ var declineCurve = new DeclineCurve();
+ declineCurve.Composition<Gas>(50m.Percent());
+ declineCurve.Composition<Oil>(50m.Percent());
+ declineCurve.Add(0, 100.BOED());
+ parkland75Percent.DeclinesUsing(declineCurve);
+
+ var schedule = new DrillSchedule();
+ var jan2013 = new Month(2013, 01);
+ schedule.Include(parkland75Percent.BringOnlineOn(jan2013));
+ schedule.EstimatedNetProductionFor<All>(jan2013).ShouldEqual(75.BOED());
+ schedule.EstimatedNetProductionFor<Gas>(jan2013).ShouldEqual(37.5m.BOED());
+ schedule.EstimatedNetProductionFor<Oil>(jan2013).ShouldEqual(37.5m.BOED());
+ };
+ }
}
}
}
|
