Changeset 14594 for branches/PersistenceOverhaul/HeuristicLab.Tests
- Timestamp:
- 01/20/17 11:16:42 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PersistenceOverhaul/HeuristicLab.Tests/HeuristicLab.Persistence-3.3/UseCasesPersistenceNew.cs
r14549 r14594 33 33 using HeuristicLab.Algorithms.GeneticAlgorithm; 34 34 using HeuristicLab.Data; 35 using HeuristicLab.Persistence; 35 36 using HeuristicLab.Persistence.Auxiliary; 36 37 using HeuristicLab.Persistence.Core; … … 39 40 using HeuristicLab.Persistence.Default.Xml; 40 41 using HeuristicLab.Persistence.Tests; 42 using HeuristicLab.Problems.TestFunctions; 41 43 using HeuristicLab.Tests; 42 44 using Microsoft.VisualStudio.TestTools.UnitTesting; … … 401 403 402 404 public string Profile(Func<object> GenerateDataFunc) { 403 int nrOfRepetitions = 100;405 int nrOfRepetitions = 30; 404 406 StringBuilder report = new StringBuilder(); 405 407 List<PerformanceData> dataList = new List<PerformanceData>(); … … 411 413 report.Append("Performance Report for " + GenerateDataFunc.Method.Name + ": " + Environment.NewLine); 412 414 report.Append(Environment.NewLine); 413 report.AppendFormat("Avg. old vs. new time for serializing a file : {0} / {1}; Factor:{2}",415 report.AppendFormat("Avg. old vs. new time for serializing a file; {0};{1};{2}", 414 416 dataList.Select(x => x.OldSerializingTime).Average(), 415 417 dataList.Select(x => x.NewSerializingTime).Average(), … … 417 419 ); 418 420 report.Append(Environment.NewLine); 419 report.AppendFormat("Avg. old vs. new time for deserializing a file : {0} / {1}; Factor:{2}",421 report.AppendFormat("Avg. old vs. new time for deserializing a file; {0};{1};{2}", 420 422 dataList.Select(x => x.OldDeserializingTime).Average(), 421 423 dataList.Select(x => x.NewDeserializingTime).Average(), … … 423 425 ); 424 426 report.Append(Environment.NewLine); 425 report.AppendFormat("Avg. old vs. new file size (in bytes) : {0} / {1}; Factor:{2}",427 report.AppendFormat("Avg. old vs. new file size (in bytes); {0};{1};{2}", 426 428 dataList.Select(x => x.OldFileSize).Average(), 427 429 dataList.Select(x => x.NewFileSize).Average(), … … 429 431 ); 430 432 report.Append(Environment.NewLine); 431 report.AppendFormat("Avg. old vs. new memory consumption for serializing a file (in bytes) : {0} / {1}; Factor:{2}",433 report.AppendFormat("Avg. old vs. new memory consumption for serializing a file (in bytes); {0};{1};{2}", 432 434 dataList.Select(x => x.OldSerializingMemoryConsumed).Average(), 433 435 dataList.Select(x => x.NewSerializingMemoryConsumed).Average(), … … 435 437 ); 436 438 report.Append(Environment.NewLine); 437 report.AppendFormat("Avg. old vs. new memory consumption for deserializing a file (in bytes) : {0} / {1}; Factor:{2}",439 report.AppendFormat("Avg. old vs. new memory consumption for deserializing a file (in bytes); {0};{1};{2}", 438 440 dataList.Select(x => x.OldDeserializingMemoryConsumed).Average(), 439 441 dataList.Select(x => x.NewDeserializingMemoryConsumed).Average(), … … 944 946 #region Old persistence test methods 945 947 [TestMethod] 946 [TestCategory("Persistence4 -EXEPTION")]948 [TestCategory("Persistence4")] 947 949 [TestProperty("Time", "short")] 948 950 public void ComplexStorable() { … … 1034 1036 1035 1037 [TestMethod] 1036 [TestCategory("Persistence4 -EXEPTION")]1038 [TestCategory("Persistence4")] 1037 1039 [TestProperty("Time", "short")] 1038 1040 public void SelfReferences() { … … 1062 1064 1063 1065 [TestMethod] 1064 [TestCategory("Persistence4 -EXEPTION")]1066 [TestCategory("Persistence4")] 1065 1067 [TestProperty("Time", "short")] 1066 1068 public void ArrayCreation() { … … 1352 1354 1353 1355 [TestMethod] 1354 [TestCategory("Persistence4 -EXEPTION")]1356 [TestCategory("Persistence4")] 1355 1357 [TestProperty("Time", "short")] 1356 1358 public void InstantiateParentChainReference() { … … 1516 1518 1517 1519 [TestMethod] 1518 [TestCategory("Persistence4 -EXEPTION")]1520 [TestCategory("Persistence4")] 1519 1521 [TestProperty("Time", "short")] 1520 1522 public void TestStreaming() { … … 2060 2062 public class A { 2061 2063 [Storable] 2062 public Tuple<B> B { get; set; } 2064 public B B { get; set; } 2065 2066 [Storable] public int i; 2063 2067 } 2064 2068 [StorableClass("6075F1E8-948A-4AD8-8F5A-942B777852EC")] … … 2066 2070 [Storable] 2067 2071 public A A { get; set; } 2072 2073 [StorableHook(HookType.AfterDeserialization)] 2074 void PostDeserializationHook() { 2075 //Assert.AreEqual(3, A.i); 2076 } 2068 2077 } 2069 2078 … … 2073 2082 public void TestCyclicReferencesWithTuple() { 2074 2083 var test = new Func<A>(() => { 2075 var a = new A { };2084 var a = new A { i = 4 }; 2076 2085 var b = new B { A = a }; 2077 a.B = Tuple.Create(b);2086 a.B = b; 2078 2087 return a; 2079 2088 }); 2080 ProtoBufSerializer serializer = new ProtoBufSerializer(); 2081 serializer.Serialize(test(), tempFile); 2082 object o = serializer.Deserialize(tempFile); 2083 A result = (A)o; 2084 2085 Assert.AreEqual(result, result.B.Item1.A); 2086 Assert.AreSame(result, result.B.Item1.A); 2087 2088 string msg = Profile(test); 2089 Console.WriteLine(msg); 2089 2090 //ProtoBufSerializer serializer = new ProtoBufSerializer(); 2091 //serializer.Serialize(test(), tempFile); 2092 //object o = serializer.Deserialize(tempFile); 2093 //A result = (A)o; 2094 2095 XmlGenerator.Serialize(test(), tempFile); 2096 object o = XmlParser.Deserialize(tempFile); 2097 2098 string msg = Profile(test); 2099 Console.WriteLine(msg); 2100 } 2101 2102 [TestMethod] 2103 [TestCategory("Persistence4")] 2104 [TestProperty("Time", "short")] 2105 public void TestGASerializeDeserializeExecute() { 2106 var test = new Func<GeneticAlgorithm>(() => { 2107 var ga = new GeneticAlgorithm(); 2108 ga.Problem = new SingleObjectiveTestFunctionProblem(); 2109 ga.MaximumGenerations.Value = 100; 2110 ga.SetSeedRandomly.Value = false; 2111 return ga; 2112 }); 2113 ProtoBufSerializer serializer = new ProtoBufSerializer(); 2114 serializer.Serialize(test(), tempFile); 2115 object o = serializer.Deserialize(tempFile); 2116 GeneticAlgorithm result = (GeneticAlgorithm)o; 2117 SamplesUtils.RunAlgorithm(result); 2118 GeneticAlgorithm original = test(); 2119 SamplesUtils.RunAlgorithm(original); 2120 //Assert.AreEqual(original.Results[""], result); 2121 2122 //string msg = Profile(test); 2123 //Console.WriteLine(msg); 2124 } 2125 [TestMethod] 2126 [TestCategory("Persistence4")] 2127 [TestProperty("Time", "short")] 2128 public void TestLoadingSamples() { 2129 var path = @"D:\Dev\HL\branches\PersistenceOverhaul\HeuristicLab.Optimizer\3.3\Documents"; 2130 var serializer = new ProtoBufSerializer(); 2131 foreach (var fileName in Directory.EnumerateFiles(path, "*.hl")) { 2132 var original = XmlParser.Deserialize(fileName); 2133 serializer.Serialize(original, fileName + ".proto"); 2134 // var newVersion = serializer.Deserialize(fileName + ".proto"); 2135 var p = Profile(() => original); 2136 Console.WriteLine(p); 2137 } 2090 2138 } 2091 2139 }
Note: See TracChangeset
for help on using the changeset viewer.