Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/18/09 18:13:40 (15 years ago)
Author:
epitzer
Message:

Pluginification and major refactoring. (#506)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/New Persistence Exploration/Persistence/Test/NewSerializationTest.cs

    r1356 r1357  
    11using System;
     2using System.Collections;
    23using System.Collections.Generic;
    34using System.IO;
    4 
    5 namespace Persistence.Test {
     5using HeuristicLab.Persistence.Interfaces;
     6
     7namespace HeuristicLab.Persistence.Test {
     8
     9  public class RootBase {
     10    [Storable]
     11    private string baseString = "Serial";
     12  }
     13
     14  public class Root : RootBase {
     15    [Storable]
     16    public int[] i = new[] { 3, 4, 5, 6 };
     17    [Storable]
     18    public string s;
     19    [Storable]
     20    public ArrayList intArray = new ArrayList(new[] { 1, 2, 3 });
     21    [Storable]
     22    public List<int> intList = new List<int>(new[] { 321, 312, 321 });
     23    [Storable]
     24    public Custom c;
     25    [Storable]
     26    public List<Root> selfReferences;
     27    [Storable]
     28    public double[,] multiDimArray = new double[,] { { 1, 2, 3 }, { 3, 4, 5 } };
     29    [Storable]
     30    public bool boolean = true;
     31    [Storable]
     32    public DateTime dateTime;
     33    [Storable]
     34    public KeyValuePair<string, int> kvp = new KeyValuePair<string, int>("Serial", 123);
     35    [Storable]
     36    public Dictionary<string, int> dict = new Dictionary<string, int>();
     37    [Storable(DefaultValue = "default")]
     38    public string uninitialized;
     39  }
     40
     41  public class Custom {
     42    [Storable]
     43    public int i;
     44    [Storable]
     45    public Root r;
     46    [Storable]
     47    public string name = "Serial";
     48  }
     49
     50  public class CloneableRoot {
     51    public int[] i = new[] { 3, 4, 5, 6 };
     52    public string s;
     53    public ArrayList intArray = new ArrayList(new[] { 1, 2, 3 });
     54    public List<int> intList = new List<int>(new[] { 321, 312, 321 });
     55    public CloneableCustom c;
     56    public List<CloneableRoot> selfReferences;
     57    public double[,] multiDimArray = new double[,] { { 1, 2, 3 }, { 3, 4, 5 } };
     58    public bool boolean = true;
     59    public DateTime dateTime;
     60    public KeyValuePair<string, int> kvp = new KeyValuePair<string, int>("test key", 123);
     61    public Dictionary<string, int> dict = new Dictionary<string, int>();
     62    public object Clone(Dictionary<object, object> twins) {
     63      if (twins.ContainsKey(this))
     64        return twins[this];
     65      CloneableRoot cr = new CloneableRoot();
     66      twins.Add(this, cr);
     67      cr.i = i;
     68      cr.s = s;
     69      cr.intArray = new ArrayList(intArray);
     70      cr.intList = new List<int>(intList);
     71      cr.c = (CloneableCustom)c.Clone(twins);
     72      cr.selfReferences = new List<CloneableRoot>();
     73      for (int j = 0; j < selfReferences.Count; j++) {
     74        cr.selfReferences.Add(this);
     75      }
     76      cr.multiDimArray = (double[,])multiDimArray.Clone();
     77      cr.dateTime = new DateTime(dateTime.Ticks);
     78      cr.kvp = new KeyValuePair<string, int>(kvp.Key, kvp.Value);
     79      cr.dict = new Dictionary<string, int>(dict);
     80      return cr;
     81    }
     82  }
     83
     84  public class CloneableCustom {
     85    public int i;
     86    public CloneableRoot r;
     87    public string name = "Serial";
     88    public object Clone(Dictionary<object, object> twins) {
     89      if (twins.ContainsKey(this))
     90        return twins[this];
     91      CloneableCustom cc = new CloneableCustom();
     92      twins.Add(this, cc);
     93      cc.i = i;
     94      cc.r = (CloneableRoot)r.Clone(twins);
     95      cc.name = name;
     96      return cc;
     97    }
     98  }
     99
     100  public class Manager {
     101
     102    private DateTime lastLoadTime;
     103    [Storable]
     104    private DateTime lastLoadTimePersistence {
     105      get { return lastLoadTime; }
     106      // ReSharper disable ValueParameterNotUsed
     107      set { lastLoadTime = DateTime.Now; }
     108      // ReSharper restore ValueParameterNotUsed
     109    }
     110    [Storable]
     111    private double? dbl;
     112  }
     113
     114  public class StorableObject {
     115
     116    [Storable]
     117    Dictionary<int, string> dict;
     118
     119    public void Init() {
     120      dict = new Dictionary<int, string>();
     121      for (int i = 0; i < 1000000; i++) {
     122        dict.Add(i, i.ToString());
     123      }
     124    }
     125  }
     126
     127  public class CloneableObject : ICloneable {
     128
     129    Dictionary<int, string> dict;
     130
     131    public void Init() {
     132      dict = new Dictionary<int, string>();
     133      for (int i = 0; i < 1000000; i++) {
     134        dict.Add(i, i.ToString());
     135      }
     136    }
     137    public object Clone() {
     138      CloneableObject clone = new CloneableObject {
     139        dict = new Dictionary<int, string>(dict)
     140      };
     141      return clone;
     142    }
     143  } 
    6144
    7145  public class NewSerializationTest {
Note: See TracChangeset for help on using the changeset viewer.