Commit 071efd4
Changed files (6)
src
domain
src/domain/GasPlant.cs
@@ -28,12 +28,7 @@ namespace domain
public IEnumerable<Month> MonthsOverAvailableCapacity()
{
- return MonthsOverAvailableCapacity(Month.Now());
- }
-
- public IEnumerable<Month> MonthsOverAvailableCapacity(Month month)
- {
- return MonthsOverAvailableCapacity(Month.Now().UpTo(month));
+ return MonthsOverAvailableCapacity(Month.Now().UpTo(new Month(2099, 12)));
}
public IEnumerable<Month> MonthsOverAvailableCapacity(IRange<Month> months)
@@ -41,14 +36,21 @@ namespace domain
var results = new List<Month>();
months.Accept(month =>
{
- var production = TotalProductionFor(month);
- Console.Out.WriteLine(production);
- if( capacity.For(month).IsGreaterThan(production) ){
+ if(IsOverCapacity(month)){
results.Add(month);
}
});
return results;
}
+
+ bool IsOverCapacity(Month month)
+ {
+ var production = TotalProductionFor(month);
+ if( capacity.AvailableFor(month).IsGreaterThan(production) ){
+ return true;
+ }
+ return false;
+ }
IQuantity TotalProductionFor(Month month)
{
IQuantity result = new Quantity(0, new BOED());
@@ -79,9 +81,13 @@ namespace domain
this.increases.Add(new Increase(quantity, month));
}
- public IQuantity For(Month month)
+ public IQuantity AvailableFor(Month month)
{
- //return this.increases.Single(x => x.IsFor(month)).;
+ return new Quantity(0, new BOED());
+ //return this
+ //.increases
+ //.Where(x => x.IsBeforeOrOn(month))
+ //.Sum(x => x.IncreasedCapacity());
return null;
}
@@ -96,10 +102,26 @@ namespace domain
this.month = month;
}
- public bool IsFor(Month other)
+ public bool IsBeforeOrOn(Month other)
{
- return month.Equals(other);
+ return month.IsBefore(other) || month.Equals(other);
}
+
+ public IQuantity IncreasedCapacity()
+ {
+ return this.quantity;
+ }
+ }
+ }
+ public static class Summation
+ {
+ static public IQuantity Sum(this IEnumerable<IQuantity> items)
+ {
+ var result = 0m.BOED();
+ foreach (var item in items) {
+ result = result.Plus(item);
+ }
+ return result;
}
}
}
src/domain/Month.cs
@@ -4,25 +4,23 @@ namespace domain
public class Month : IComparable<Month>, IIncrementable<Month>
{
- int year;
- int month;
+ DateTime date;
public Month(int year, int month)
{
- this.year = year;
- this.month = month;
+ date = new DateTime(year, month, 01);
}
public Month Plus(int months)
{
- var newMonth = ToDateTime().AddMonths(months);
- return ToMonth(newMonth);
+ return ToMonth(date.AddMonths(months));
}
- DateTime ToDateTime()
+ public bool IsBefore(Month other)
{
- return new DateTime(year, month, 01);
+ return this.CompareTo(other) < 0;
}
+
Month ToMonth(DateTime date)
{
return new Month(date.Year, date.Month);
@@ -36,7 +34,7 @@ namespace domain
public int CompareTo(Month other)
{
- return new DateTime(year, month, 01).CompareTo(new DateTime(other.year, other.month, 01));
+ return this.date.CompareTo(other.date);
}
public Month Next()
@@ -48,7 +46,7 @@ namespace domain
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
- return other.year == year && other.month == month;
+ return other.date == date;
}
public override bool Equals(object obj)
@@ -63,13 +61,13 @@ namespace domain
{
unchecked
{
- return (year*397) ^ month;
+ return (date.Year*397) ^ date.Month;
}
}
public override string ToString()
{
- return string.Format("{0} {1}", year, month);
+ return string.Format("{0} {1}", date.Year, date.Month);
}
}
src/domain/Quantity.cs
@@ -23,6 +23,7 @@ namespace domain
public IQuantity Plus(IQuantity other)
{
+ if(null == other) return this;
return new Quantity(Amount + other.ConvertTo(Units).Amount, Units);
}
src/test/MCFSpecs.cs
@@ -7,7 +7,9 @@ namespace test
{
sut = new MCF();
};
+
static MCF sut;
+
public class when_converting_6_mcf_to_boed
{
It should_return_one_boed=()=>
src/test/MonthSpecs.cs
@@ -20,5 +20,20 @@ namespace test
new Month(2012, 04).CompareTo(new Month(2012, 04)).ShouldEqual(0);
};
}
+ public class when_checking_if_a_month_is_before_another
+ {
+ It should_return_true_when_it_is =()=>
+ {
+ new Month(2012, 02).IsBefore(new Month(2012, 03)).ShouldBeTrue();
+ };
+ It should_return_false_when_it_is_not=()=>
+ {
+ new Month(2012, 03).IsBefore(new Month(2012, 02)).ShouldBeFalse();
+ };
+ It should_return_false_when_it_is_the_same_month=()=>
+ {
+ new Month(2012, 02).IsBefore(new Month(2012, 02)).ShouldBeFalse();
+ };
+ }
}
}
src/test/test.csproj
@@ -50,12 +50,12 @@
<Compile Include="GreetingSpecs.cs" />
<Compile Include="BOEDSpecs.cs" />
<Compile Include="CalculatorSpecs.cs" />
- <Compile Include="GasPlantSpecs.cs" />
<Compile Include="MCFSpecs.cs" />
<Compile Include="Mock.cs" />
<Compile Include="MonthSpecs.cs" />
<Compile Include="ProductionScheduleSpecs.cs" />
<Compile Include="RangeSpecs.cs" />
+ <Compile Include="GasPlantSpecs.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />