Пример #1
0
        public void BigInt_Compare_ReturnsZeroIfValuesAreEqual()
        {
            BigInt bigInt1 = BigInt.FromLong(10);
            BigInt bigInt2 = BigInt.FromLong(10);

            Assert.AreEqual(0, bigInt1.Compare(bigInt2));
        }
Пример #2
0
        public void BigInt_Compare_ReturnsMinusOneIfParamIsGreater()
        {
            BigInt bigInt1 = BigInt.FromLong(5);
            BigInt bigInt2 = BigInt.FromLong(10);

            Assert.Equal(-1, bigInt1.Compare(bigInt2));
        }
Пример #3
0
        public void BigInt_Compare_ReturnsZeroOrMinusOneIfGivenBigIntIsEmpty()
        {
            BigInt bigInt = new BigInt();

            Assert.AreEqual(-1, bigInt.Compare(BigInt.FromLong(0)));
            Assert.AreEqual(0, bigInt.Compare(bigInt));
        }
Пример #4
0
        public void BigInt_Compare_ReturnsOneIfParamIsEmpty()
        {
            BigInt bigInt1 = BigInt.FromLong(10);
            BigInt bigInt2 = new BigInt();

            Assert.AreEqual(1, bigInt1.Compare(bigInt2));
        }
Пример #5
0
        public void BigInt_Compare_ReturnsMinusOneIfParamIsLess()
        {
            BigInt bigInt1 = BigInt.FromLong(50);
            BigInt bigInt2 = BigInt.FromLong(10);

            Assert.AreEqual(1, bigInt1.Compare(bigInt2));
        }
Пример #6
0
        public void BigInt_Print_DigitSeparatorIsCommaIfCommodityDoesNotHave_COMMODITY_STYLE_DECIMAL_COMMA()
        {
            Commodity comm = new Commodity(CommodityPool.Current, new CommodityBase("comm"));

            comm.Flags = CommodityFlagsEnum.COMMODITY_STYLE_THOUSANDS; /* no COMMODITY_STYLE_DECIMAL_COMMA */
            Assert.AreEqual("1,000", BigInt.FromLong(1000).Print(0, 2, comm));
        }
Пример #7
0
        public void BigInt_IsZeroInPrecision_ReturnsTrueForZero()
        {
            BigInt bigInt = BigInt.Parse("0");

            Assert.IsTrue(bigInt.IsZeroInPrecision());

            bigInt = BigInt.FromLong(0);
            bigInt.SetPrecision(4);
            Assert.IsTrue(bigInt.IsZeroInPrecision());
        }
Пример #8
0
        public void Amount_Subtract_ReturnsSubtractedAmountForTheSameCommodity()
        {
            Commodity comm     = new Commodity(CommodityPool.Current, new CommodityBase("comm"));
            Amount    amount10 = new Amount(BigInt.FromLong(10), comm);
            Amount    amount8  = new Amount(BigInt.FromLong(8), comm);

            Amount amount = amount10.InPlaceSubtract(amount8);

            Assert.AreEqual(2, amount.Quantity.ToLong());
        }
Пример #9
0
        public void Balance_CommodityAmount_LooksForAddedAmountWithTheSameCommodity()
        {
            Commodity comm    = new Commodity(CommodityPool.Current, new CommodityBase("comm"));
            Balance   balance = new Balance();

            balance.Add(new Amount(BigInt.FromLong(5), comm));

            Amount amount = balance.CommodityAmount(comm);

            Assert.AreEqual(5, amount.Quantity.ToLong());
        }
Пример #10
0
        public void Commodity_CompareByCommodity_PerformsOrdinalComparisonForBaseSymbol()
        {
            Commodity commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("€"));
            Commodity commodity2 = new Commodity(CommodityPool.Current, new CommodityBase("EUR"));

            Amount amount1 = new Amount(BigInt.FromLong(0), commodity1);
            Amount amount2 = new Amount(BigInt.FromLong(0), commodity2);

            Assert.IsFalse(Commodity.CompareByCommodity(amount1, amount2));
            Assert.IsTrue(Commodity.CompareByCommodity(amount2, amount1));
        }
