public void TestCloneLongListInt() { var list1 = new SampleMatrix { M = new List <List <int> >() }; for (int i = 0; i < 1000; ++i) { list1.M.Add(new List <int>()); for (int j = 0; j < 400; ++j) { list1.M[i].Add(i * j * 97); } } var list2 = new ClonerGen().Deep(list1); Assert.AreEqual(list1.M.Count, list2.M.Count); }
public void TestJsonLongListInt() { var list1 = new SampleMatrix { M = new List <List <int> >() }; for (int i = 0; i < 300; ++i) { list1.M.Add(new List <int>()); for (int j = 0; j < 400; ++j) { list1.M[i].Add(i * j * 97); } } var js = new JsonSerializer(); var result1 = js.ToString(list1); Assert.IsTrue(result1 != ""); var list2 = new SampleMatrix(); var jd = new JsonDeserializer(); jd.FromString(list2, result1); Assert.AreEqual(list1.M.Count, list2.M.Count); for (int i = 0; i < list1.M.Count; ++i) { for (int j = 0; j < list1.M[i].Count; ++j) { Assert.AreEqual(list1.M[i][j], list2.M[i][j]); } } var jdg = new SampleMatrix_JsonDeserializer(); var list3 = (SampleMatrix)jdg.FromString(result1); Assert.AreEqual(list1.M.Count, list3.M.Count); }
public void TestCollection() { TestGen(cl => { var src = new List <string> { "s1", "s2" }; var dst = cl.Deep(src); Assert.AreNotEqual(src, dst); CollectionAssert.AreEqual(src, dst); }); TestGen(cl => { var src = new List <Sample1> { new Sample1 { X = 34 } }; var dst = cl.Deep(src); Assert.AreNotEqual(src, dst); Assert.AreEqual(src.Count, dst.Count); Assert.AreNotEqual(src[0], dst[0]); Assert.AreEqual(src[0].X, dst[0].X); }); TestGen(cl => { var src = new SampleList { E = new List <string> { "sq" } }; var dst = cl.Deep(src); Assert.AreNotEqual(src, dst); Assert.AreEqual(src.E.Count, dst.E.Count); Assert.AreNotEqual(src.E, dst.E); Assert.AreEqual(src.E[0], dst.E[0]); }); TestGen(cl => { var src = new SampleMatrix { M = new List <List <int> > { new List <int> { 1, 2, 3 }, new List <int> { 4 }, } }; var dst = cl.Deep(src); Assert.AreNotEqual(src, dst); Assert.AreNotEqual(src.M, dst.M); Assert.AreNotEqual(src.M[0], dst.M[0]); CollectionAssert.AreEqual(src.M[0], dst.M[0]); CollectionAssert.AreEqual(src.M[1], dst.M[1]); }); TestGen(cl => { var src = new SampleCollection <int> { 1, 5 }; var dst = cl.Deep(src); Assert.AreNotEqual(src, dst); int[] srcA = new int[2], dstA = new int[2]; src.CopyTo(srcA, 0); dst.CopyTo(dstA, 0); CollectionAssert.AreEqual(srcA, dstA); }); TestGen(cl => { var src = new SampleExplicitCollection <int>(); ((ICollection <int>)src).Add(1); ((ICollection <int>)src).Add(5); var dst = cl.Deep(src); Assert.AreNotEqual(src, dst); CollectionAssert.AreEqual(src.ToList(), dst.ToList()); }); }