public void じ金額ならHashCodeも同じ() { var a = new 通貨(100); var b = new 通貨(100); Assert.IsTrue(a.GetHashCode() == b.GetHashCode()); }
public void Thisとは等しい() { var x = new 通貨(100); Assert.IsTrue(x.Equals(x as object)); Assert.IsTrue(x.Equals(x)); }
public void 通貨100円から通貨200円を引くと通貨マイナス100円になる() { var a = new 通貨(100); var b = new 通貨(200); var c = new 通貨(-100); Assert.IsTrue(a - b == c); }
public void 通貨100円と通貨200円を足すと通貨300円になる() { var a = new 通貨(100); var b = new 通貨(200); var c = new 通貨(300); Assert.IsTrue(a + b == c); }
public IEnumerable <硬貨> 決済(通貨 請求金額) { if (this.投入金額合計() < 請求金額) { throw new InvalidOperationException("cannot payment"); } var result = this.Factorize硬貨(this.投入金額合計() - 請求金額); this.投入硬貨.Clear(); return(result); }
public I自動販売機CommandResult Insert貨幣(自動販売機Insert貨幣Command command) { var result = new 通貨(command.投入金額); try { this.自動販売機.Insert貨幣(new 硬貨(command.投入金額)); } catch { return(new 自動販売機Insert貨幣FailureCommandResult(result)); } return(new 自動販売機Insert貨幣SuccessCommandResult(result)); }
private IEnumerable <硬貨> Factorize硬貨(通貨 金額) { List <硬貨> result = new List <硬貨>(); foreach (var x in 硬貨.AvailableValues.OrderByDescending(x => x)) { int n = 金額.Value / x; for (int i = 0; i < n; i++) { result.Add(new 硬貨(x)); } 金額 -= new 硬貨(x) * n; } return(result); }
public 自動販売機Insert貨幣FailureCommandResult(通貨 投入金額) { this.投入金額 = 投入金額 ?? throw new ArgumentNullException(nameof(投入金額) + " cannot be null"); }
public 自動販売機投入金額合計CommandResult(通貨 投入金額合計) { this.投入金額合計 = 投入金額合計; }