public void TestPieceSerialization() { string tstr = @"{ ""index"": 0}"; var json = JSON.Parse(tstr); var t = PieceType.FromJSON(json); Assert.AreEqual(0, t.index); for (int i = 0; i < 100; i++) { var tt = PieceType.Get(i); var tjson = tt.ToJSON(); var tout = PieceType.FromJSON(tjson); Assert.AreEqual(i, tt.index, "initial type has correct index"); Assert.AreEqual(i, tout.index, "deserialized type has correct index"); Assert.AreEqual(tt.index, tout.index, "both have correct index"); Assert.IsTrue(tt.Matches(PieceType.FromJSON(tjson)), "serialize -> deserialize results in same type"); } for (int i = 0; i < 10; i++) { for (int size = 1; size <= 16; size *= 2) { var p = new Piece(PieceType.Get(i), size); Assert.IsTrue(p.Matches(Piece.FromJSON(p.ToJSON())), "piece matches its serialized -> deserialized"); } } }
public void RestoredSerializedEqualsOriginal() { foreach (var t in new PieceType[] { t0, t1, t2 }) { var json = t.ToJSON(); var restoredType = PieceType.FromJSON(json); Assert.AreEqual(t, restoredType, "restored type equals original"); } }
public void RestoredSerializedMatchesOriginal() { foreach (var t in new PieceType[] { t0, t1, t2 }) { var json = t.ToJSON(); var restoredType = PieceType.FromJSON(json); Assert.IsTrue(t.Matches(restoredType), "restored type matches original"); } }