Пример #11
0
        public void Commodity_CompareByCommodity_ComparesBaseSymbolsIfTheyAreNotEqual()
        {
            Commodity commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("comm1"));
            Commodity commodity2 = new Commodity(CommodityPool.Current, new CommodityBase("comm2"));

            Amount amount1 = new Amount(BigInt.FromLong(0), commodity1);
            Amount amount2 = new Amount(BigInt.FromLong(0), commodity2);

            Assert.IsTrue(Commodity.CompareByCommodity(amount1, amount2));
            Assert.IsFalse(Commodity.CompareByCommodity(amount2, amount1));
        }
Пример #12
0
        public void Balance_CommodityAmount_ReturnsExistingSingleCommodity()
        {
            Commodity comm    = new Commodity(CommodityPool.Current, new CommodityBase("comm"));
            Balance   balance = new Balance();

            balance.Add(new Amount(BigInt.FromLong(5), comm));

            Amount amount = balance.CommodityAmount();

            Assert.AreEqual(5, amount.Quantity.ToLong());
        }
Пример #13
0
        public void Balance_EqualsAmount_ComparesSingleAmountWithAmount()
        {
            Commodity commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("base-1"));

            Balance balance = new Balance();

            balance.Add(new Amount(BigInt.FromInt(10), commodity1));
            balance.Add(new Amount(BigInt.FromInt(20), commodity1));

            Assert.IsTrue(balance.Equals(new Amount(BigInt.FromLong(30), commodity1)));
        }
Пример #14
0
        public void Amount_StripAnnotations_ReturnsOriginalAmountIfKeepAllIsTrue()
        {
            Commodity             comm        = new Commodity(CommodityPool.Current, new CommodityBase("comm"));
            Amount                amount      = new Amount(BigInt.FromLong(10), comm);
            AnnotationKeepDetails keepDetails = new AnnotationKeepDetails();

            // Commodity is not annotated - it is enough condition to return the original object
            Amount newAmount = amount.StripAnnotations(keepDetails);

            Assert.AreEqual(amount, newAmount);
        }
Пример #15
0
        public void BigInt_Print_NoPrefixZerosForHundreds()
        {
            Commodity commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("comm"));
            Commodity commodity2 = new Commodity(CommodityPool.Current, new CommodityBase("comm"));

            commodity2.Flags = CommodityFlagsEnum.COMMODITY_STYLE_THOUSANDS | CommodityFlagsEnum.COMMODITY_STYLE_DECIMAL_COMMA;
            BigInt bigInt1 = BigInt.FromLong(100);

            Assert.AreEqual("100.00", bigInt1.Print(2, 2));
            Assert.AreEqual("100.00", bigInt1.Print(2, 2, commodity1));
            Assert.AreEqual("100,00", bigInt1.Print(2, 2, commodity2));
        }
Пример #16
0
        public void BigInt_Print_CommodityAffectsDecimalMark()
        {
            Commodity commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("comm"));
            Commodity commodity2 = new Commodity(CommodityPool.Current, new CommodityBase("comm"));

            commodity2.Flags = CommodityFlagsEnum.COMMODITY_STYLE_THOUSANDS | CommodityFlagsEnum.COMMODITY_STYLE_DECIMAL_COMMA;
            BigInt bigInt1 = BigInt.FromLong(1000);

            Assert.AreEqual("1000.00", bigInt1.Print(2, 2));
            Assert.AreEqual("1000.00", bigInt1.Print(2, 2, commodity1));
            Assert.AreEqual("1.000,00", bigInt1.Print(2, 2, commodity2));
        }
Пример #17
0
        public void IntegerValueStorage_Add_AddsAmountWithCommodityAndChangesToBalance()
        {
            string    commodityName = "test-commodity";
            Commodity commodity     = CommodityPool.Current.Find(commodityName) ?? CommodityPool.Current.Create(commodityName);

            IntegerValueStorage storage1 = new IntegerValueStorage(100);
            AmountValueStorage  storage2 = new AmountValueStorage(new Amount(BigInt.FromLong(200), commodity));

            IValueStorage result = storage1.Add(storage2);

            Assert.AreEqual(ValueTypeEnum.Balance, result.Type);
        }
