Example #1
0
        public void Load()
        {
            string newName1 = "test";
            string newName2 = "test2";
            int    newSize  = 20;

            MockPersistence mockPersistence = new MockPersistence
            {
                MockData = new SaveData
                {
                    Group1Name   = newName1,
                    Group2Name   = newName2,
                    Participants = Enumerable.Repeat <UnitSave>(null, newSize).ToList()
                }
            };

            NewModel();
            _context.Persistence = mockPersistence;
            _context.Persistence.Load("");

            _model.Load();
            Assert.AreEqual(newName1, _context.Group1Name);
            Assert.AreEqual(newName2, _context.Group2Name);
            Assert.AreEqual(newSize, _context.TotalSize);
        }
        public void Load()
        {
            List <AlgorithmSaveBase> algorithms = new List <AlgorithmSaveBase>
            {
                new GaleShapleyAlgorithmSave
                {
                    AlgorithmName = "galeshapley"
                },
                new GeneticAlgorithmSave
                {
                    AlgorithmName              = "genetic",
                    AbsoluteSelection          = _settings.AbsoluteSelection,
                    SelectionRate              = _settings.SelectionRate,
                    MutationChance             = _settings.MutationChance,
                    StablePairWeight           = _settings.StablePairWeight,
                    GroupHappinessWeight       = _settings.GroupHappinessWeight,
                    EgalitarianHappinessWeight = _settings.EgalitarianHappinessWeight,
                    Generations = _settings.Generations,
                    Size        = _settings.Size
                }
            };
            MockPersistence mockPersistence = new MockPersistence
            {
                MockData = new SaveData
                {
                    Algorithms = algorithms
                }
            };

            NewModel();

            _context.Persistence = mockPersistence;
            _context.Persistence.Load("");

            _model.Load();
            Assert.AreEqual(2, _context.Algorithms.Count());

            Assert.AreEqual("galeshapley", _context.Algorithms[0].Name);
            _visitor = new AlgorithmVisitor(null,
                                            () => Assert.Fail());
            _visitor.Visit(_context.Algorithms[0].Element);

            Assert.AreEqual("genetic", _context.Algorithms[1].Name);
            _visitorParam = new AlgorithmVisitorParam((x) => Assert.Fail(),
                                                      (x) =>
            {
                Assert.AreEqual(x.Settings.AbsoluteSelection, _settings.AbsoluteSelection);
                Assert.AreEqual(x.Settings.SelectionRate, _settings.SelectionRate);
                Assert.AreEqual(x.Settings.MutationChance, _settings.MutationChance);
                Assert.AreEqual(x.Settings.StablePairWeight, _settings.StablePairWeight);
                Assert.AreEqual(x.Settings.GroupHappinessWeight, _settings.GroupHappinessWeight);
                Assert.AreEqual(x.Settings.EgalitarianHappinessWeight, _settings.EgalitarianHappinessWeight);
                Assert.AreEqual(x.Settings.Generations, _settings.Generations);
                Assert.AreEqual(x.Settings.Size, _settings.Size);
            });
            _visitorParam.Visit(_context.Algorithms[1].Element);
        }
        public void Load()
        {
            NewModel();

            List <PreferenceSave> preferences = new List <PreferenceSave>();

            foreach (Participant participant in _context.Group1Participants)
            {
                preferences.Add(new PreferenceSave
                {
                    Id          = participant.ID,
                    Preferences = _context.Group2Participants.Select(x => x.ID).Reverse().ToList()
                });
            }
            foreach (Participant participant in _context.Group2Participants)
            {
                preferences.Add(new PreferenceSave
                {
                    Id          = participant.ID,
                    Preferences = _context.Group1Participants.Select(x => x.ID).Reverse().ToList()
                });
            }
            MockPersistence mockPersistence = new MockPersistence
            {
                MockData = new SaveData
                {
                    Preferences = preferences
                }
            };

            _context.Persistence = mockPersistence;
            _context.Persistence.Load("");

            _model.Load();
            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(i, _context.Participants[i].ID);
                for (int j = 0; j < 5; j++)
                {
                    if (i < 5)
                    {
                        Assert.AreEqual(9 - j, _context.Priorities[i][j]);
                    }
                    else
                    {
                        Assert.AreEqual(4 - j, _context.Priorities[i][j]);
                    }
                }
            }
            Assert.IsTrue(_context.ParticipantsChanged);
        }
Example #4
0
        public void Load()
        {
            NewModel();

            List <UnitSave> participants = new List <UnitSave>();

            for (int i = 0; i < 5; i++)
            {
                participants.Add(new UnitSave {
                    Id = i, Name = "test" + i, Group = MarriageGroup.Group1
                });
            }
            for (int i = 5; i < 10; i++)
            {
                participants.Add(new UnitSave {
                    Id = i, Name = "test" + i, Group = MarriageGroup.Group2
                });
            }

            MockPersistence mockPersistence = new MockPersistence
            {
                MockData = new SaveData
                {
                    Participants = participants
                }
            };

            _context.Persistence = mockPersistence;
            _context.Persistence.Load("");

            _model.Load();
            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(i, _context.Participants[i].ID);
                Assert.AreEqual("test" + i, _context.Participants[i].Name);
                Assert.AreEqual(i < 5 ? MarriageGroup.Group1 : MarriageGroup.Group2, _context.Participants[i].Group);
            }
            Assert.IsTrue(_context.ParticipantsChanged);
        }
Example #5
0
 private void NewModel()
 {
     _persistence = new MockPersistence();
     _context     = new ModelContext();
     _model       = new AppModel(_persistence, _context);
 }