public void LoadData() { SaveData data; NewModel(); SetupModel setupModel = new SetupModel(_context); setupModel.Initialize(); ParticipantsModel participantsModel = new ParticipantsModel(_context); participantsModel.Initialize(); PreferencesModel preferencesModel = new PreferencesModel(_context); preferencesModel.Initialize(); AlgorithmModel algorithmModel = new AlgorithmModel(_context); algorithmModel.Initialize(); _model.SaveAsData(""); data = _persistence.MockData; NewModel(); _persistence.MockData = data; _model.LoadData(""); Assert.AreEqual(data, _persistence.Data); }
public void RefreshPage() { if (_context.SetupChanged) { _model.Initialize(); } Group1Participants = new ObservableCollection <ParticipantRow>(); Group2Participants = new ObservableCollection <ParticipantRow>(); Group1Name = _context.Group1Name; Group2Name = _context.Group2Name; foreach (Participant participant in _context.Group1Participants) { ParticipantRow row = new ParticipantRow(participant.ID, participant.Name); row.NameChanged += new EventHandler(OnParticipantNameChanged); Group1Participants.Add(row); } foreach (Participant participant in _context.Group2Participants) { ParticipantRow row = new ParticipantRow(participant.ID, participant.Name); row.NameChanged += new EventHandler(OnParticipantNameChanged); Group2Participants.Add(row); } OnPropertyChanged("Group1Name"); OnPropertyChanged("Group2Name"); OnPropertyChanged("Group1Participants"); OnPropertyChanged("Group2Participants"); }
public void NewAlgorithmModel() { NewModel(); SetupModel setupModel = _model.NewSetupModel(); setupModel.Initialize(); ParticipantsModel participantsModel = _model.NewParticipantsModel(); participantsModel.Initialize(); PreferencesModel preferencesModel = _model.NewPreferencesModel(); preferencesModel.Initialize(); AlgorithmModel algorithmModel = _model.NewAlgorithmModel(); algorithmModel.Initialize(); _context.AlgorithmsChanged = false; algorithmModel.CreateGaleShapleyAlgorithm(); Assert.AreEqual(1, _context.Algorithms.Count()); AlgorithmVisitor _visitor = new AlgorithmVisitor(null, () => Assert.Fail()); _visitor.Visit(_context.Algorithms[0].Element); Assert.IsTrue(_context.AlgorithmsChanged); }
/// <summary> /// Create new model /// </summary> private void NewModel() { _context = new ModelContext { TotalSize = 10, SetupChanged = true }; _model = new ParticipantsModel(_context); _model.Initialize(); _context.ParticipantsChanged = false; }
public void NewParticipantsModel() { NewModel(); SetupModel setupModel = _model.NewSetupModel(); setupModel.Initialize(); ParticipantsModel participantsModel = _model.NewParticipantsModel(); participantsModel.Initialize(); _context.ParticipantsChanged = false; participantsModel.EditParticipant(0, "test"); Assert.AreEqual("test", _context.Participants[0].Name); Assert.IsTrue(_context.ParticipantsChanged); }
private void NewViewModel() { _context = new ModelContext(); _model = new PreferencesModel(_context); _viewModel = new PreferencesViewModel(_model, _context); SetupModel setupModel = new SetupModel(_context); setupModel.Initialize(); ParticipantsModel participantsModel = new ParticipantsModel(_context); participantsModel.Initialize(); _viewModel.RefreshPage(); }
public void NewPreferencesModel() { NewModel(); SetupModel setupModel = _model.NewSetupModel(); setupModel.Initialize(); ParticipantsModel participantsModel = _model.NewParticipantsModel(); participantsModel.Initialize(); PreferencesModel preferencesModel = _model.NewPreferencesModel(); preferencesModel.Initialize(); _context.PreferencesChanged = false; preferencesModel.EditPreference(0, 0, 3); Assert.AreEqual(3, _context.Priorities[0][0]); Assert.IsTrue(_context.PreferencesChanged); }
public void NewRunModel() { StablePairsEvaluation stablePairsEvaluation = new StablePairsEvaluation(); GroupHappinessEvaluation groupHappinessEvaluation = new GroupHappinessEvaluation(); EgalitarianHappinessEvaluation egalitarianHappinessEvaluation = new EgalitarianHappinessEvaluation(); NewModel(); SetupModel setupModel = _model.NewSetupModel(); setupModel.Initialize(); ParticipantsModel participantsModel = _model.NewParticipantsModel(); participantsModel.Initialize(); PreferencesModel preferencesModel = _model.NewPreferencesModel(); preferencesModel.Initialize(); AlgorithmModel algorithmModel = _model.NewAlgorithmModel(); algorithmModel.Initialize(); RunModel runModel = _model.NewRunModel(); runModel.Initialize(); int receivedEvents = 0; Task task; NewModel(); runModel.AlgorithmStarted += (object sender, AlgorithmEventArgs e) => receivedEvents++; runModel.AlgorithmFinished += (object sender, AlgorithmEventArgs e) => { receivedEvents++; Assert.AreEqual(_context.Algorithms[e.Index].Algorithm.Evaluate(stablePairsEvaluation), e.StablePairs); Assert.AreEqual(_context.Algorithms[e.Index].Algorithm.Evaluate(groupHappinessEvaluation), e.GroupHappiness); Assert.AreEqual(_context.Algorithms[e.Index].Algorithm.Evaluate(egalitarianHappinessEvaluation), e.EgalitarianHappiness); }; task = Task.Run(async() => { await runModel.RunSingleAlgorithm(0); Assert.AreEqual(2, receivedEvents); }); }
private void NewModel() { _context = new ModelContext(); SetupModel setupModel = new SetupModel(_context); setupModel.Initialize(); ParticipantsModel participantsModel = new ParticipantsModel(_context); participantsModel.Initialize(); PreferencesModel preferencesModel = new PreferencesModel(_context); preferencesModel.Initialize(); AlgorithmModel algorithmModel = new AlgorithmModel(_context); algorithmModel.Initialize(); algorithmModel.CreateGaleShapleyAlgorithm(); algorithmModel.CreateGeneticAlgorithm(); _model = new RunModel(_context); _model.Initialize(); _context.AlgorithmsChanged = false; }
private void NewViewModel() { _context = new ModelContext(); _model = new RunModel(_context); _viewModel = new RunViewModel(_model, _context); SetupModel setupModel = new SetupModel(_context); setupModel.Initialize(); ParticipantsModel participantsModel = new ParticipantsModel(_context); participantsModel.Initialize(); PreferencesModel preferencesModel = new PreferencesModel(_context); preferencesModel.Initialize(); AlgorithmModel algorithmModel = new AlgorithmModel(_context); algorithmModel.Initialize(); algorithmModel.CreateGaleShapleyAlgorithm(); algorithmModel.CreateGeneticAlgorithm(); _viewModel.RefreshPage(); }
public void SaveData() { NewModel(); SetupModel setupModel = new SetupModel(_context); setupModel.Initialize(); ParticipantsModel participantsModel = new ParticipantsModel(_context); participantsModel.Initialize(); PreferencesModel preferencesModel = new PreferencesModel(_context); preferencesModel.Initialize(); AlgorithmModel algorithmModel = new AlgorithmModel(_context); algorithmModel.Initialize(); _model.SaveAsData(""); Assert.IsNotNull(_persistence.MockData); Assert.IsNotNull(_persistence.MockData.Group1Name); Assert.IsNotNull(_persistence.MockData.Group2Name); Assert.IsNotNull(_persistence.MockData.Participants); Assert.IsNotNull(_persistence.MockData.Preferences); Assert.IsNotNull(_persistence.MockData.Algorithms); }