From 5b5905137b3d70d76eb134a0ed5febeebd8958b6 Mon Sep 17 00:00:00 2001 From: mo k Date: Mon, 16 Apr 2012 16:40:35 -0600 Subject: refactor tests to something that looks less of a spike. --- src/domain/Month.cs | 50 +++++++++++++++++++++++ src/domain/Percent.cs | 55 +++++++++++++++++++++++++ src/domain/Well.cs | 98 -------------------------------------------- src/domain/domain.csproj | 2 + src/test/WellSpecs.cs | 103 ++++++++++++++++++++++++++++++++--------------- 5 files changed, 178 insertions(+), 130 deletions(-) create mode 100644 src/domain/Month.cs create mode 100644 src/domain/Percent.cs 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(Month month) where T : ICommodity, new(); IQuantity NetProductionFor(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 @@ + + 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(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(jan2013).ShouldEqual(100.BOED()); - schedule.EstimatedGrossProductionFor(jan2013).ShouldEqual(100.BOED()); - schedule.EstimatedGrossProductionFor(jan2013).ShouldEqual(0.BOED()); - schedule.EstimatedGrossProductionFor(jan2013).ShouldEqual(0.BOED()); - schedule.EstimatedGrossProductionFor(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(50m.Percent()); - declineCurve.Composition(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(jan2013).ShouldEqual(75.BOED()); - schedule.EstimatedNetProductionFor(jan2013).ShouldEqual(37.5m.BOED()); - schedule.EstimatedNetProductionFor(jan2013).ShouldEqual(37.5m.BOED()); - }; + Establish context = ()=> + { + parkland100Percent = new Oppurtunity(); + parkland100Percent.WorkingInterest(100m.Percent()); + var declineCurve = new DeclineCurve(); + declineCurve.Composition(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(jan2013).ShouldEqual(100.BOED()); + }; + + It should_be_able_to_tell_the_estimated_production_for_gas=()=> + { + sut.EstimatedGrossProductionFor(jan2013).ShouldEqual(100.BOED()); + }; + + It should_be_able_to_tell_the_estimated_production_for_oil=()=> + { + sut.EstimatedGrossProductionFor(jan2013).ShouldEqual(0.BOED()); + }; + + It should_be_able_to_tell_the_estimated_production_for_ngl=()=> + { + sut.EstimatedGrossProductionFor(jan2013).ShouldEqual(0.BOED()); + }; + + It should_be_able_to_tell_the_estimated_production_for_condensate=()=> + { + sut.EstimatedGrossProductionFor(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(50m.Percent()); + declineCurve.Composition(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(jan2013).ShouldEqual(75.BOED()); + schedule.EstimatedNetProductionFor(jan2013).ShouldEqual(37.5m.BOED()); + schedule.EstimatedNetProductionFor(jan2013).ShouldEqual(37.5m.BOED()); + }; + } } } } -- cgit v1.2.3