public void SimilarityMatrixRawSerializationTest() { string[] sources = new string[] { "source1", "source2", "source3", "source4", "source5", "source6", "source7", "source8", "source9", "source10" }; string[] targets = new string[] { "target1", "target2", "target3", "target4", "target5", "target6", "target7", "target8", "target9", "target10" }; TLSimilarityMatrix matrixIn = new TLSimilarityMatrix(); for (int i = 0; i < sources.Length; i++) { matrixIn.AddLink(sources[i], targets[i], (double)i); } BinaryWriter binWriter = new BinaryWriter(new MemoryStream()); BinaryReader binReader = new BinaryReader(binWriter.BaseStream); matrixIn.WriteData(binWriter); binReader.BaseStream.Position = 0; TLSimilarityMatrix matrixOut = new TLSimilarityMatrix(); matrixOut.ReadData(binReader); Assert.AreEqual(matrixIn.Count, matrixOut.Count); StringHashSet setIn = matrixIn.SourceArtifactsIds; StringHashSet setOut = matrixOut.SourceArtifactsIds; foreach (string artifact in setIn) { Assert.IsTrue(setOut.Contains(artifact)); } }
/// <summary> /// Reads the data. (allows faster custom serialization for better performance in TraceLab) /// </summary> /// <param name="reader">The reader.</param> public void ReadData(System.IO.BinaryReader reader) { int dataversion = reader.ReadInt32(); if (dataversion != TLDataset.version) { throw new InvalidOperationException("Binary reader did not read correct data version. Data corrupted. Potentially IRawSerializable not implemented correctly"); } else { this.m_name = reader.ReadString(); bool isMemberPresent = reader.ReadBoolean(); if (isMemberPresent) { TLArtifactsCollection artifacts = new TLArtifactsCollection(); artifacts.ReadData(reader); this.SourceArtifacts = artifacts; } isMemberPresent = reader.ReadBoolean(); if (isMemberPresent) { TLArtifactsCollection artifacts = new TLArtifactsCollection(); artifacts.ReadData(reader); this.TargetArtifacts = artifacts; } isMemberPresent = reader.ReadBoolean(); if (isMemberPresent) { TLSimilarityMatrix matrix = new TLSimilarityMatrix(); matrix.ReadData(reader); this.AnswerSet = matrix; } } }