public void Tdate_AsOf_2() { Tdate td = new Tdate(); td.AddState(Time.DawnOf, Date(2011, 01, 01)); td.AddState(Time.DawnOf.AddYears(2), Date(2012, 01, 01)); Assert.AreEqual(Date(2011, 1, 1), td.AsOf(Time.DawnOf.AddYears(1)).Out); }
public void Tdate_Lean_1() { Tdate td = new Tdate(); td.AddState(Time.DawnOf, Date(2011, 01, 01)); td.AddState(Time.DawnOf.AddYears(2), Date(2011, 01, 01)); Assert.AreEqual(Date(2011, 1, 1), td.Lean.Out); }
public void Tdate_IsAfter_1() { Tdate td1 = new Tdate(2010, 1, 1); Tdate td2 = new Tdate(); td2.AddState(Time.DawnOf, Date(2009, 1, 1)); td2.AddState(Date(2000, 1, 1), Date(2011, 1, 1)); Tbool result = td1 > td2; Assert.AreEqual("{Dawn: true; 1/1/2000: false}", result.Out); }
public void Tdate_Equals_2() { Tdate td1 = new Tdate(2010, 5, 13); Tdate td2 = new Tdate(); td2.AddState(Time.DawnOf, Date(2011, 01, 01)); td2.AddState(Date(2000, 1, 1), Date(2010, 5, 13)); Tbool result = td1 != td2; Assert.AreEqual("{Dawn: true; 1/1/2000: false}", result.Out); }
public void Tdate_IsAtOrBefore_1() { Tdate td1 = new Tdate(2000, 1, 1); Tdate td2 = new Tdate(); td2.AddState(Time.DawnOf, Date(1999, 1, 1)); td2.AddState(Date(2000, 1, 1), Date(2000, 1, 1)); td2.AddState(Date(2001, 1, 1), Date(2008, 1, 1)); Tbool result = td2 <= td1; Assert.AreEqual("{Dawn: true; 1/1/2001: false}", result.Out); }
public void FT_ToDateTime_3() { Tdate t = new Tdate(Date(1000, 1, 1)); t.AddState(Date(1000, 1, 1), Date(2000, 1, 1)); Assert.AreEqual(null, t.ToNullDateTime); }
public void FT_AsOf_12() { // Tdate varies, but base Tvar is eternal, so .AsOf should return that eternal value Tbool t = new Tbool(true); Tdate time = new Tdate(Date(2000, 1, 1)); time.AddState(Date(2010, 1, 1), Date(2010, 1, 1)); Assert.AreEqual(true, t.AsOf(time).Out); }
/// <summary> /// Asserts a given fact (of the proper Tvar type) /// </summary> private static void AssertFact(Factoid f) { // Instantiate relevant Things Thing t1 = f.Arg1.ToString() != "" ? Facts.AddThing(f.Arg1.ToString()) : null; Thing t2 = f.Arg2.ToString() != "" ? Facts.AddThing(f.Arg2.ToString()) : null; Thing t3 = f.Arg3.ToString() != "" ? Facts.AddThing(f.Arg3.ToString()) : null; // Sometimes I have my doubts about static typing... if (f.FactType == "Tbool") { Tbool val = new Tbool(); foreach (TemporalValue v in f.Timeline) { val.AddState(v.Date, new Hval(v.Value)); } Facts.Assert(t1, f.Relationship, t2, t3, val); } else if (f.FactType == "Tnum") { Tnum val = new Tnum(); foreach (TemporalValue v in f.Timeline) { val.AddState(v.Date, new Hval(v.Value)); } Facts.Assert(t1, f.Relationship, t2, t3, val); } else if (f.FactType == "Tstr") { Tstr val = new Tstr(); foreach (TemporalValue v in f.Timeline) { val.AddState(v.Date, new Hval(v.Value)); } Facts.Assert(t1, f.Relationship, t2, t3, val); } else if (f.FactType == "Tdate") { Tdate val = new Tdate(); foreach (TemporalValue v in f.Timeline) { val.AddState(v.Date, new Hval(v.Value)); } Facts.Assert(t1, f.Relationship, t2, t3, val); } else if (f.FactType == "Tset") { Tset val = new Tset(); foreach (TemporalValue v in f.Timeline) { val.AddState(v.Date, new Hval(v.Value)); } Facts.Assert(t1, f.Relationship, t2, t3, val); } }
public void FT_AsOf_14() { // Both Tdate and Tvar vary Tbool t = new Tbool(true); t.AddState(Date(2000, 1, 1), false); // When Tdate varies, the FirstValue is used... Tdate time = new Tdate(Date(1999, 1, 1)); time.AddState(Date(2010, 1, 1), Date(2010, 1, 1)); Assert.AreEqual(true, t.AsOf(time).Out); }
/// <summary> /// Creates a Tdate from a string representing a time-varying value. /// </summary> /// <remarks> /// Sample input: {2012-01-01: 2012-12-31; Time.DawnOf: 2000-12-31} /// </remarks> private static Tdate TdateFromTemporalString(string val) { if (val.StartsWith("{")) { Tdate result = new Tdate(); foreach (string s in TimeValuePairs(val)) { string[] parts = s.Split(new char[] { ':' }); DateTime datePart = Convert.ToDateTime(parts[0].Trim().Replace("Dawn", "1800-01-01")); DateTime valPart = Convert.ToDateTime(parts[1].Trim()); result.AddState(datePart, valPart); } return(result); } return(new Tdate(val)); }
public void Tdate_AsOf_2() { Tdate td = new Tdate(); td.AddState(Time.DawnOf, Date(2011,01,01)); td.AddState(Time.DawnOf.AddYears(2), Date(2012,01,01)); Assert.AreEqual(Date(2011,1,1), td.AsOf(Time.DawnOf.AddYears(1)).Out); }
public void FT_AsOf_14() { // Both Tdate and Tvar vary Tbool t = new Tbool(true); t.AddState(Date(2000,1,1),false); // When Tdate varies, the FirstValue is used... Tdate time = new Tdate(Date(1999,1,1)); time.AddState(Date(2010,1,1),Date(2010,1,1)); Assert.AreEqual(true, t.AsOf(time).Out); }
public void Tdate_IsAtOrBefore_1() { Tdate td1 = new Tdate(2000,1,1); Tdate td2 = new Tdate(); td2.AddState(Time.DawnOf, Date(1999,1,1)); td2.AddState(Date(2000,1,1), Date(2000,1,1)); td2.AddState(Date(2001,1,1), Date(2008,1,1)); Tbool result = td2 <= td1; Assert.AreEqual("{Dawn: true; 1/1/2001: false}", result.Out); }
public void Tdate_Equals_2() { Tdate td1 = new Tdate(2010,5,13); Tdate td2 = new Tdate(); td2.AddState(Time.DawnOf, Date(2011,01,01)); td2.AddState(Date(2000,1,1), Date(2010,5,13)); Tbool result = td1 != td2; Assert.AreEqual("{Dawn: true; 1/1/2000: false}", result.Out); }
public void FT_ToDateTime_3() { Tdate t = new Tdate(Date(1000,1,1)); t.AddState(Date(1000,1,1), Date(2000,1,1)); Assert.AreEqual(null, t.ToNullDateTime); }
public void Tdate_IsBefore_1() { Tdate td1 = new Tdate(2010,1,1); Tdate td2 = new Tdate(); td2.AddState(Time.DawnOf, Date(2009,1,1)); td2.AddState(Date(2000,1,1), Date(2011,1,1)); Tbool result = td1 < td2; Assert.AreEqual("{Dawn: false; 1/1/2000: true}", result.Out); }
public void Tdate_Lean_1() { Tdate td = new Tdate(); td.AddState(Time.DawnOf, Date(2011,01,01)); td.AddState(Time.DawnOf.AddYears(2), Date(2011,01,01)); Assert.AreEqual(Date(2011,1,1), td.Lean.Out); }
/// <summary> /// Creates a Tdate from a string representing a time-varying value. /// </summary> /// <remarks> /// Sample input: {2012-01-01: 2012-12-31; Time.DawnOf: 2000-12-31} /// </remarks> private static Tdate TdateFromTemporalString(string val) { if (val.StartsWith("{")) { Tdate result = new Tdate(); foreach (string s in TimeValuePairs(val)) { string[] parts = s.Split(new char[] {':'}); DateTime datePart = Convert.ToDateTime(parts[0].Trim().Replace("Dawn","1800-01-01")); DateTime valPart = Convert.ToDateTime(parts[1].Trim()); result.AddState(datePart, valPart); } return result; } return new Tdate(val); }
public void FT_AsOf_12() { // Tdate varies, but base Tvar is eternal, so .AsOf should return that eternal value Tbool t = new Tbool(true); Tdate time = new Tdate(Date(2000,1,1)); time.AddState(Date(2010,1,1),Date(2010,1,1)); Assert.AreEqual(true, t.AsOf(time).Out); }