zrrz111

DictionarySerializerTest

May 16th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class DictionarySerializerTest : MonoBehaviour {
  6.  
  7.     void Start () {
  8.         //Declare
  9.         Dictionary<int[,], Columns> testDictionary = new Dictionary<int[,], Columns>();
  10.         List<BlockProperties> properties = new List<BlockProperties>();
  11.         properties.Add(new BlockProperties(16, false));
  12.         testDictionary.Add(new int[,] {{ 12, 4 }}, new Columns(2, 9, properties));
  13.  
  14.  
  15.         //Action
  16.         byte[] bArray = DictionarySerializer<int[,], Columns>.Save(testDictionary);
  17.         Dictionary<int[,], Columns> deserializedDictionary = DictionarySerializer<int[,], Columns>.Load(bArray);
  18.  
  19.         //Assert
  20.         Debug.Log("deserializeDictionary != null : " + deserializedDictionary != null);
  21.         Debug.Log("deserializeDictionary.Count : " + deserializedDictionary.Count);
  22.         foreach (KeyValuePair<int[,], Columns> pair in deserializedDictionary)
  23.         {
  24.             string log = "{";
  25.             for (int i = 0, n = pair.Key.GetLength(0); i < n; i++)
  26.             {
  27.                 for (int j = 0, n2 = pair.Key.GetLength(1); j < n2; j++)
  28.                 {
  29.                     log += pair.Key[i, j] + " ";
  30.                 }
  31.             }
  32.             log += "} Column(";
  33.             log += pair.Value.xPos + " ";
  34.             log += pair.Value.yPos + " BlockProperties{";
  35.             for (int i = 0; i < pair.Value.properties.Count; i++)
  36.             {
  37.                 log += pair.Value.properties[i].num + " " + pair.Value.properties[i].flag;
  38.             }
  39.             log += "})";
  40.             Debug.Log(log);
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment