public void BigInt_Compare_ReturnsZeroIfValuesAreEqual() { BigInt bigInt1 = BigInt.FromLong(10); BigInt bigInt2 = BigInt.FromLong(10); Assert.AreEqual(0, bigInt1.Compare(bigInt2)); }
public void BigInt_Compare_ReturnsMinusOneIfParamIsGreater() { BigInt bigInt1 = BigInt.FromLong(5); BigInt bigInt2 = BigInt.FromLong(10); Assert.Equal(-1, bigInt1.Compare(bigInt2)); }
public void BigInt_Compare_ReturnsZeroOrMinusOneIfGivenBigIntIsEmpty() { BigInt bigInt = new BigInt(); Assert.AreEqual(-1, bigInt.Compare(BigInt.FromLong(0))); Assert.AreEqual(0, bigInt.Compare(bigInt)); }
public void BigInt_Compare_ReturnsOneIfParamIsEmpty() { BigInt bigInt1 = BigInt.FromLong(10); BigInt bigInt2 = new BigInt(); Assert.AreEqual(1, bigInt1.Compare(bigInt2)); }
public void BigInt_Compare_ReturnsMinusOneIfParamIsLess() { BigInt bigInt1 = BigInt.FromLong(50); BigInt bigInt2 = BigInt.FromLong(10); Assert.AreEqual(1, bigInt1.Compare(bigInt2)); }
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)); }
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()); }
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()); }
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()); }
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)); }
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)); }
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()); }
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))); }
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); }
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)); }
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)); }
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); }
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)); }
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); }
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); }
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)); }
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)); }
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)); }
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)); }
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); }
public void BigInt_Print_NoDigitSeparatorsIfCommodityIsNull() { Assert.AreEqual("1000", BigInt.FromLong(1000).Print(0, 2)); }
public void BigInt_Print_DefaultDecimalMarkIsPoint() { BigInt bigInt1 = BigInt.FromLong(100); Assert.AreEqual("100.0", bigInt1.Print(1, 1)); }
public void BigInt_Print_DefaultDigitSeparatorIsComma() { BigInt bigInt1 = BigInt.FromLong(1000); Assert.AreEqual("1000", bigInt1.Print(0)); }