Exemple #1
0
        public void AutoTestCase_Value_TestEquality()
        {
            DateTime localtime = new DateTime(2010, 2, 10);
            var      s1        = new List <Value>();

            Value v1  = new Value();
            Value v2  = new Value(true);
            Value v3  = new Value(localtime);
            Value v4  = new Value(TimesCommon.Current.ParseDate("2014/08/14"));
            Value v5  = new Value(2L);
            Value v6  = new Value((long)2UL);
            Value v7  = new Value(1.00);
            Value v8  = new Value(new Amount("4 GBP"));
            Value v9  = new Value(new Balance("4 GBP"));
            Value v10 = new Value(new Mask("regex"));
            Value v11 = new Value(s1);
            Value v12 = new Value("$1");
            Value v13 = new Value("2 CAD");
            Value v14 = new Value("comment", true);
            Value v15 = new Value("comment", true);

            Assert.AreEqual(v1, new Value());
            Assert.AreEqual(v2, new Value(true));
            Assert.AreEqual(v3, new Value(localtime));
            Assert.IsTrue(!(v4 == new Value(TimesCommon.Current.ParseDate("2014/08/15"))));

            Value v19 = new Value(new Amount("2"));
            Value v20 = new Value(new Balance("2"));

            Assert.AreEqual(v5, v6);
            Assert.AreEqual(v5, v19);
            Assert.AreEqual(v5, v20);
            Assert.IsTrue(v19 == v5);
            Assert.IsTrue(v19 == v20);
            Assert.IsTrue(v19 == new Value(new Amount("2")));
            Assert.IsTrue(v20 == v5);
            Assert.IsTrue(v20 == v19);
            Assert.IsTrue(v20 == new Value(new Balance(2L)));
            Assert.IsTrue(v14 == v15);
            Assert.IsTrue(v10 == new Value(new Mask("regex")));
            Assert.IsTrue(v11 == new Value(s1));

            Boost.CheckThrow <ValueError, bool>(() => v8 == v10);

            Assert.IsTrue(v1.IsValid);
            Assert.IsTrue(v2.IsValid);
            Assert.IsTrue(v3.IsValid);
            Assert.IsTrue(v4.IsValid);
            Assert.IsTrue(v5.IsValid);
            Assert.IsTrue(v6.IsValid);
            Assert.IsTrue(v7.IsValid);
            Assert.IsTrue(v8.IsValid);
            Assert.IsTrue(v9.IsValid);
            Assert.IsTrue(v10.IsValid);
            Assert.IsTrue(v11.IsValid);
            Assert.IsTrue(v12.IsValid);
            Assert.IsTrue(v13.IsValid);
            Assert.IsTrue(v14.IsValid);
            Assert.IsTrue(v15.IsValid);
            Assert.IsTrue(v19.IsValid);
            Assert.IsTrue(v20.IsValid);
        }
Exemple #2
0
        public void AutoTestCase_Value_TestAddition()
        {
            DateTime localtime = new DateTime(2010, 2, 10);
            var      s1        = new List <Value>();

            Value v1  = new Value();
            Value v2  = new Value(true);
            Value v3  = new Value(localtime);
            Value v4  = new Value(TimesCommon.Current.ParseDate("2014/08/14"));
            Value v5  = new Value(2L);
            Value v6  = new Value((long)2UL);
            Value v7  = new Value(1.00);
            Value v8  = new Value(new Amount("4 GBP"));
            Value v9  = new Value(new Balance("4 GBP"));
            Value v10 = new Value(new Mask("regex"));
            Value v11 = new Value(s1);
            Value v12 = new Value("$1");
            Value v13 = new Value("2 CAD");
            Value v14 = new Value("comment", true);
            Value v15 = new Value("comment", true);
            Value v16 = new Value(new Amount("2"));

            v14 += v15;
            Assert.AreEqual(v14, new Value("commentcomment", true));
            v14 += v12;
            Assert.AreEqual(v14, new Value("commentcomment$1.00", true));

            Assert.AreEqual(v3, new Value(new DateTime(2010, 2, 10, 0, 0, 0)));
            v3 += new Value(2L);
            Assert.AreEqual(v3, new Value(new DateTime(2010, 2, 10, 0, 0, 2)));
            v3 += new Value(new Amount("2"));
            Assert.AreEqual(v3, new Value(new DateTime(2010, 2, 10, 0, 0, 4)));

            v4 += new Value(2L);
            Assert.AreEqual(v4, new Value(TimesCommon.Current.ParseDate("2014/08/16")));
            v4 += new Value(new Amount("2"));
            Assert.AreEqual(v4, new Value(TimesCommon.Current.ParseDate("2014/08/18")));

            v5 += new Value(2L);
            Assert.AreEqual(v5, new Value(4L));
            v5 += new Value(new Amount("2"));
            Assert.AreEqual(v5, new Value(new Amount("6")));
            v5 += v8;

            v16 += new Value(2L);
            v16 += new Value(new Amount("2"));
            v16 += v8;
            Assert.AreEqual(v5, v16);

            v8 += new Value("6");
            Assert.AreEqual(v8, v16);

            Value v17 = new Value(6L);

            v17 += new Value(new Amount("4 GBP"));
            Assert.AreEqual(v8, v17);

            Value v18 = new Value(6L);

            v18 += v9;
            Value v19 = new Value(new Amount("6"));

            v19 += v9;
            Assert.AreEqual(v18, v19);

            v9  += new Value(2L);
            v9  += new Value(new Amount("4"));
            v9  += v19;
            v18 += v19;
            Assert.AreEqual(v9, v18);

            Value v20 = new Value(s1);

            v11 += new Value(2L);
            v11 += new Value("4 GBP");
            Boost.CheckThrow <ValueError, Value>(() => v11 += v20);
            Boost.CheckThrow <ValueError, Value>(() => v10 += v8);

            v20 += new Value(2L);
            v20 += new Value("4 GBP");
            Assert.AreEqual(v11, v20);
            v11 += v20;
            v20 += v20;
            Assert.AreEqual(v11, v20);

            Assert.IsTrue(v1.IsValid);
            Assert.IsTrue(v2.IsValid);
            Assert.IsTrue(v3.IsValid);
            Assert.IsTrue(v4.IsValid);
            Assert.IsTrue(v5.IsValid);
            Assert.IsTrue(v6.IsValid);
            Assert.IsTrue(v7.IsValid);
            Assert.IsTrue(v8.IsValid);
            Assert.IsTrue(v9.IsValid);
            Assert.IsTrue(v10.IsValid);
            Assert.IsTrue(v11.IsValid);
            Assert.IsTrue(v12.IsValid);
            Assert.IsTrue(v13.IsValid);
            Assert.IsTrue(v14.IsValid);
            Assert.IsTrue(v15.IsValid);
            Assert.IsTrue(v16.IsValid);
            Assert.IsTrue(v17.IsValid);
            Assert.IsTrue(v18.IsValid);
            Assert.IsTrue(v19.IsValid);
            Assert.IsTrue(v20.IsValid);
        }
