Example #1
0
        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));
            }
        }