Beispiel #1
0
    public void UpdateGeneration_savesAlteredGeneration()
    {
        var gen = new Generation();

        gen.Individuals.Add(new Individual("abc"));
        gen.Individuals.Add(new Individual("def"));

        _handler.SaveNewGeneration(gen, 3, 4);

        var RetrievedGen1 = _handler.ReadGeneration(3, 4);

        Assert.IsNotNull(RetrievedGen1);
        Assert.AreEqual(2, RetrievedGen1.Individuals.Count);

        var i1 = RetrievedGen1.Individuals.First();

        Assert.AreEqual("abc", i1.Genome);
        Assert.AreEqual(0, i1.Score);
        Assert.AreEqual(0, i1.MatchesPlayed);
        Assert.AreEqual(0, i1.MatchesSurvived);
        Assert.AreEqual(0, i1.KilledAllDrones);
        Assert.AreEqual(0, i1.TotalDroneKills);
        Assert.AreEqual("", i1.MatchScoresString);
        Assert.AreEqual(0, i1.MatchScores.Count);

        var i2 = RetrievedGen1.Individuals[1];

        Assert.AreEqual("def", i2.Genome);
        Assert.AreEqual(0, i2.Score);
        Assert.AreEqual(0, i2.MatchesPlayed);
        Assert.AreEqual(0, i2.MatchesSurvived);
        Assert.AreEqual(0, i2.KilledAllDrones);
        Assert.AreEqual(0, i2.TotalDroneKills);
        Assert.AreEqual("", i2.MatchScoresString);
        Assert.AreEqual(0, i2.MatchScores.Count);

        gen.RecordMatch(new GenomeWrapper("abc"), 42, true, true, 15, new List <string> {
            "abc"
        }, false);

        _handler.UpdateGeneration(gen, 3, 4);

        var RetrievedGen2 = _handler.ReadGeneration(3, 4);

        Assert.IsNotNull(RetrievedGen2);
        Assert.AreEqual(2, RetrievedGen2.Individuals.Count);

        var i1b = RetrievedGen2.Individuals.First();

        Assert.AreEqual("abc", i1b.Genome);
        Assert.AreEqual(42, i1b.Score);
        Assert.AreEqual(1, i1b.MatchesPlayed);
        Assert.AreEqual(1, i1b.MatchesSurvived);
        Assert.AreEqual(1, i1b.KilledAllDrones);
        Assert.AreEqual(15, i1b.TotalDroneKills);
        Assert.AreEqual("42", i1b.MatchScoresString);
        Assert.AreEqual(1, i1b.MatchScores.Count);
        Assert.AreEqual(42, i1b.MatchScores.First());

        var i2b = RetrievedGen2.Individuals[1];

        Assert.AreEqual("def", i2b.Genome);
        Assert.AreEqual(0, i2b.Score);
        Assert.AreEqual(0, i2b.MatchesPlayed);
        Assert.AreEqual(0, i2b.MatchesSurvived);
        Assert.AreEqual(0, i2b.KilledAllDrones);
        Assert.AreEqual(0, i2b.TotalDroneKills);
        Assert.AreEqual("", i2b.MatchScoresString);
        Assert.AreEqual(0, i2b.MatchScores.Count);
    }
    public void UpdateGeneration_SavesCurrentGeneration()
    {
        Generation gen = new Generation();

        gen.Individuals.Add(new Individual("abc"));
        gen.Individuals.Add(new Individual("def"));

        _handler.SaveNewGeneration(gen, 3, 4);

        Generation RetrievedGen1 = _handler.ReadGeneration(3, 4);

        Assert.IsNotNull(RetrievedGen1);
        Assert.AreEqual(2, RetrievedGen1.Individuals.Count);

        var i1 = RetrievedGen1.Individuals.First();

        Assert.AreEqual("abc", i1.Genome);
        Assert.AreEqual(0, i1.Score);
        Assert.AreEqual(0, i1.MatchesAsLastSurvivor);
        Assert.AreEqual("", i1.PreviousCombatantsString);
        Assert.AreEqual(0, i1.PreviousCombatants.Count);

        var i2 = RetrievedGen1.Individuals[1];

        Assert.AreEqual("def", i2.Genome);
        Assert.AreEqual(0, i2.Score);
        Assert.AreEqual(0, i2.MatchesAsLastSurvivor);
        Assert.AreEqual("", i2.PreviousCombatantsString);
        Assert.AreEqual(0, i2.PreviousCombatants.Count);

        var gwA = new GenomeWrapper("abc")
        {
            Budget = 59
        };

        gen.RecordMatch(gwA, 5, true, false, 0, new List <string> {
            "abc", "def"
        }, true);
        gen.RecordMatch(new GenomeWrapper("def"), 15, false, false, 0, new List <string> {
            "abc", "def"
        }, false);

        _handler.UpdateGeneration(gen, 3, 4);

        Generation RetrievedGen2 = _handler.ReadGeneration(3, 4);

        Assert.IsNotNull(RetrievedGen2);
        Assert.AreEqual(2, RetrievedGen2.Individuals.Count);

        var i1b = RetrievedGen2.Individuals.First(i => i.Genome == "abc");

        Assert.AreEqual(5, i1b.Score);
        Assert.AreEqual(1, i1b.MatchesAsLastSurvivor);
        Assert.AreEqual(1, i1b.MatchesPlayed);
        Assert.AreEqual(1, i1b.MatchesSurvived);
        Assert.AreEqual("def", i1b.PreviousCombatantsString);
        Assert.AreEqual(1, i1b.PreviousCombatants.Count);
        Assert.AreEqual("def", i1b.PreviousCombatants.First());

        var i2b = RetrievedGen2.Individuals.First(i => i.Genome == "def");

        Assert.AreEqual(15, i2b.Score);
        Assert.AreEqual(0, i2b.MatchesAsLastSurvivor);
        Assert.AreEqual(0, i2b.MatchesSurvived);
        Assert.AreEqual(1, i2b.MatchesPlayed);
        Assert.AreEqual("abc", i2b.PreviousCombatantsString);
        Assert.AreEqual(1, i2b.PreviousCombatants.Count);
        Assert.AreEqual("abc", i2b.PreviousCombatants.First());
    }