public void ObjectEquality_TEST() { Xorshift random = new Xorshift(Seed); double delta = 1.0e-6; double deltaDateSeconds = 1.0e-3; // bool Assert.IsTrue(Plist.EqualObject(true, true, delta, deltaDateSeconds)); Assert.IsTrue(Plist.EqualObject(false, false, delta, deltaDateSeconds)); Assert.IsTrue(Plist.EqualObject(true, false, delta, deltaDateSeconds) == false); Assert.IsTrue(Plist.EqualObject(true, false, delta, deltaDateSeconds) == false); for (int i = 0; i < 100000; ++i) { int value1 = (int)random.Generate() * (random.Uniform() < 0.5 ? 1 : -1); int value2 = (int)random.Generate() * (random.Uniform() < 0.5 ? 1 : -1); Assert.IsTrue(Plist.EqualObject(value1, value1, delta, deltaDateSeconds)); Assert.IsTrue(Plist.EqualObject(value1, value2, delta, deltaDateSeconds) == (value1 == value2)); Assert.IsTrue(Plist.EqualObject(value1, value2, delta, deltaDateSeconds) == Plist.EqualObject(value2, value1, delta, deltaDateSeconds)); } for (int i = 0; i < 100000; ++i) { double value1 = random.Uniform(-1.0e+9, 1.0e+9); Assert.IsTrue(Plist.EqualObject(value1, value1, delta, deltaDateSeconds)); Assert.IsTrue(Plist.EqualObject(value1, value1 + random.Uniform(0.1, 1000.0), delta, deltaDateSeconds) == false); Assert.IsTrue(Plist.EqualObject(value1, value1 - random.Uniform(0.1, 1000.0), delta, deltaDateSeconds) == false); } for (int i = 0; i < 100000; ++i) { DateTime value1 = DateTime.Now.Add(TimeSpan.FromSeconds(random.Uniform(-1.0e+6, 1.0e+6))); Assert.IsTrue(Plist.EqualObject(value1, value1, delta, deltaDateSeconds)); Assert.IsTrue(Plist.EqualObject(value1, value1.AddSeconds(random.Uniform(0.1, 1000.0)), delta, deltaDateSeconds) == false); Assert.IsTrue(Plist.EqualObject(value1, value1.AddSeconds(-random.Uniform(0.1, 1000.0)), delta, deltaDateSeconds) == false); } for (int i = 0; i < 10000; ++i) { string value1 = Arbitrary.Text(); string value2 = Arbitrary.Text(); Assert.IsTrue(Plist.EqualObject(value1, value1, delta, deltaDateSeconds)); Assert.IsTrue(Plist.EqualObject(value1 + value2, value1 + value2, delta, deltaDateSeconds)); Assert.IsTrue(Plist.EqualObject(value1, value1 + "a", delta, deltaDateSeconds) == false); Assert.IsTrue(Plist.EqualObject(value1, value2, delta, deltaDateSeconds) == Plist.EqualObject(value2, value1, delta, deltaDateSeconds)); Assert.IsTrue(Plist.EqualObject(value1, value2, delta, deltaDateSeconds) == (value2 == value1)); } for (int i = 0; i < 10000; ++i) { byte[] value1 = Arbitrary.BinaryData(); byte[] valueA = value1.Concat(new byte[] { (byte)(random.Generate() & 0xFF) }).ToArray(); byte[] valueB = value1.Concat(new byte[] { (byte)(random.Generate() & 0xFF) }).ToArray(); Assert.IsTrue(Plist.EqualObject(valueA, valueB, delta, deltaDateSeconds) == Plist.EqualObject(valueB, valueA, delta, deltaDateSeconds)); Assert.IsTrue(Plist.EqualObject(value1, valueA, delta, deltaDateSeconds) == false); } for (int i = 0; i < 5000; ++i) { List <object> value1 = new List <object>(); int n = (int)random.Generate() % 100; for (int j = 0; j < n; ++j) { value1.Add(Arbitrary.PlistValue()); } Assert.IsTrue(Plist.EqualObject(value1, value1, delta, deltaDateSeconds)); // Insert Test List <object> value2 = new List <object>(value1); value2.Insert((int)random.Generate() % (value1.Count + 1), Arbitrary.PlistValue()); Assert.IsTrue(Plist.EqualObject(value1, value2, delta, deltaDateSeconds) == false); // Modify Test if (n > 0) { List <object> value3 = new List <object>(value1); int index = (int)random.Generate() % value1.Count; object newValue = Arbitrary.PlistValue(); object oldValue = value3[index]; value3[index] = newValue; if (Plist.EqualObject(oldValue, newValue, delta, deltaDateSeconds)) { Assert.IsTrue(Plist.EqualObject(value1, value3, delta, deltaDateSeconds)); } else { Assert.IsTrue(Plist.EqualObject(value1, value3, delta, deltaDateSeconds) == false); } } } for (int i = 0; i < 1000; ++i) { Dictionary <string, object> value1 = new Dictionary <string, object>(); int n = (int)random.Generate() % 100; for (int j = 0; j < n; ++j) { value1[Arbitrary.Text()] = Arbitrary.PlistValue(); } Assert.IsTrue(Plist.EqualObject(value1, value1, delta, deltaDateSeconds)); // Add Test Dictionary <string, object> value2 = new Dictionary <string, object>(value1); var newKey = Arbitrary.Text(); if (value2.ContainsKey(newKey) == false) { value2[newKey] = Arbitrary.PlistValue(); Assert.IsTrue(Plist.EqualObject(value1, value2, delta, deltaDateSeconds) == false); } // Modify Test Dictionary <string, object> value3 = new Dictionary <string, object>(value1); if (n > 0) { var key = value3.Keys.ToArray()[(int)random.Generate() % value3.Count]; object newValue = Arbitrary.PlistValue(); object oldValue = value3[key]; value3[key] = newValue; if (Plist.EqualObject(oldValue, newValue, delta, deltaDateSeconds)) { Assert.IsTrue(Plist.EqualObject(value1, value3, delta, deltaDateSeconds)); } else { Assert.IsTrue(Plist.EqualObject(value1, value3, delta, deltaDateSeconds) == false); } } } }