Beispiel #1
0
 public IStoreGoodInfo this[Good good]
 {
     get
     {
         return _store[good].Info;
     }
 }
Beispiel #2
0
 public IStoreGood this[Good good]
 {
     get
     {
         return _goods.GetOrInit(good, _storeGoodFactory.Create);
     }
 }
 public float GetSupplyDemand(Good good, int period)
 {
     Contract.Requires<ArgumentNullException>(good != null);
     Contract.Requires<ArgumentOutOfRangeException>(period > 0);
     Contract.Ensures(Contract.Result<float>() >= -1 && Contract.Result<float>() <= 1);
     throw new NotImplementedException();
 }
 public float? GetAveragePrice(Good good, int period)
 {
     Contract.Requires<ArgumentNullException>(good != null);
     Contract.Requires<ArgumentOutOfRangeException>(period > 0);
     Contract.Ensures(!Contract.Result<float?>().HasValue || Contract.Result<float?>().Value >= 0);
     throw new NotImplementedException();
 }
Beispiel #5
0
 protected void Produce(IEconomyTraderProxy proxy, Good good, float amount, float chance = 1f)
 {
     if (chance >= 1f || ThreadStaticRandomProvider.Instance.NextDouble() < chance)
     {
         proxy.AddGoods(good, amount);
     }
 }
Beispiel #6
0
 public void EqualsTest()
 {
     var good1 = new Good("Good");
     var good2 = new Good("Good");
     Assert.IsFalse(good1 == good2);
     Assert.IsFalse(good1.Equals(good2));
 }
Beispiel #7
0
 internal TradeRequest(IStore store, TradeRequestType type, Good good, float amount, float price)
 {
     _store = store;
     Type = type;
     Good = good;
     Amount = amount;
     Price = price;
 }
Beispiel #8
0
 public void SellTest()
 {
     var good = new Good("good");
     var proxyMock = new Mock<IEconomyTraderProxy>();
     proxyMock.SetupGet(p => p.Active).Returns(true);
     proxyMock.Object.Sell(good, 1, 2);
     proxyMock.Verify(p => p.CreateTradeRequest(TradeRequestType.Sell, good, 1, 2));
 }
Beispiel #9
0
 public TradeRequest CreateTradeRequest(TradeRequestType type, Good good, float amount, float price)
 {
     Contract.Requires<ArgumentNullException>(good != null);
     Contract.Requires<ArgumentOutOfRangeException>(amount > 0);
     Contract.Requires<ArgumentOutOfRangeException>(price >= 0);
     Contract.Requires<InvalidOperationException>(type == TradeRequestType.Buy || this[good].Amount >= amount);
     Contract.Ensures(Contract.Result<TradeRequest>() != null);
     throw new NotImplementedException();
 }
 public IStoreGoodInfo this[Good good]
 {
     get
     {
         Contract.Requires<ArgumentNullException>(good != null);
         Contract.Ensures(Contract.Result<IStoreGoodInfo>() != null);
         throw new NotImplementedException();
     }
 }
Beispiel #11
0
        public void EqualsTest()
        {
            var good1 = new Good("Good");
            var good2 = new Good("Good");

            Assert.IsTrue((good1 * 1).Equals(good1 * 1));
            Assert.IsFalse((good1 * 1).Equals(good1 * 2));
            Assert.IsFalse((good1 * 1).Equals(good2 * 1));
        }
Beispiel #12
0
 public void OnTradeRequestFinish(TradeRequestType type, Good good, float amount, float price, float soldAmount, float soldTotalPrice)
 {
     Contract.Requires<ArgumentNullException>(good != null);
     Contract.Requires<ArgumentOutOfRangeException>(amount >= 0);
     Contract.Requires<ArgumentOutOfRangeException>(price >= 0);
     Contract.Requires<ArgumentOutOfRangeException>(soldAmount >= 0);
     Contract.Requires<ArgumentOutOfRangeException>(soldTotalPrice >= 0);
     throw new NotImplementedException();
 }
 public void CreateTradeRequest(TradeRequestType type, Good good, float amount, float price)
 {
     Contract.Requires<InvalidOperationException>(Active);
     Contract.Requires<ArgumentNullException>(good != null);
     Contract.Requires<ArgumentOutOfRangeException>(amount > 0);
     Contract.Requires<ArgumentOutOfRangeException>(price >= 0);
     Contract.Requires<InvalidOperationException>(type == TradeRequestType.Buy || Store[good].Amount >= amount);
     throw new NotImplementedException();
 }
