Exemplo n.º 1
0
 public void BigInt_Negative_ReturnsNegaitveValue()
 {
     Assert.AreEqual(BigInt.FromInt(0), BigInt.Zero.Negative());
     Assert.AreEqual(BigInt.FromInt(-1), BigInt.One.Negative());
     Assert.AreEqual(BigInt.FromInt(-10), BigInt.FromInt(10).Negative());
     Assert.AreEqual(BigInt.FromInt(10), BigInt.FromInt(-10).Negative());
 }
Exemplo n.º 2
0
        public void BigInt_MultiplicityOperator_ReturnsMultiplicideValue()
        {
            BigInt result = BigInt.FromInt(10) * BigInt.FromInt(5);

            Assert.IsTrue(result.HasValue);
            Assert.AreEqual(50, result.ToLong());
        }
Exemplo n.º 3
0
        public void Amount_HasAnnotation_ReturnsFalseIfCommodityIsNotAnnotated()
        {
            Commodity comm   = new Commodity(CommodityPool.Current, new CommodityBase("comm"));
            Amount    amount = new Amount(BigInt.FromInt(1), comm);

            Assert.IsFalse(amount.HasAnnotation);
        }
Exemplo n.º 4
0
        public void Session_FnLotDate_ReturnsDateFromFirstArgAmount()
        {
            Session session = new Session();

            Amount    amount1 = new Amount(0); // No date
            CallScope scope1  = new CallScope(new EmptyScope());

            //scope1.PushBack(Value.Get(false));  // first argument
            scope1.PushBack(Value.Get(amount1));
            Assert.AreEqual(Value.Empty, session.FnLotDate(scope1));

            Commodity  commodity  = new Commodity(CommodityPool.Current, new CommodityBase("base"));
            Date       date       = (Date)DateTime.Now.Date;
            Annotation annotation = new Annotation()
            {
                Date = date
            };
            AnnotatedCommodity annotatedCommodity = new AnnotatedCommodity(commodity, annotation);
            Amount             amount2            = new Amount(BigInt.FromInt(10), annotatedCommodity); // With date
            CallScope          scope2             = new CallScope(new EmptyScope());

            //scope2.PushBack(Value.Get(false));  // first argument
            scope2.PushBack(Value.Get(amount2));
            Assert.AreEqual(date, session.FnLotDate(scope2).AsDate);
        }
Exemplo n.º 5
0
        public void Amount_Annotate_DoesNothingIfNoCOmmodity()
        {
            Amount amount1 = new Amount(BigInt.FromInt(10), null);

            amount1.Annotate(new Annotation());
            Assert.IsFalse(amount1.HasAnnotation);
        }
Exemplo n.º 6
0
 public void BigInt_Abs_ReturnsAbsoluteValue()
 {
     Assert.AreEqual(BigInt.FromInt(0), BigInt.Zero.Abs());
     Assert.AreEqual(BigInt.FromInt(1), BigInt.One.Abs());
     Assert.AreEqual(BigInt.FromInt(10), BigInt.FromInt(10).Abs());
     Assert.AreEqual(BigInt.FromInt(10), BigInt.FromInt(-10).Abs());
 }
Exemplo n.º 7
0
        public void Balance_Constructor_ClonesAmounts()
        {
            Commodity commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("base-1"));
            Commodity commodity2 = new Commodity(CommodityPool.Current, new CommodityBase("base-2"));

            Amount amount1 = new Amount(BigInt.FromInt(200), commodity1);
            Amount amount2 = new Amount(BigInt.FromInt(300), commodity2);

            Balance balance = new Balance();

            balance.Add(amount1);
            balance.Add(amount2);

            Balance clonedBalance = new Balance(balance);

            clonedBalance.Amounts.ElementAt(0).Value.Multiply(new Amount(5));
            clonedBalance.Amounts.ElementAt(1).Value.Multiply(new Amount(7));

            Assert.AreEqual(2, clonedBalance.Amounts.Count());
            Assert.AreEqual(1000, clonedBalance.Amounts.ElementAt(0).Value.Quantity.ToLong());
            Assert.AreEqual(2100, clonedBalance.Amounts.ElementAt(1).Value.Quantity.ToLong());

            Assert.AreEqual(2, balance.Amounts.Count());
            Assert.AreEqual(200, balance.Amounts.ElementAt(0).Value.Quantity.ToLong());
            Assert.AreEqual(300, balance.Amounts.ElementAt(1).Value.Quantity.ToLong());
        }