Exemple #3
0
        public void AutoTestCase_Commodity_TestPriceHistory()
        {
            DateTime jan17_05;
            DateTime jan17_06;
            DateTime jan17_07;
            DateTime feb27_07;
            DateTime feb28_07;
            DateTime feb28_07sbm;
            DateTime mar01_07;
            DateTime apr15_07;

            jan17_05    = TimesCommon.Current.ParseDateTime("2005/01/17 00:00:00");
            jan17_06    = TimesCommon.Current.ParseDateTime("2006/01/17 00:00:00");
            jan17_07    = TimesCommon.Current.ParseDateTime("2007/01/17 00:00:00");
            feb27_07    = TimesCommon.Current.ParseDateTime("2007/02/27 18:00:00");
            feb28_07    = TimesCommon.Current.ParseDateTime("2007/02/28 06:00:00");
            feb28_07sbm = TimesCommon.Current.ParseDateTime("2007/02/28 11:59:59");
            mar01_07    = TimesCommon.Current.ParseDateTime("2007/03/01 00:00:00");
            apr15_07    = TimesCommon.Current.ParseDateTime("2007/04/15 13:00:00");

            Amount x0 = new Amount();
            Amount x1 = new Amount("100.10 AAPL");

            Boost.CheckThrow <AmountError, Amount>(() => x0.Value());
            Assert.IsTrue(!(bool)x1.Value());

            // Commodities cannot be constructed by themselves, since a great deal
            // of their state depends on how they were seen to be used.
            Commodity aapl = x1.Commodity;

            aapl.AddPrice(jan17_07, new Amount("$10.20"));
            aapl.AddPrice(feb27_07, new Amount("$13.40"));
            aapl.AddPrice(feb28_07, new Amount("$18.33"));
            aapl.AddPrice(feb28_07sbm, new Amount("$18.30"));
            aapl.AddPrice(mar01_07, new Amount("$19.50"));
            aapl.AddPrice(apr15_07, new Amount("$21.22"));
            aapl.AddPrice(jan17_05, new Amount("EUR 23.00"));
            aapl.AddPrice(jan17_06, new Amount("CAD 25.00"));

            Amount    one_euro = new Amount("EUR 1.00");
            Commodity euro     = one_euro.Commodity;

            euro.AddPrice(feb27_07, new Amount("CAD 1.40"));
            euro.AddPrice(jan17_05, new Amount("$0.78"));

            Amount    one_cad = new Amount("CAD 1.00");
            Commodity cad     = one_cad.Commodity;

            cad.AddPrice(jan17_06, new Amount("$1.11"));

            Amount amt = x1.Value(feb28_07sbm);

            Assert.IsNotNull(amt);
            Assert.AreEqual(new Amount("$1831.83"), amt);

            amt = x1.Value(TimesCommon.Current.CurrentTime);
            Assert.IsNotNull(amt);
            Assert.AreEqual("$2124.12", amt.ToString());
            Assert.AreEqual("$2124.122", amt.ToFullString());

            amt = x1.Value(TimesCommon.Current.CurrentTime, euro);
            Assert.IsNotNull(amt);
            Assert.AreEqual("EUR 1787.50", amt.Rounded().ToString());

            // Add a newer Euro pricing
            aapl.AddPrice(jan17_07, new Amount("EUR 23.00"));

            amt = x1.Value(TimesCommon.Current.CurrentTime, euro);
            Assert.IsNotNull(amt);
            Assert.AreEqual("EUR 2302.30", amt.ToString());

            amt = x1.Value(TimesCommon.Current.CurrentTime, cad);
            Assert.IsNotNull(amt);
            Assert.AreEqual("CAD 3223.22", amt.ToString());

            Assert.IsTrue(x1.Valid());
        }