Example #1
0
        public void SerializeSynapseTest(int segmentindex, int synapseindex, double permanence)
        {
            Cell cell = new Cell(12, 14, 16, 18, new CellActivity());

            var distSeg1 = new DistalDendrite(cell, 1, 2, 2, 1.0, 100);

            cell.DistalDendrites.Add(distSeg1);

            var distSeg2 = new DistalDendrite(cell, 44, 24, 34, 1.0, 100);

            cell.DistalDendrites.Add(distSeg2);

            Cell preSynapticcell = new Cell(11, 14, 16, 28, new CellActivity());

            var synapse1 = new Synapse(cell, distSeg1.SegmentIndex, 23, 1.0);

            preSynapticcell.ReceptorSynapses.Add(synapse1);

            var synapse2 = new Synapse(cell, distSeg2.SegmentIndex, 27, 1.0);

            preSynapticcell.ReceptorSynapses.Add(synapse2);

            using (StreamWriter sw = new StreamWriter($"ser_{nameof(SerializeSynapseTest)}.txt"))
            {
                synapse1.Serialize(sw);
            }

            using (StreamReader sr = new StreamReader($"ser_{nameof(SerializeSynapseTest)}.txt"))
            {
                HtmSerializer2 ser = new HtmSerializer2();

                Synapse synapseT1 = ser.DeserializeSynapse(sr);

                Assert.IsTrue(synapse1.Equals(synapseT1));
            }
        }
Example #2
0
        //[DataRow(13, 87, 22.45)]
        //[DataRow(1000, 3400, 4573.623)]

        public void SerializeSynapseTest(int segmentindex, int synapseindex, double permanence)
        {
            Cell cell = new Cell(12, 14, 16, 18, new CellActivity());

            //Cell cell = new Cell();
            cell.DistalDendrites = new List <DistalDendrite>();

            cell.DistalDendrites.Add(new DistalDendrite(cell, 1, 2, 2, 1.0, 100));
            cell.DistalDendrites.Add(new DistalDendrite(cell, 44, 24, 34, 1.0, 100));

            cell.ReceptorSynapses = new List <Synapse>();

            cell.ReceptorSynapses.Add(new Synapse(cell, 1, 23, 1.0));
            cell.ReceptorSynapses.Add(new Synapse(cell, 3, 27, 1.0));
            Synapse synapse  = new Synapse(cell, segmentindex, synapseindex, permanence);
            Synapse synapse1 = null;

            using (StreamWriter sw = new StreamWriter($"ser_{nameof(SerializeSynapseTest)}_{synapseindex}.txt"))
            {
                synapse.Serialize(sw);

                using (StreamWriter streamWriter = new StreamWriter($"ser_{nameof(SerializeCellTest)}_{cell.Index}.txt"))
                {
                    cell.Serialize(streamWriter);
                    for (int j = 0; j < cell.DistalDendrites.Count; j++)
                    {
                        if (!File.Exists($"Users / mouni.kolisetty / neocortexapi / NeoCortexApi / UnitTestsProject / bin / Debug / net5.0 / ser_SerializeSynapseTest_{cell.DistalDendrites[j].Ordinal}.txt"))
                        {
                            using (StreamWriter swLD = new StreamWriter($"ser_{nameof(SerializeDistalDendrite)}_{cell.DistalDendrites[j].Ordinal}.txt"))
                            {
                                cell.DistalDendrites[j].Serialize(swLD);
                            }
                        }
                    }
                    for (int i = 0; i < cell.ReceptorSynapses.Count; i++)
                    {
                        if (!File.Exists($"Users / mouni.kolisetty / neocortexapi / NeoCortexApi / UnitTestsProject / bin / Debug / net5.0 / ser_SerializeSynapseTest_{cell.ReceptorSynapses[i].SynapseIndex}.txt"))
                        {
                            using (StreamWriter swLS = new StreamWriter($"ser_{nameof(SerializeSynapseTest)}_{cell.ReceptorSynapses[i].SynapseIndex}.txt"))
                            {
                                cell.ReceptorSynapses[i].Serialize(swLS);
                            }
                        }
                    }
                }
            }
            using (StreamReader sr = new StreamReader($"ser_{nameof(SerializeSynapseTest)}_{synapseindex}.txt"))
            {
                synapse1 = Synapse.Deserialize(sr);
            }
            using (StreamReader streamreader = new StreamReader($"ser_SerializeCellTest_{synapse1.SourceCell.Index}.txt"))
            {
                var mvcell = Cell.Deserialize(streamreader);
                synapse1.SourceCell = mvcell;
                foreach (Synapse s in synapse1.SourceCell.ReceptorSynapses)
                {
                    s.SourceCell = mvcell;
                }
                foreach (DistalDendrite dd in synapse1.SourceCell.DistalDendrites)
                {
                    dd.ParentCell = mvcell;
                }
            }

            Assert.IsTrue(synapse1.SourceCell.ReceptorSynapses.SequenceEqual(synapse.SourceCell.ReceptorSynapses));
            //using (StreamReader sr = new StreamReader($"ser_{nameof(SerializeSynapseTest)}.txt"))
            //{
            //    Synapse synapse1 = Synapse.Deserialize(sr);

            //    Assert.IsTrue(synapse1.Equals(synapse));
            //}
        }