Exemplo n.º 8
0
        public void Session_FnLotTag_ReturnsDateFromFirstArgAmouunt()
        {
            Session session = new Session();

            Amount    amount1 = new Amount(0); // No tag
            CallScope scope1  = new CallScope(new EmptyScope());

            //scope1.PushBack(Value.Get(false));  // first argument
            scope1.PushBack(Value.Get(amount1));
            Assert.AreEqual(Value.Empty, session.FnLotTag(scope1));

            Commodity  commodity  = new Commodity(CommodityPool.Current, new CommodityBase("base"));
            string     tag        = "my-tag";
            Annotation annotation = new Annotation()
            {
                Tag = tag
            };
            AnnotatedCommodity annotatedCommodity = new AnnotatedCommodity(commodity, annotation);
            Amount             amount2            = new Amount(BigInt.FromInt(10), annotatedCommodity); // With date
            CallScope          scope2             = new CallScope(new EmptyScope());

            //scope2.PushBack(Value.Get(false));  // first argument
            scope2.PushBack(Value.Get(amount2));
            Assert.AreEqual(tag, session.FnLotTag(scope2).AsString);
        }
Exemplo n.º 9
0
        public void BigInt_SubtractOperator_ReturnsSubtractedValue()
        {
            BigInt result = BigInt.FromInt(10) - BigInt.FromInt(7);

            Assert.IsTrue(result.HasValue);
            Assert.AreEqual(3, result.ToLong());
        }
Exemplo n.º 10
0
        public void Amount_Subtract_NullAmountCausesException()
        {
            Commodity commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("base-1"));
            Amount    amount1    = new Amount(BigInt.FromInt(10), commodity1);

            amount1.InPlaceSubtract(null);
        }
Exemplo n.º 11
0
        public void Balance_Subtract_Balance_SubtractsAllAmounts()
        {
            Commodity commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("base-1"));
            Commodity commodity2 = new Commodity(CommodityPool.Current, new CommodityBase("base-2"));

            // First balance

            Amount amount1 = new Amount(BigInt.FromInt(200), commodity1);
            Amount amount2 = new Amount(BigInt.FromInt(300), commodity2);

            Balance balance1 = new Balance();

            balance1.Add(amount1);
            balance1.Add(amount2);

            // Second balance

            Amount amount3 = new Amount(BigInt.FromInt(50), commodity1);
            Amount amount4 = new Amount(BigInt.FromInt(70), commodity2);

            Balance balance2 = new Balance();

            balance2.Add(amount3);
            balance2.Add(amount4);

            // Action

            balance1.Subtract(balance2);

            // Assert

            Assert.AreEqual(2, balance1.Amounts.Count());
            Assert.AreEqual(150, balance1.Amounts.ElementAt(0).Value.Quantity.ToLong());
            Assert.AreEqual(230, balance1.Amounts.ElementAt(1).Value.Quantity.ToLong());
        }
Exemplo n.º 12
0
        public void BigInt_DivisionOperator_ReturnsDividedValue()
        {
            BigInt result = BigInt.FromInt(10) / BigInt.FromInt(5);

            Assert.IsTrue(result.HasValue);
            Assert.AreEqual(2, result.ToLong());
        }
