public void _利用者がお金を投入する() { var role = new CoinMeckRole (); var received = new CashFlow(); Assert.True(role.Receive(received, Money.Coin10)); Assert.True(role.Receive(received, Money.Coin50)); Assert.True(role.Receive(received, Money.Coin100)); Assert.True(role.Receive(received, Money.Coin500)); Assert.True(role.Receive(received, Money.Bill1000)); Assert.False(role.Receive(received, Money.Coin1)); Assert.False(role.Receive(received, Money.Coin5)); Assert.False(role.Receive(received, Money.Bill2000)); Assert.False(role.Receive(received, Money.Bill5000)); Assert.False(role.Receive(received, Money.Bill10000)); Assert.True(role.Receive(received, Money.Coin10)); Assert.True(role.Receive(received, Money.Coin50)); Assert.True(role.Receive(received, Money.Coin100)); Assert.True(role.Receive(received, Money.Coin500)); Assert.True(role.Receive(received, Money.Bill1000)); Assert.False(role.Receive(received, Money.Coin1)); Assert.False(role.Receive(received, Money.Coin5)); Assert.False(role.Receive(received, Money.Bill2000)); Assert.False(role.Receive(received, Money.Bill5000)); Assert.False(role.Receive(received, Money.Bill10000)); Assert.False(received.RecevedMoney.Contains(Money.Coin1)); Assert.False(received.RecevedMoney.Contains(Money.Coin5)); Assert.False(received.RecevedMoney.Contains(Money.Bill2000)); Assert.False(received.RecevedMoney.Contains(Money.Bill5000)); Assert.False(received.RecevedMoney.Contains(Money.Bill10000)); Assert.That(received.ChangedAount, Is.EqualTo(3320)); }
public IEnumerable<Money> Eject(CashFlow inCash, ReservedMoney inReservedMoney) { try { if (inCash.UsedAmount == 0) { return inCash.RecevedMoney.ToList(); } var received = inCash.RecevedMoney .GroupBy(m => m) .ToDictionary(g => g.Key, g => g.Count()) ; var result = new List<KeyValuePair<Money, int>>(); this.EjectCore( inCash.ChangedAount, inReservedMoney.Items.OrderByDescending(pair => pair.Key.Value()), (m, totalCount, useCount) => { result.Add( new KeyValuePair<Money, int>(m, (int)useCount) ); } ); return result.SelectMany(r => Enumerable.Repeat(r.Key, r.Value)); } finally { inCash.RecevedMoney.Clear(); } }
public void _お金を入れず購入() { var role = new CoinMeckRole (); var received = new CashFlow(); Assert.False(role.Purchase(received, 100)); Assert.That(received.UsedAmount, Is.EqualTo(0)); }
public bool Receive(CashFlow inCash, Money inMoney) { if (this.IsAvailableMoney(inMoney)) { inCash.RecevedMoney.Add(inMoney); return true; } return false; }
public bool Purchase(CashFlow inCash, int inItemValue) { if (inCash.ChangedAount >= inItemValue) { inCash.UsedAmount += inItemValue; return true; } return false; }
public void _何も購入せずお金を排出する(Money inMoney, int inRepeat) { var role = new CoinMeckRole (); var received = new CashFlow(); var reserved = this.InitInfinityReservedChange(); for (var i = 0; i < inRepeat; ++i) { role.Receive(received, inMoney); } var changed = role.Eject(received, reserved) .GroupBy(m => m) .ToDictionary(g => g.Key, g => g) ; Assert.That(received.RecevedMoney.Count, Is.EqualTo(0)); Assert.That(changed.Count, Is.EqualTo(1)); Assert.True(changed.ContainsKey(inMoney)); Assert.That(changed[inMoney].Count(), Is.EqualTo(inRepeat)); }
public void _商品購入後お金を排出する( [ValueSource(typeof(_商品購入後お金を排出するParams), "Source")] _商品購入後お金を排出するParams.Parameter inParameter) { var role = new CoinMeckRole (); var received = new CashFlow (); var reserved = this.InitInfinityReservedChange (); foreach (var m in inParameter.ReceivedMoney) { for (var i = 0; i < m.Item2; ++i) { role.Receive (received, m.Item1); } } Assert.True(role.Purchase(received, 100)); var changed = role.Eject(received, reserved) .GroupBy(m => m) .ToDictionary(g => g.Key, g => g) ; var lookup = inParameter.ChangedMoney.ToDictionary(m => m.Item1, m => m.Item2); Assert.That(received.RecevedMoney.Count, Is.EqualTo(0)); Assert.That(received.UsedAmount, Is.EqualTo(100)); Assert.That(changed.Count, Is.EqualTo(lookup.Count), "count money type (id = {0})", inParameter.Id); foreach (var pair in changed) { Assert.True(lookup.ContainsKey(pair.Key), "money ({0}) should be contained (id = {1})", pair.Key, inParameter.Id); Assert.That(pair.Value.Count(), Is.EqualTo (lookup[pair.Key]), "money ({0}) count should be equaled (id = {1})", pair.Key, inParameter.Id); } }