Inheritance: IUserCoinMeckRole
Example #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]));
            }
        }
Example #2
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));
        }
Example #3
0
        public void _利用者がお金を投入する()
        {
            var role = new CoinMeckRole ();
            var received = new CashDeal();

            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 void _Pool間でお金の移動を行う()
        {
            var pool1 = new CreditPool();
            var pool2 = new CreditPool(new Dictionary<Money, int> {
                {Money.Bill1000, 1},
                {Money.Coin500, 10},
                {Money.Coin100, 5}
            });

            var pool2Keys = new HashSet<Money>(pool2.Credits.Keys);

            var role = new CoinMeckRole();

            var pool4 = role.TransferMoney(pool1, pool2, (m1, m2) => m1+m2);

            Assert.That(pool4, Is.Not.EqualTo(pool2));
            Assert.That(pool4.Credits.Keys.All(m => pool2Keys.Contains(m)), Is.True);
            foreach (var k in pool2Keys) {
                Assert.That(pool4.Credits[k], Is.EqualTo(pool2.Credits[k]));
            }

            var pool5 = role.TransferMoney(pool4, pool2, (m1, m2) => m1-m2);

            Assert.That(pool5, Is.Not.EqualTo(pool1));
            foreach (var k in pool2Keys) {
                Assert.That(pool4.Credits[k], Is.EqualTo(pool2.Credits[k]));
                Assert.That(pool5.Credits[k], Is.EqualTo(0));
            }
        }
Example #5
0
        public void _お金を入れず購入()
        {
            var role = new CoinMeckRole ();
            var received = new CashDeal();

            Assert.False(role.Purchase(received, 100));

            Assert.That(received.UsedAmount, Is.EqualTo(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));
        }
Example #7
0
        public PurchaseContext(ChangePool inChanges, ItemRackPosition inItems)
        {
            mDealAmount = new CashDeal();
            mChanges    = inChanges;
            mItems      = inItems;

            mCoinMeckRole = new CoinMeckRole();
            mItemRole     = new ItemRackRole();
        }
Example #8
0
        public PurchaseContext(ChangePool inChanges, ItemRackPosition inItems)
        {
            mDealAmount = new CashDeal();
            mChanges = inChanges;
            mItems = inItems;

            mCoinMeckRole = new CoinMeckRole();
            mItemRole = new ItemRackRole();
        }
Example #9
0
        public void _何も購入せずお金を排出する(Money inMoney, int inRepeat)
        {
            var role = new CoinMeckRole ();
            var received = new CashDeal();
            var pool = TestHelper.InitInfinityReservedChange();

            for (var i = 0; i < inRepeat; ++i) {
                role.Receive(received, inMoney);
            }

            var changed = role.Eject(received, pool)
                .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));
        }
Example #10
0
        public void _何も購入せずお金を排出する(Money inMoney, int inRepeat)
        {
            var role = new CoinMeckRole ();
            var received = new CashDeal();
            var pool = TestHelper.InitInfinityReservedChange();

            role.Receive(received, inMoney, inRepeat);

            var expectReceived = received.RecevedMoney.TotalAmount();

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

            Assert.That(received.RecevedMoney.TotalAmount(), Is.EqualTo(expectReceived));

            Assert.That(changes.Count, Is.EqualTo(1));
            Assert.True(changes.ContainsKey(inMoney));
            Assert.That(changes[inMoney], Is.EqualTo(inRepeat));
        }
Example #11
0
        public void _お金投入による商品選択状態の変化(
            [ValueSource(typeof(商品選択状態の変化Params), "Source")] 
            商品選択状態の変化Params.Param inParameter)
        {
            var racks = TestHelper.InitInfinityItems(ItemRackState.CanNotPurchase);

            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);
            }

            foreach (var result in racks.Items.Zip(inParameter.States, (r, s) => Tuple.Create(r, s))) {
                itemRackRole.UpdateItemSelectionState(result.Item1, credit, pool);

                Assert.That(result.Item1.State, Is.EqualTo(result.Item2));
                Assert.That(itemRackRole.CanItemPurchase(result.Item1), Is.EqualTo(result.Item2 == ItemRackState.CanPurchase));            }
        }
Example #12
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);
                }
            }

            Assert.True(role.Purchase(received, 100));

            var changed = role.Eject(received, pool)
                .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);
            }
        }
Example #13
0
        public void _投入するお金の利用可不可を判定する()
        {
            var role = new CoinMeckRole();

            Assert.True(role.IsAvailableMoney(Money.Coin10), "10円は使用可能");
            Assert.True(role.IsAvailableMoney(Money.Coin50), "50円は使用可能");
            Assert.True(role.IsAvailableMoney(Money.Coin100), "100円は使用可能");
            Assert.True(role.IsAvailableMoney(Money.Coin500), "500円は使用可能");
            Assert.True(role.IsAvailableMoney(Money.Bill1000), "1000円は使用可能");

            Assert.False(role.IsAvailableMoney(Money.Coin1), "1円は使用不可");
            Assert.False(role.IsAvailableMoney(Money.Coin5), "5円は使用不可");
            Assert.False(role.IsAvailableMoney(Money.Bill2000), "2000円は使用不可");
            Assert.False(role.IsAvailableMoney(Money.Bill5000), "5000円は使用不可");
            Assert.False(role.IsAvailableMoney(Money.Bill10000), "10000円は使用不可");
        }
Example #14
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);
            }
        }
Example #15
0
        public void _利用者がお金を投入する_正しくない投入枚数の場合(int inCount)
        {
            var role = new CoinMeckRole ();
            var received = new CashDeal();

            Assert.False(role.Receive(received, Money.Coin10, inCount));
            Assert.False(role.Receive(received, Money.Coin50, inCount));
            Assert.False(role.Receive(received, Money.Coin100, inCount));
            Assert.False(role.Receive(received, Money.Coin500, inCount));
            Assert.False(role.Receive(received, Money.Bill1000, inCount));
            Assert.False(role.Receive(received, Money.Coin1, inCount));
            Assert.False(role.Receive(received, Money.Coin5, inCount));
            Assert.False(role.Receive(received, Money.Bill2000, inCount));
            Assert.False(role.Receive(received, Money.Bill5000, inCount));
            Assert.False(role.Receive(received, Money.Bill10000, inCount));
            Assert.False(role.Receive(received, Money.Coin10, inCount));
            Assert.False(role.Receive(received, Money.Coin50, inCount));
            Assert.False(role.Receive(received, Money.Coin100, inCount));
            Assert.False(role.Receive(received, Money.Coin500, inCount));
            Assert.False(role.Receive(received, Money.Bill1000, inCount));
            Assert.False(role.Receive(received, Money.Coin1, inCount));
            Assert.False(role.Receive(received, Money.Coin5, inCount));
            Assert.False(role.Receive(received, Money.Bill2000, inCount));
            Assert.False(role.Receive(received, Money.Bill5000, inCount));
            Assert.False(role.Receive(received, Money.Bill10000, inCount));

            Assert.False(received.RecevedMoney.Credits.ContainsKey(Money.Coin1));
            Assert.False(received.RecevedMoney.Credits.ContainsKey(Money.Coin5));
            Assert.False(received.RecevedMoney.Credits.ContainsKey(Money.Bill2000));
            Assert.False(received.RecevedMoney.Credits.ContainsKey(Money.Bill5000));
            Assert.False(received.RecevedMoney.Credits.ContainsKey(Money.Bill10000));

            Assert.That(received.ChangedAount, Is.EqualTo(0));
        }