Exemplo n.º 13
0
        public void Amount_Parse_Integration()
        {
            Amount amount1 = new Amount(default(BigInt), null);
            string line1   = "-10 USD";

            amount1.Parse(ref line1, AmountParseFlagsEnum.PARSE_DEFAULT);
            Assert.AreEqual(BigInt.FromInt(-10), amount1.Quantity);
            Assert.AreEqual("USD", amount1.Commodity.BaseSymbol);
            Assert.AreEqual(String.Empty, line1);

            Amount amount2 = new Amount(default(BigInt), null);
            string line2   = "99 USD";

            amount2.Parse(ref line2, AmountParseFlagsEnum.PARSE_DEFAULT);
            Assert.AreEqual(BigInt.FromInt(99), amount2.Quantity);
            Assert.AreEqual("USD", amount2.Commodity.BaseSymbol);
            Assert.AreEqual(String.Empty, line2);

            Amount amount3 = new Amount(default(BigInt), null);
            string line3   = "STS 99.99";

            amount3.Parse(ref line3, AmountParseFlagsEnum.PARSE_DEFAULT);
            Assert.AreEqual(BigInt.Parse("99.99", 2), amount3.Quantity);  // Precision = 2
            Assert.AreEqual("STS", amount3.Commodity.BaseSymbol);
            Assert.AreEqual(String.Empty, line3);
        }
Exemplo n.º 14
0
        public void Amount_HasAnnotation_FailsIfAnnotatedCommodityHasNoDetails()
        {
            Commodity          comm    = new Commodity(CommodityPool.Current, new CommodityBase("comm"));
            AnnotatedCommodity annComm = new AnnotatedCommodity(comm, null);  /* not sure it is a valid case. TBD */
            Amount             amount  = new Amount(BigInt.FromInt(1), annComm);

            Assert.IsTrue(amount.HasAnnotation);
        }
Exemplo n.º 15
0
        public void Amount_HasAnnotation_ReturnsTrueIfCommodityIsAnnotated()
        {
            Commodity          comm    = new Commodity(CommodityPool.Current, new CommodityBase("comm"));
            AnnotatedCommodity annComm = new AnnotatedCommodity(comm, new Annotation());
            Amount             amount  = new Amount(BigInt.FromInt(1), annComm);

            Assert.IsTrue(amount.HasAnnotation);
        }
Exemplo n.º 16
0
        public void Amount_HasCommodity_ChecksNullCommodity()
        {
            BigInt bigInt  = BigInt.FromInt(10, 2);
            Amount amountA = new Amount(bigInt, null);

            Assert.IsFalse(amountA.HasCommodity);
            Assert.AreEqual(CommodityPool.Current.NullCommodity, amountA.Commodity);
        }
Exemplo n.º 17
0
        public void BigInt_HasValue_ReflectsWhetherValueIsPopulated()
        {
            BigInt uninitialized = default(BigInt);

            Assert.IsFalse(uninitialized.HasValue);

            uninitialized = BigInt.FromInt(10);
            Assert.IsTrue(uninitialized.HasValue);
        }
Exemplo n.º 18
0
        public void Amount_ClearCommodity_ClearsCommodity()
        {
            Commodity commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("base-1"));
            Amount    amount1    = new Amount(BigInt.FromInt(10), commodity1);

            Assert.IsNotNull(amount1.Commodity);
            amount1.ClearCommodity();
            Assert.AreEqual(CommodityPool.Current.NullCommodity, amount1.Commodity);
        }
Exemplo n.º 19
0
        public void Amount_Subtract_InvalidAmountCausesException()
        {
            Commodity commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("base-1"));
            Amount    amount1    = new Amount(BigInt.FromInt(10), commodity1);
            Amount    amount2    = new Amount(new BigInt(), commodity1);

            Assert.IsFalse(amount2.Valid());
            amount1.InPlaceSubtract(amount2);
        }
Exemplo n.º 20
0
        public void Amount_Compare_FailsIfCommoditiesAreDifferent()
        {
            Commodity commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("base-1"));
            Commodity commodity2 = new Commodity(CommodityPool.Current, new CommodityBase("base-2"));
            Amount    amount1    = new Amount(BigInt.FromInt(10), commodity1);
            Amount    amount2    = new Amount(BigInt.FromInt(12), commodity2);

            amount1.Compare(amount2);
        }
Exemplo n.º 21
0
        public void Amount_Subtract_ChecksThatBothCommoditiesAreEqual()
        {
            Commodity commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("base-1"));
            Commodity commodity2 = new Commodity(CommodityPool.Current, new CommodityBase("base-2"));
            Amount    amount1    = new Amount(BigInt.FromInt(10), commodity1);
            Amount    amount2    = new Amount(BigInt.FromInt(20), commodity2);

            amount1.InPlaceSubtract(amount2);
        }