Пример #18
0
        public void BigInt_Print_CommodityHasToHaveStyleThousandsToAffectDigitSeparator()
        {
            Commodity commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("comm"));
            Commodity commodity2 = new Commodity(CommodityPool.Current, new CommodityBase("comm"));

            commodity2.Flags = CommodityFlagsEnum.COMMODITY_STYLE_THOUSANDS | CommodityFlagsEnum.COMMODITY_STYLE_DECIMAL_COMMA;
            BigInt bigInt1 = BigInt.FromLong(1000);

            Assert.AreEqual("1000", bigInt1.Print(0, 0));
            Assert.AreEqual("1000", bigInt1.Print(0, 0, commodity1));
            Assert.AreEqual("1.000", bigInt1.Print(0, 0, commodity2));
        }
Пример #19
0
        public void Amount_StripAnnotations_ReturnsNewAmountForAnnotatedCommodity()
        {
            Commodity             comm        = new Commodity(CommodityPool.Current, new CommodityBase("comm"));
            AnnotatedCommodity    annComm     = new AnnotatedCommodity(comm, new Annotation());
            Amount                amount      = new Amount(BigInt.FromLong(10), annComm);
            AnnotationKeepDetails keepDetails = new AnnotationKeepDetails();

            // The original ampunt has annotated commodity, but "keepDetails" does not specify anything to keep.
            // Therefore, the new amount has not annotated commodity
            Amount newAmount = amount.StripAnnotations(keepDetails);

            Assert.IsFalse(newAmount.Commodity.IsAnnotated);
        }
Пример #20
0
        public void Balance_IsSingleAmount_IndicatesThatBalanceHasOneAmounts()
        {
            Balance balance = new Balance();

            Assert.IsFalse(balance.IsSingleAmount);

            balance.Add(new Amount(1));
            Assert.IsTrue(balance.IsSingleAmount);

            Commodity comm = new Commodity(CommodityPool.Current, new CommodityBase("comm"));

            balance.Add(new Amount(BigInt.FromLong(1), comm));
            Assert.IsFalse(balance.IsSingleAmount);
        }
Пример #21
0
        public void Commodity_CompareByCommodity_ChecksWhetherCommoditiesAreAnnotated()
        {
            Commodity          commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("comm1"));
            AnnotatedCommodity annComm1   = new AnnotatedCommodity(commodity1, new Annotation());
            Commodity          commodity2 = new Commodity(CommodityPool.Current, new CommodityBase("comm1"));

            Amount amount1 = new Amount(BigInt.FromLong(0), commodity1);
            Amount amount2 = new Amount(BigInt.FromLong(0), annComm1);
            Amount amount3 = new Amount(BigInt.FromLong(0), commodity2);

            Assert.IsTrue(Commodity.CompareByCommodity(amount1, amount2));
            Assert.IsFalse(Commodity.CompareByCommodity(amount1, amount3));

            Assert.IsFalse(Commodity.CompareByCommodity(amount2, amount1));
        }
Пример #22
0
        public void Commodity_CompareByCommodityComparison_ReturnsZeroForEqualAmounts()
        {
            CommodityBase commBase1  = new CommodityBase("comm1");
            CommodityBase commBase2  = new CommodityBase("comm2");
            Commodity     commodity1 = new Commodity(CommodityPool.Current, commBase1);
            Commodity     commodity2 = new Commodity(CommodityPool.Current, commBase2);

            Amount amt1  = new Amount(BigInt.FromLong(10), commodity1);
            Amount amt1a = new Amount(BigInt.FromLong(10), commodity1);
            Amount amt2  = new Amount(BigInt.FromLong(10), commodity2);

            Assert.AreEqual(0, Commodity.CompareByCommodityComparison(amt1, amt1a));
            Assert.AreEqual(-1, Commodity.CompareByCommodityComparison(amt1, amt2));
            Assert.AreEqual(1, Commodity.CompareByCommodityComparison(amt2, amt1));
        }
