[Test] public void test_has_class_value_on_extendable() { var rows = new [] { new TestingRow5 { CLASS = 1.0, ATT_1 = "1" }, new TestingRow5 { CLASS = 33.0, ATT_1 = "2" }, new TestingRow5 { CLASS = 22.0, ATT_1 = "3" } }; var extendable = rows.Select(r => ExtendableObj.Create(r).AddNominal("added", "yes")); var instances = new InstancesBuilder <ExtendableObj <TestingRow5> >(extendable.ToArray(), 0).Build(); Assert.AreEqual(4, instances.numAttributes()); Assert.AreEqual(3, instances.numInstances()); CollectionAssert.AreEqual( new [] { 1.0, 33.0, 22.0 }, instances.GetAttrDoubles(0), "Actual: " + String.Join(", ", instances.GetAttrDoubles(0))); CollectionAssert.AreEqual( new [] { "1", "2", "3" }, instances.GetAttrStrings(1), "Actual: " + String.Join(", ", instances.GetAttrStrings(1))); CollectionAssert.AreEqual( new [] { "yes", "yes", "yes" }, instances.GetAttrStrings(2), "Actual: " + String.Join(", ", instances.GetAttrStrings(2))); }
public void externdable_with_some_extended() { ExtendableObj <ExtendableInner> o = ExtendableObj.Create(new ExtendableInner()). AddBinary("nom1", true). AddDate("date1", DateTime.Now). AddNominal("nom2", "a"). AddNumerical("num1", 1). AddString("str1", "val"); List <PmlAttribute> atts = Build(new[] { o }); // NOTE: The order below is actually fixed, that // is: binary, date, nom, num, str. Assert.AreEqual(6, atts.Count); Assert.IsTrue(atts[0].IsNominal); Assert.AreEqual(0, atts[0].IndexOfValue(StringSplitOptions.None.ToString())); Assert.AreEqual(1, atts[0].IndexOfValue(StringSplitOptions.RemoveEmptyEntries.ToString())); Assert.IsTrue(atts[1].IsNominal); Assert.AreEqual(0, atts[1].IndexOfValue("0")); Assert.AreEqual(1, atts[1].IndexOfValue("1")); Assert.IsTrue(atts[2].IsDate); Assert.IsTrue(atts[3].IsNominal); Assert.AreEqual(0, atts[3].IndexOfValue("a")); Assert.IsTrue(atts[4].IsNumeric); Assert.IsTrue(atts[5].IsString); }
public void externdable_with_no_additionals() { List <PmlAttribute> atts = Build(new[] { ExtendableObj.Create(new ExtendableInner()) }); Assert.AreEqual(1, atts.Count); Assert.IsTrue(atts[0].IsNominal); Assert.AreEqual(0, atts[0].IndexOfValue(StringSplitOptions.None.ToString())); Assert.AreEqual(1, atts[0].IndexOfValue(StringSplitOptions.RemoveEmptyEntries.ToString())); }
[Test] public void test_get_value_on_extendable_objects() { var ex = ExtendableObj.Create(new SimpleObj { p = "p1" }); ex.AddString("p2", "v2"); Assert.AreEqual("p1", Helpers.GetValue <string>(ex, "p")); Assert.AreEqual("p1", Helpers.GetValue(ex, "p")); Assert.AreEqual("v2", Helpers.GetValue <string>(ex, "p2")); Assert.AreEqual("v2", Helpers.GetValue(ex, "p2")); }
[Test] public void test_cloning_on_extendables_with_simple_base() { var s = new SimpleObj { p = "v" }; var ex = ExtendableObj.Create(s); ex.AddString("p2", "v2"); var cloned = Helpers.Clone(ex); Assert.AreNotEqual(ex, cloned); Assert.AreEqual(ex.GetValue("p"), cloned.GetValue("p")); Assert.AreEqual(ex.GetValue("p2"), cloned.GetValue("p2")); }
[Test] public void test_cloning_on_extendables_with_clonable_base() { var c = new CloneableObj { p = 100 }; var ex = ExtendableObj.Create(c); ex.AddString("p2", "v2"); var cloned = Helpers.Clone(ex); Assert.AreNotEqual(ex, cloned); Assert.AreEqual(100, ex.GetValue("p")); Assert.AreEqual(101, cloned.GetValue("p")); Assert.AreEqual(ex.GetValue("p2"), cloned.GetValue("p2")); }
public void test_set_value_on_extendable_objects() { ExtendableObj <SimpleObj> ex = ExtendableObj.Create(new SimpleObj { p = "p1" }); ex.AddString("p2", "v2"); Helpers.SetValue(ex, "p", "p2"); Helpers.SetValue(ex, "p2", "v3"); Assert.AreEqual("p2", ex.BaseObject.p); Assert.AreEqual("p2", Helpers.GetValue <string>(ex, "p")); Assert.AreEqual("p2", Helpers.GetValue(ex, "p")); Assert.AreEqual("v3", Helpers.GetValue <string>(ex, "p2")); Assert.AreEqual("v3", Helpers.GetValue(ex, "p2")); }
public void extendable_with_append_has_att() { ExtendableObj <WithAppendHasAtt> o = ExtendableObj.Create(new WithAppendHasAtt()). AddBinary("nom1", true). AddDate("date1", DateTime.Now). AddNominal("nom2", "a"). AddNumerical("num1", 1). AddString("str1", "val"); List <PmlAttribute> atts = Build(new[] { o }); Assert.AreEqual(7, atts.Count); Assert.IsTrue(atts[0].IsNominal); Assert.AreEqual(0, atts[0].IndexOfValue("a")); Assert.AreEqual(1, atts[0].IndexOfValue("b")); // Extendables: Assert.IsTrue(atts[1].IsNominal); Assert.AreEqual(0, atts[1].IndexOfValue("0")); Assert.AreEqual(1, atts[1].IndexOfValue("1")); Assert.IsTrue(atts[2].IsDate); Assert.IsTrue(atts[3].IsNominal); Assert.AreEqual(0, atts[3].IndexOfValue("a")); Assert.IsTrue(atts[4].IsNumeric); Assert.IsTrue(atts[5].IsString); // Has Att Assert.IsTrue(atts[6].IsNominal); Assert.AreEqual(0, atts[6].IndexOfValue("0")); Assert.AreEqual(1, atts[6].IndexOfValue("1")); }