Exemplo n.º 22
0
        public void Amount_Print_DoesNotAddSuffixSpaceInCaseCommodityStyleSeparatedNotSpecified()
        {
            Commodity commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("TKP1"));

            commodity1.Flags |= CommodityFlagsEnum.COMMODITY_STYLE_SUFFIXED;
            Amount amount1 = new Amount(BigInt.FromInt(10), commodity1);

            Assert.AreEqual("10TKP1", amount1.Print());
        }
Exemplo n.º 23
0
        public void Amount_StripAnnotation_HoldsKeepPrecisionFlag()
        {
            Commodity commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("AAHKPF1"));
            Amount    amt1       = new Amount(BigInt.FromInt(10).SetKeepPrecision(true), null);

            Amount result = amt1.StripAnnotations(new AnnotationKeepDetails());

            Assert.IsTrue(result.KeepPrecision);
        }
Exemplo n.º 24
0
        public void Amount_Negated_HoldsKeepPrecisionFlag()
        {
            Commodity commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("AAHKPF1"));
            Amount    amt1       = new Amount(BigInt.FromInt(10).SetKeepPrecision(true), null);

            Amount result = amt1.Negated();

            Assert.IsTrue(result.KeepPrecision);
        }
Exemplo n.º 25
0
        public void Amount_InPlaceInvert_InvertsItself()
        {
            BigInt bigInt  = BigInt.FromInt(10, 2);
            Amount amountA = new Amount(bigInt, null);

            amountA.InPlaceInvert();

            Assert.AreEqual("0.1", amountA.ToString());
        }
Exemplo n.º 26
0
        public void Amount_Print_AddsSuffixSpaceInCaseCommodityStyleSeparatedSpecified()
        {
            Commodity commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("TKP1"));

            commodity1.Flags |= CommodityFlagsEnum.COMMODITY_STYLE_SUFFIXED | CommodityFlagsEnum.COMMODITY_STYLE_SEPARATED; /* COMMODITY_STYLE_SEPARATED is added */
            Amount amount1 = new Amount(BigInt.FromInt(10), commodity1);

            Assert.AreEqual("10 TKP1", amount1.Print()); /* Space between the number and commodity */
        }
Exemplo n.º 27
0
        public void Amount_Inverted_ReturnsNewInvertedAmount()
        {
            BigInt bigInt  = BigInt.FromInt(10, 2);
            Amount amountA = new Amount(bigInt, null);

            Amount amountB = amountA.Inverted();

            Assert.AreEqual("10", amountA.ToString());
            Assert.AreEqual("0.1", amountB.ToString());
        }
Exemplo n.º 28
0
        public void Amount_Subtract_HoldsKeepPrecisionFlag()
        {
            Commodity commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("AAHKPF1"));
            Amount    amt1       = new Amount(BigInt.FromInt(10).SetKeepPrecision(true), null);
            Amount    amt2       = new Amount(BigInt.FromInt(5), commodity1);

            Amount result = amt1.InPlaceSubtract(amt2);

            Assert.IsTrue(result.KeepPrecision);
        }
Exemplo n.º 29
0
        public void Amount_Compare_ReturnsMinusOneOrZeroOrOne()
        {
            Commodity commodity1 = new Commodity(CommodityPool.Current, new CommodityBase("base-1"));
            Amount    amount1    = new Amount(BigInt.FromInt(10), commodity1);
            Amount    amount2    = new Amount(BigInt.FromInt(12), commodity1);

            Assert.AreEqual(-1, amount1.Compare(amount2));
            Assert.AreEqual(0, amount1.Compare(amount1));
            Assert.AreEqual(1, amount2.Compare(amount1));
        }
Exemplo n.º 30
0
        public void BigInt_SetPrecision_ChangesPrecision()
        {
            BigInt value = BigInt.FromInt(10, 20);

            Assert.AreEqual(20, value.Precision);
            BigInt value1 = value.SetPrecision(30);

            Assert.AreEqual(20, value.Precision); // Note that the original instance is not changed
            Assert.AreEqual(30, value1.Precision);
        }