Пример #23
0
        public void Commodity_CompareByCommodity_ComparesDates()
        {
            Commodity          commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("comm1"));
            AnnotatedCommodity annComm1   = new AnnotatedCommodity(commodity1, new Annotation());
            Commodity          commodity2 = new Commodity(CommodityPool.Current, new CommodityBase("comm1"));
            AnnotatedCommodity annComm2   = new AnnotatedCommodity(commodity2, new Annotation());

            Amount amount1 = new Amount(BigInt.FromLong(0), annComm1);
            Amount amount2 = new Amount(BigInt.FromLong(0), annComm2);

            annComm1.Details.Date = (Date)DateTime.UtcNow.Date;
            Assert.IsFalse(Commodity.CompareByCommodity(amount1, amount2));
            Assert.IsTrue(Commodity.CompareByCommodity(amount2, amount1));

            annComm1.Details.Date = (Date)DateTime.UtcNow.Date;
            annComm2.Details.Date = (Date)DateTime.UtcNow.Date.AddDays(1);
            Assert.IsTrue(Commodity.CompareByCommodity(amount1, amount2));
            Assert.IsFalse(Commodity.CompareByCommodity(amount2, amount1));
        }
Пример #24
0
        public void Commodity_CompareByCommodity_ComparesTags()
        {
            Commodity          commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("comm1"));
            AnnotatedCommodity annComm1   = new AnnotatedCommodity(commodity1, new Annotation());
            Commodity          commodity2 = new Commodity(CommodityPool.Current, new CommodityBase("comm1"));
            AnnotatedCommodity annComm2   = new AnnotatedCommodity(commodity2, new Annotation());

            Amount amount1 = new Amount(BigInt.FromLong(0), annComm1);
            Amount amount2 = new Amount(BigInt.FromLong(0), annComm2);

            annComm1.Details.Tag = "tag-1";
            Assert.IsFalse(Commodity.CompareByCommodity(amount1, amount2));
            Assert.IsTrue(Commodity.CompareByCommodity(amount2, amount1));

            annComm1.Details.Tag = "tag-1";
            annComm2.Details.Tag = "tag-2";
            Assert.IsTrue(Commodity.CompareByCommodity(amount1, amount2));
            Assert.IsFalse(Commodity.CompareByCommodity(amount2, amount1));
        }
Пример #25
0
        public void AnonymizePosts_RenderCommodity_HidesCommodityName()
        {
            string    commodityName1 = "comm-name-1";
            string    commodityName2 = "comm-name-2";
            Commodity commodity1     = CommodityPool.Current.FindOrCreate(commodityName1);
            Commodity commodity2     = CommodityPool.Current.FindOrCreate(commodityName2);
            Amount    amount1        = new Amount(BigInt.FromLong(10), commodity1);
            Amount    amount2        = new Amount(BigInt.FromLong(10), commodity2);

            AnonymizePosts anonymizePosts = new AnonymizePosts(null);

            anonymizePosts.RenderCommodity(amount1);
            anonymizePosts.RenderCommodity(amount2);

            Assert.AreEqual("A", amount1.Commodity.Symbol);
            Assert.AreEqual("B", amount2.Commodity.Symbol);

            Assert.AreEqual(commodityName1, anonymizePosts.CommodityIndexMap.Keys.First().BaseSymbol);
            Assert.AreEqual(commodityName2, anonymizePosts.CommodityIndexMap.Keys.Last().BaseSymbol);
        }
Пример #26
0
 public void BigInt_Print_NoDigitSeparatorsIfCommodityIsNull()
 {
     Assert.AreEqual("1000", BigInt.FromLong(1000).Print(0, 2));
 }
Пример #27
0
        public void BigInt_Print_DefaultDecimalMarkIsPoint()
        {
            BigInt bigInt1 = BigInt.FromLong(100);

            Assert.AreEqual("100.0", bigInt1.Print(1, 1));
        }
Пример #28
0
        public void BigInt_Print_DefaultDigitSeparatorIsComma()
        {
            BigInt bigInt1 = BigInt.FromLong(1000);

            Assert.AreEqual("1000", bigInt1.Print(0));
        }