CalcChanges() 공개 메소드

public CalcChanges ( CashDeal inCash, CreditPool inChangePool, int inItemValue ) : CreditPool
inCash CashDeal
inChangePool CreditPool
inItemValue int
리턴 CreditPool
예제 #1
0
        public void _お金投入による商品選択状態の変化_売り切れの場合(
            [ValueSource(typeof(商品選択状態の変化Params), "SoldOutSource")] 
            商品選択状態の変化Params.Param inParameter)
        {
            var positions = TestHelper.InitInfinityItems(ItemRackState.Soldout);

            var pool = TestHelper.InitInfinityReservedChange();
            var credit = new CashDeal();

            var coinMeckRole = new CoinMeckRole();
            var itemRackRole = new  ItemRackRole();

            foreach (var c in inParameter.Credits) {
                coinMeckRole.Receive(credit, c, 1);
            }

            foreach (var p in Enumerable.Range(0, positions.Racks.Length)) {
                var newState = itemRackRole.UpdateItemSelectionState(
                    positions.Racks[p], credit,
                    coinMeckRole.CalcChanges(credit, pool, positions.Racks[p].Item.Price)
                    );

                Assert.That(newState, Is.EqualTo(inParameter.States[p]));
            }
        }
예제 #2
0
        public void _お金を入れず購入()
        {
            var role = new CoinMeckRole ();
            var received = new CashDeal();
            var pool = new CreditPool();

            var changes = role.CalcChanges(received, pool, 100);
            Assert.That(changes.TotalAmount(), Is.EqualTo(0));
        }
예제 #3
0
        public void _商品を購入する()
        {
            var racks = TestHelper.InitInfinityItems(ItemRackState.CanNotPurchase);

            var pool = TestHelper.InitInfinityReservedChange();
            var credit = new CashDeal();

            var coinMeckRole = new CoinMeckRole();
            var itemRackRole = new  ItemRackRole();

            coinMeckRole.Receive(credit, Money.Coin100, 1);
            coinMeckRole.Receive(credit, Money.Coin10, 1);
            coinMeckRole.Receive(credit, Money.Coin10, 1);

            var rack = itemRackRole.FindRackAt(racks, 0);
            itemRackRole.UpdateItemSelectionState(
                rack, credit,
                coinMeckRole.CalcChanges(credit, pool, rack.Item.Price)
            );

            var svCount = rack.Count;
            Assert.That(rack.State, Is.EqualTo(ItemRackState.CanPurchase));

            coinMeckRole.CalcChanges(credit, pool, rack.Item.Price);
            var item = itemRackRole.Purchase(rack);

            Assert.That(item, Is.Not.Null);
            Assert.That(item.Name, Is.EqualTo("Item0"));

            Assert.That(rack.Count, Is.EqualTo(svCount-1));
        }
예제 #4
0
        public void _商品購入後お金を排出する(
			    [ValueSource(typeof(_商品購入後お金を排出するParams), "Source")] 
			    _商品購入後お金を排出するParams.Parameter inParameter)
        {
            var role = new CoinMeckRole();
            var received = new CashDeal();
            var pool = TestHelper.InitInfinityReservedChange();

            foreach (var m in inParameter.ReceivedMoney) {
                for (var i = 0; i < m.Item2; ++i) {
                    role.Receive (received, m.Item1, 1);
                }
            }

            var newReceives = new CashDeal(role.CalcChanges(received, pool, 100));
            var changes = role.Eject(newReceives, pool)
                .Credits
                .Where(c => c.Value > 0)
                .ToDictionary(g => g.Key, g => g.Value)
            ;

            var lookup = inParameter.ChangedMoney.ToDictionary(m => m.Item1, m => m.Item2);

            Assert.That(changes.Count, Is.EqualTo(lookup.Count), "count money type (id = {0})", inParameter.Id);

            foreach (var pair in changes) {
                Assert.True(lookup.ContainsKey(pair.Key), "money ({0}) should be contained (id = {1})", pair.Key, inParameter.Id);
                Assert.That(pair.Value, Is.EqualTo (lookup[pair.Key]), "money ({0}) count should be equaled (id = {1})", pair.Key, inParameter.Id);
            }
        }