Beispiel #14
0
 public TradeRequest CreateTradeRequest(TradeRequestType type, Good good, float amount, float price)
 {
     var request = new TradeRequest(this, type, good, amount, price);
     if (type == TradeRequestType.Sell)
     {
         Add(good, -amount);
     }
     else
     {
         Money -= amount * price;
     }
     return request;
 }
        public void ExecuteAndFinishTest()
        {
            var buyTraderMock = new Mock<ITrader>();
            var sellTraderMock = new Mock<ITrader>();
            var buyStoreMock = SetUpStoreMock(new Mock<IStore>(), buyTraderMock);
            var sellStoreMock = SetUpStoreMock(new Mock<IStore>(), sellTraderMock);

            var good = new Good("Good");

            var buy = new TradeRequest(buyStoreMock.Object, TradeRequestType.Buy, good, 20f, 3f);
            var sell = new TradeRequest(sellStoreMock.Object, TradeRequestType.Sell, good, 10f, 1f);

            //execute
            var logEntry = TradeRequest.Execute(buy, sell, 0);

            // check requests
            Assert.IsFalse(buy.IsEmpty);
            Assert.IsTrue(sell.IsEmpty);
            Assert.AreEqual(10f, buyStoreMock.Object.Money);
            Assert.AreEqual(20f, sellStoreMock.Object.Money);
            buyStoreMock.Verify(o => o.Add(good, 10f));

            // check log entry
            Assert.AreEqual(10f, logEntry.Amount);
            Assert.AreEqual(3f, logEntry.BuyPrice);
            Assert.AreEqual(1f, logEntry.SellPrice);
            Assert.AreEqual(2f, logEntry.Price);
            Assert.AreEqual(good, logEntry.Good);
            Assert.AreEqual(0, logEntry.Time);

            //finish
            var logEntry2 = buy.Finish(0);
            Assert.IsNull(sell.Finish(0));

            // check requests
            Assert.IsTrue(buy.IsEmpty);
            Assert.AreEqual(40f, buyStoreMock.Object.Money);
            buyTraderMock.Verify(o => o.OnTradeRequestFinish(TradeRequestType.Buy, good, 20, 3f, 10, 20f));
            sellTraderMock.Verify(o => o.OnTradeRequestFinish(TradeRequestType.Sell, good, 10, 1f, 10, 20f));

            // check log entry 2
            Assert.AreEqual(10f, logEntry2.Amount);
            Assert.AreEqual(3f, logEntry2.Price);
            Assert.AreEqual(TradeRequestType.Buy, logEntry2.Type);
            Assert.AreEqual(good, logEntry2.Good);
            Assert.AreEqual(0, logEntry2.Time);
        }
Beispiel #16
0
 public void SetUp()
 {
     _good = new Good("Good");
     _traderMock = new Mock<ITrader>();
     _store = new Store(_traderMock.Object, new StoreGoodFactory());
 }
Beispiel #17
0
 public abstract void OnTradeRequestFinish(TradeRequestType type, Good good, float amount, float price, float soldAmount, float soldTotalPrice);
 public void AddGoods(Good good, float amount)
 {
     _container.Store.Add(good, amount);
 }
 public FailedTradingHistoryEntry(Good good, float amount, TradeRequestType type, float price, int time)
     : base(good, amount, time)
 {
     Type = type;
     Price = price;
 }
 public SuccessfulTradingHistoryEntry(Good good, float amount, float buyPrice, float sellPrice, int time)
     : base(good, amount, time)
 {
     BuyPrice = buyPrice;
     SellPrice = sellPrice;
 }
Beispiel #21
0
 public bool Has(Good good, float amount)
 {
     return this[good].Amount >= amount;
 }
 public float? GetAveragePrice(Good good, int period)
 {
     return _container.Economy.Market.History.GetAveragePrice(good, period);
 }
Beispiel #23
0
 public void Add(Good good, float amount)
 {
     this[good].Amount += amount;
 }
 public void CreateTradeRequest(TradeRequestType type, Good good, float amount, float price)
 {
     var request = _container.Store.CreateTradeRequest(type, good, amount, price);
     _container.Economy.Market.RegisterTradeRequest(request);
 }
 public override void OnTradeRequestFinish(TradeRequestType type, Good good, float amount, float price, float soldAmount,
     float soldTotalPrice)
 {
     Contract.Requires(MarketTraderProxy != null && MarketTraderProxy.Active);
     throw new System.NotImplementedException();
 }
 public IStoreGood Create(Good good)
 {
     Contract.Requires<ArgumentNullException>(good != null);
     Contract.Ensures(Contract.Result<IStoreGood>() != null);
     throw new NotImplementedException();
 }
 protected BaseTradingHistoryEntry(Good good, float amount, int time)
 {
     Good = good;
     Amount = amount;
     Time = time;
 }
Beispiel #28
0
 public StoreGood(Good good)
 {
     Contract.Requires<ArgumentNullException>(good != null);
     Good = good;
 }
 public void OnTradeRequestFinishTest()
 {
     var good = new Good("Good");
     _eventedTrader.OnTradeRequestFinish(TradeRequestType.Buy, good, 1, 1, 1, 1);
     _traderMock.Verify(t => t.OnTradeRequestFinish(TradeRequestType.Buy, good, 1, 1, 1, 1));
 }
 public float GetSupplyDemand(Good good, int period)
 {
     return _container.Economy.Market.History.GetSupplyDemand(good, period);
 }