Пример #1
0
        public void TestGenotype_RoundTripJSON()
        {
            var json = "{\"neurons\":[{\"innovation\":0,\"type\":4,\"mean\":0.5,\"sigma\":0,\"a\":0.5,\"b\":0.5,\"c\":0.5,\"d\":0.5},{\"innovation\":1,\"type\":4,\"mean\":0.5,\"sigma\":0,\"a\":0.5,\"b\":0.5,\"c\":0.5,\"d\":0.5},{\"innovation\":2,\"type\":4,\"mean\":0.5,\"sigma\":0,\"a\":0.5,\"b\":0.5,\"c\":0.5,\"d\":0.5}],\"synapses\":[{\"innovation\":0,\"weight\":0.5,\"from\":0,\"to\":1,\"enabled\":true},{\"innovation\":1,\"weight\":0.5,\"from\":0,\"to\":1,\"enabled\":true},{\"innovation\":2,\"weight\":0.5,\"from\":0,\"to\":1,\"enabled\":true}]}";
            var deserializedGenotype = Genotype.FromJSON(JSON.Deserialize(json));
            var serializedGenotype   = JSON.Serialize(deserializedGenotype.ToJSON());

            Assert.AreEqual(json, serializedGenotype, "JSON can convert round-trip");
        }
Пример #2
0
        public void TestGenotype_FromJSON()
        {
            var json = "{\"neurons\":[{\"innovation\":0,\"type\":4,\"mean\":0.5,\"sigma\":0,\"a\":0.5,\"b\":0.5,\"c\":0.5,\"d\":0.5},{\"innovation\":1,\"type\":4,\"mean\":0.5,\"sigma\":0,\"a\":0.5,\"b\":0.5,\"c\":0.5,\"d\":0.5},{\"innovation\":2,\"type\":4,\"mean\":0.5,\"sigma\":0,\"a\":0.5,\"b\":0.5,\"c\":0.5,\"d\":0.5}],\"synapses\":[{\"innovation\":0,\"weight\":0.5,\"from\":0,\"to\":1,\"enabled\":true},{\"innovation\":1,\"weight\":0.5,\"from\":0,\"to\":1,\"enabled\":true},{\"innovation\":2,\"weight\":0.5,\"from\":0,\"to\":1,\"enabled\":true}]}";
            var deserializedGenotype = Genotype.FromJSON(JSON.Deserialize(json));

            var comparer = new GenotypeEqualityComparer();

            Assert.That(comparer.Equals(genotype, deserializedGenotype));
        }