Esempio n. 1
0
        public void ReturnsHighestValueGivenAuctionWithAtOneBid(
            double expectedAmount,
            double[] offers)
        {
            //Arranje
            var modality = new HighestValue();
            var auction  = new Auction("Corvette CR7", modality);
            var buyer    = new Client("Marcio", auction);
            var buyer2   = new Client("Maria", auction);

            auction.StartsPreaching();
            for (int i = 0; i < offers.Length; i++)
            {
                var value = offers[i];
                if ((i % 2) == 0)
                {
                    auction.ReceiveBid(buyer, value);
                }
                else
                {
                    auction.ReceiveBid(buyer2, value);
                }
            }

            //Act
            auction.EndsPreaching();

            //Assert
            var obtainedAmount = auction.Winner.Value;

            Assert.Equal(expectedAmount, obtainedAmount);
        }
Esempio n. 2
0
        public void DoesNotAllowNewBidsGivenAuctionEnded(
            int expectedAmount, double[] offers)
        {
            //Arranje
            var modality = new HighestValue();
            var auction  = new Auction("Corvette CR7", modality);
            var buyer    = new Client("Marcio", auction);
            var buyer2   = new Client("Maria", auction);

            auction.StartsPreaching();
            for (int i = 0; i < offers.Length; i++)
            {
                var value = offers[i];
                if ((i % 2) == 0)
                {
                    auction.ReceiveBid(buyer, value);
                }
                else
                {
                    auction.ReceiveBid(buyer2, value);
                }
            }
            auction.EndsPreaching();

            //Act
            auction.ReceiveBid(buyer, 1000);

            //Assert
            var obtainedAmount = auction.Binds.Count();

            Assert.Equal(expectedAmount, obtainedAmount);
        }
Esempio n. 3
0
        public override string ToString()
        {
            string ls = LowestValue.Equals(minValue) ? "-Inf" : LowestValue.ToString();
            string hs = HighestValue.Equals(maxValue) ? "Inf" : HighestValue.ToString();

            return(Value.ToString() + " [" + ls + ", " + hs + "]");
        }
Esempio n. 4
0
 /// <summary>
 /// gets the current info and places it in an info array the will be saved
 /// </summary>
 /// <returns>the info array</returns>
 public string[] GetInfo()
 {
     string[] info = new string[4];
     info[0] = LastValue.ToString();
     info[1] = HighestValue.ToString();
     info[2] = Key.ToString();
     info[3] = Name;
     return(info);
 }
Esempio n. 5
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Id.GetHashCode();
         hashCode = (hashCode * 397) ^ TimeStamp.GetHashCode();
         hashCode = (hashCode * 397) ^ (RealmSlug?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ MeanValue.GetHashCode();
         hashCode = (hashCode * 397) ^ AdjustedMeanValue.GetHashCode();
         hashCode = (hashCode * 397) ^ LowestValue.GetHashCode();
         hashCode = (hashCode * 397) ^ HighestValue.GetHashCode();
         hashCode = (hashCode * 397) ^ Quantity;
         return(hashCode);
     }
 }
Esempio n. 6
0
        public void InvalidOperationExceptionWhenPreachingNotStarted()
        {
            //Arranje
            var modality = new HighestValue();
            var auction  = new Auction("Corvette CR7", modality);

            //Assert
            var exceptionObtained = Assert.Throws <System.InvalidOperationException>(
                //Act
                () => auction.EndsPreaching()
                );

            var expectedMessage = "It is not possible to finish the trading session without it having started.";

            Assert.Equal(expectedMessage, exceptionObtained.Message);
        }
Esempio n. 7
0
        public void ReturnsZeroGivenAuctionWithoutBids()
        {
            //Arranje
            var modality = new HighestValue();
            var auction  = new Auction("Corvette CR7", modality);

            auction.StartsPreaching();

            //Act
            auction.EndsPreaching();

            //Assert
            var expectedAmount = 0;
            var obtainedAmount = auction.Winner.Value;

            Assert.Equal(expectedAmount, obtainedAmount);
        }
Esempio n. 8
0
 public override dynamic GetObjectToSerialize(bool is_explicit)
 {
     IsExplicit = is_explicit;
     if (IsExplicit)
     {
         Dictionary <string, object> dict = base.GetObjectToSerialize(is_explicit) as Dictionary <string, object>;
         if (HighestValue.CompareTo(maxValue) < 0)
         {
             dict["higher_bound"] = HighestValue;
         }
         if (LowestValue.CompareTo(minValue) > 0)
         {
             dict["lower_bound"] = LowestValue;
         }
         return(dict);
     }
     return(Value);
 }
Esempio n. 9
0
        public void DontAcceptNextBidWhenSameClientPerformedLastBid()
        {
            //Arranje
            var modality = new HighestValue();
            var auction  = new Auction("Corvette CR7", modality);
            var buyer    = new Client("Marcio", auction);

            auction.StartsPreaching();
            auction.ReceiveBid(buyer, 800);

            //Act
            auction.ReceiveBid(buyer, 1000);

            //Assert
            var expectedAmount = 1;
            var obtainedAmount = auction.Binds.Count();

            Assert.Equal(expectedAmount, obtainedAmount);
        }
Esempio n. 10
0
 protected bool Equals(ItemData other)
 {
     return(Id == other.Id && TimeStamp.Equals(other.TimeStamp) && string.Equals(RealmSlug, other.RealmSlug) && MeanValue.Equals(other.MeanValue) && AdjustedMeanValue.Equals(other.AdjustedMeanValue) && LowestValue.Equals(other.LowestValue) && HighestValue.Equals(other.HighestValue) && Quantity == other.Quantity);
 }