public void TestEquivalence() { var cell1 = new SampleCell1 { Foo = 1, Bar = "bar" }; var cell2 = new SampleCell1 { Foo = 1, Bar = "bar" }; var cell3 = new SampleCell1 { Foo = 1, Bar = "foo" }; var cell4 = new SampleCell2 { Foo = 1, Bar = "bar" }; var cell5 = new SampleCell3 { Foo = 1, Bar = "bar" }; var cell6 = new SampleCell4 { Foo = 1, Bar = "bar" }; var cell7 = new SampleCell4 { Foo = 1, Bar = "bar" }; // Reference first Assert.True(cell1.Equivalent(cell1)); Assert.True(cell2.Equivalent(cell2)); Assert.True(cell3.Equivalent(cell3)); Assert.True(cell4.Equivalent(cell4)); // Fingerprint second Assert.True(cell1.Equivalent(cell4)); Assert.False(cell4.Equivalent(cell1)); Assert.True(cell6.Equivalent(cell7)); Assert.True(cell7.Equivalent(cell6)); cell7.Quux = true; Assert.True(cell6.Equivalent(cell7)); Assert.False(cell7.Equivalent(cell6)); // Contents third cell4.Bar = "foo"; Assert.False(cell1.Equivalent(cell4)); Assert.False(cell4.Equivalent(cell1)); cell6.Quux = false; Assert.False(cell6.Equivalent(cell7)); Assert.False(cell7.Equivalent(cell6)); cell6.Quux = true; Assert.True(cell6.Equivalent(cell7)); Assert.True(cell7.Equivalent(cell6)); }
public void TestEquality() { var cell1 = new SampleCell1 { Foo = 1, Bar = "bar" }; var cell2 = new SampleCell1 { Foo = 1, Bar = "bar" }; var cell3 = new SampleCell1 { Foo = 1, Bar = "foo" }; var cell4 = new SampleCell2 { Foo = 1, Bar = "bar" }; var cell5 = new SampleCell3 { Foo = 1, Bar = "bar" }; var cell6 = new SampleCell4 { Foo = 1, Bar = "bar" }; var cell7 = new SampleCell4 { Foo = 1, Bar = "bar" }; Assert.True(cell1.Equals(cell2)); Assert.True(cell2.Equals(cell1)); Assert.False(cell1.Equals(cell3)); Assert.False(cell3.Equals(cell1)); Assert.False(cell1.Equals(cell4)); Assert.False(cell1.Equals(cell5)); Assert.False(cell1.Equals(cell6)); Assert.False(cell1.Equals(cell7)); Assert.True(cell6.Equals(cell7)); }
public void TestCreation() { Cell cell1 = new SampleCell1(); Cell cell2 = new SampleCell2(); Cell cell3 = new SampleCell3(); Cell cell4 = new SampleCell4(); // Static construction var tag = cell1.GetTypeTag(); Assert.IsNull(tag.Base); Assert.AreEqual(cell1.GetType(), tag.RuntimeType); Assert.AreEqual(2, tag.NumProps); Assert.AreEqual(0, tag.Offset); tag = cell2.GetTypeTag(); Assert.AreEqual(cell1.GetTypeTag(), tag.Base); Assert.AreEqual(cell2.GetType(), tag.RuntimeType); Assert.AreEqual(1, tag.NumProps); Assert.AreEqual(2, tag.Offset); tag = cell3.GetTypeTag(); Assert.AreEqual(cell1.GetTypeTag(), tag.Base); Assert.AreEqual(cell3.GetType(), tag.RuntimeType); Assert.AreEqual(1, tag.NumProps); Assert.AreEqual(2, tag.Offset); tag = cell4.GetTypeTag(); Assert.AreEqual(cell2.GetTypeTag(), tag.Base); Assert.AreEqual(cell4.GetType(), tag.RuntimeType); Assert.AreEqual(1, tag.NumProps); Assert.AreEqual(3, tag.Offset); // Fingerprint length Assert.AreEqual(2, cell1.GetFingerprint().Length); Assert.AreEqual(3, cell2.GetFingerprint().Length); Assert.AreEqual(3, cell3.GetFingerprint().Length); Assert.AreEqual(4, cell4.GetFingerprint().Length); }
public void TestHashing() { var cell1 = new SampleCell1 { Foo = 1, Bar = "bar" }; var cell2 = new SampleCell1 { Foo = 1, Bar = "bar" }; var cell3 = new SampleCell1 { Foo = 1, Bar = "foo" }; var cell4 = new SampleCell2 { Foo = 1, Bar = "bar" }; var cell5 = new SampleCell3 { Foo = 1, Bar = "bar" }; var cell6 = new SampleCell4 { Foo = 1, Bar = "bar" }; var cell7 = new SampleCell4 { Foo = 1, Bar = "bar" }; Assert.AreEqual(cell1.GetHashCode(), cell2.GetHashCode()); Assert.AreNotEqual(cell1.GetHashCode(), cell3.GetHashCode()); Assert.AreEqual(cell1.GetHashCode(), cell4.GetHashCode()); Assert.AreEqual(cell1.GetHashCode(), cell5.GetHashCode()); Assert.AreEqual(cell1.GetHashCode(), cell6.GetHashCode()); Assert.AreEqual(cell1.GetHashCode(), cell7.GetHashCode()); Assert.AreEqual(cell6.GetHashCode(), cell7.GetHashCode()); cell6.Quux = true; Assert.AreNotEqual(cell6.GetHashCode(), cell7.GetHashCode()); cell7.Quux = true; Assert.AreEqual(cell6.GetHashCode(), cell7.GetHashCode()); }
private void Initialize() { sampleCell_ = null; }
public void TestPartialSerialization() { EventFactory.Register<SampleEvent5>(); var buffer = new x2.Buffer(); var cell1 = new SampleCell1 { // base Foo = 9, Bar = "hello" }; var cell2 = new SampleCell2 { // derived Foo = 9, Bar = "hello", Baz = true }; var event1 = new SampleEvent5(); // has base // base > base > base event1.SampleCell = cell1; Serializer serializer = new Serializer(buffer); serializer.Write(event1.GetTypeId()); event1.Serialize(serializer); long bufferLength = buffer.Length; buffer.Rewind(); Deserializer deserializer = new Deserializer(buffer); var retrieved = deserializer.Create(); retrieved.Deserialize(deserializer); var event11 = retrieved as SampleEvent5; Assert.NotNull(event11); Assert.AreEqual(event1.SampleCell.Foo, event11.SampleCell.Foo); Assert.AreEqual(event1.SampleCell.Bar, event11.SampleCell.Bar); buffer.Reset(); // derived > base > base event1.SampleCell = cell2; // base <= derived serializer = new Serializer(buffer); serializer.Write(event1.GetTypeId()); event1.Serialize(serializer); Assert.AreEqual(bufferLength, buffer.Length); { var event2 = new SampleEvent6(); // has derived event2.SampleCell = cell2; // derived <= derived var buffer2 = new x2.Buffer(); serializer = new Serializer(buffer2); serializer.Write(event2.GetTypeId()); event2.Serialize(serializer); Assert.Greater(buffer2.Length, buffer.Length); } buffer.Rewind(); deserializer = new Deserializer(buffer); retrieved = deserializer.Create(); retrieved.Deserialize(deserializer); var event12 = retrieved as SampleEvent5; Assert.NotNull(event12); Assert.AreEqual(event1.SampleCell.Foo, event12.SampleCell.Foo); Assert.AreEqual(event1.SampleCell.Bar, event12.SampleCell.Bar); }