public async Task Run_Once_When_Consistent()
        {
            var strategyRepository   = new StrategyRepository(connection);
            var strategyService      = new StrategyService(strategyRepository);
            var simulationRepository = new SimulationRepository(connection);
            var gameService          = new GameService(strategyService, gameSettingsProvider);
            var populationService    = new PopulationService(gameService);
            //TODO: simplify /\
            var simulationServce = new SimulationService(simulationRepository, populationService,
                                                         strategyService, new SimulationSettingsProvider());
            Strategy cooperator = await strategyRepository
                                  .GetByNameAsync(NoMemoryStrategies.GetSimpleCooperator().Name);

            var players = new List <Player>();

            for (int i = 0; i < 10; i++)
            {
                players.Add(new Player()
                {
                    StrategyId = cooperator.Id
                });
            }

            Simulation simulation = await simulationServce.Run(players);

            Assert.IsNotNull(simulation.Winner);
            Assert.AreEqual(1, simulation.PopulationsCompleated);
        }
Ejemplo n.º 2
0
        public async Task Get_Strategies_By_Id_Count_Equal_Distinct_Strategies()
        {
            var strategyRepository = new StrategyRepository(connection);
            var strategyService    = new StrategyService(strategyRepository);

            List <Strategy> allStrategies = await strategyService.GetAllStrategies();

            Strategy cheater    = allStrategies.Where(s => s.Name == "Simple Cheater").FirstOrDefault();
            Strategy cooperator = allStrategies.Where(s => s.Name == "Simple Cooperator").FirstOrDefault();

            List <Player> players = new List <Player>();

            for (int i = 0; i < 5; i++)
            {
                players.Add(new Player()
                {
                    StrategyId = cheater.Id
                });
                players.Add(new Player()
                {
                    StrategyId = cooperator.Id
                });
            }

            var strategies = strategyService.GetStrategiesById(players.Select(p => p.StrategyId).ToList());

            Assert.AreEqual(2, strategies.Count);
        }
        public async Task Winner_Score_Is_Total_Score()
        {
            var strategyRepository   = new StrategyRepository(connection);
            var strategyService      = new StrategyService(strategyRepository);
            var simulationRepository = new SimulationRepository(connection);
            var gameService          = new GameService(strategyService, gameSettingsProvider);
            var populationService    = new PopulationService(gameService);
            //TODO: simplify /\
            var simulationServce = new SimulationService(simulationRepository, populationService,
                                                         strategyService, new SimulationSettingsProvider());
            Strategy cooperator = await strategyRepository
                                  .GetByNameAsync(NoMemoryStrategies.GetSimpleCooperator().Name);

            var players = new List <Player>();

            for (int i = 0; i < 10; i++)
            {
                players.Add(new Player()
                {
                    StrategyId = cooperator.Id
                });
            }

            Simulation simulation = await simulationServce.Run(players);

            GameSettings gameSettings = gameSettingsProvider.GetGameSettings();
            int          totalScore   = gameSettings.TotalRounds
                                        * (gameSettings.CooperateModifier + gameSettings.MoveModifier)
                                        * (players.Count - 1);

            Assert.AreEqual(totalScore, simulation.Winner.Score);
        }
        public async Task PopulateDb()
        {
            //TODO: remove when GUI created
            var strategyRepository = new StrategyRepository(connection);

            var strategies = new List <Strategy>()
            {
                NoMemoryStrategies.GetSimpleCheater(),
                NoMemoryStrategies.GetSimpleCooperator(),
                OneRoundStrategies.GetCopycat(),
                OneRoundStrategies.GetCheaterCopycat(),
                OneRoundStrategies.GetReverser(),
                OneRoundStrategies.GetCheaterReverser()
            };

            var newStrategies = new List <string>();

            foreach (Strategy strategy in strategies)
            {
                Strategy tmp = await strategyRepository.GetByNameAsync(strategy.Name);

                if (tmp == null)
                {
                    string newId = await strategyRepository.AddAsync(strategy);

                    newStrategies.Add(newId);
                }
            }

            List <Strategy> addedStrategies = await strategyRepository.GetAsync(newStrategies);

            Assert.AreEqual(newStrategies.Count, addedStrategies.Count);
        }
        public async Task Get_Cooperator_Players_Strategies()
        {
            var strategyRepository   = new StrategyRepository(connection);
            var strategyService      = new StrategyService(strategyRepository);
            var simulationRepository = new SimulationRepository(connection);
            var gameService          = new GameService(strategyService, gameSettingsProvider);
            var populationService    = new PopulationService(gameService);
            //TODO: simplify /\
            var simulationServce = new SimulationService(simulationRepository, populationService,
                                                         strategyService, new SimulationSettingsProvider());
            Strategy cooperator = await strategyRepository
                                  .GetByNameAsync(NoMemoryStrategies.GetSimpleCooperator().Name);

            var players = new List <Player>();

            for (int i = 0; i < 10; i++)
            {
                players.Add(new Player()
                {
                    StrategyId = cooperator.Id
                });
            }
            players = simulationServce.GetPlayersStrategies(players);

            bool badPlayers = players.Where(p => p.StrategyId != cooperator.Id).Any();

            Assert.IsFalse(badPlayers);
        }
        public async Task Get_Null_When_No_Strategy()
        {
            var      strategyRepository = new StrategyRepository(connection);
            Strategy strategy           = await strategyRepository.GetAsync((string)null);

            Assert.IsNull(strategy);
        }
Ejemplo n.º 7
0
        public void Setup()
        {
            this.mockStrategyTradingService = new Mock <IStrategyTradingService>();
            this.mockLocalCache             = new Mock <ILocalCache>();

            this.subject = new StrategyRepository(this.mockStrategyTradingService.Object,
                                                  this.mockLocalCache.Object);
        }
Ejemplo n.º 8
0
        public async Task Get_Strategies_By_Id_Count_Equal_All_Strategies()
        {
            var strategyRepository = new StrategyRepository(connection);
            var strategyService    = new StrategyService(strategyRepository);
            var strategiesIds      = strategyService.GetAllStrategies().Result.Select(s => s.Id).ToList();
            var strategies         = strategyService.GetStrategiesById(strategiesIds);

            Assert.AreEqual(strategiesIds.Count, strategies.Count);
        }
Ejemplo n.º 9
0
 public UnitOfWork(ArchimedesContext context)
 {
     _context   = context;
     Price      = new PriceRepository(_context);
     Candle     = new CandleRepository(_context);
     Trade      = new TradeRepository(_context);
     Market     = new MarketRepository(_context);
     PriceLevel = new PriceLevelRepository(_context);
     Strategy   = new StrategyRepository(_context);
 }
Ejemplo n.º 10
0
 public static FavoriteStrategyModel ToModel(this FavoriteStrategyEntity FE)
 {
     if (FE != null)
     {
         StrategyRepository    repoEnre = new StrategyRepository();
         UserRepository        repoUtil = new UserRepository();
         FavoriteStrategyModel FM       = new FavoriteStrategyModel();
         FM.Strategy = repoEnre.GetOne(FE.StrategyId).ToModel();
         FM.User     = repoUtil.GetOne(FE.UserId).MapTo <UserModel>();
         FM.Id       = FE.Id;
         FM.Active   = FE.Active;
         return(FM);
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 11
0
 public static VoteModel ToModel(this VoteEntity VE)
 {
     if (VE != null)
     {
         StrategyRepository repoStr  = new StrategyRepository();
         UserRepository     repoUtil = new UserRepository();
         VoteModel          VM       = new VoteModel();
         VM.Strategy = repoStr.GetOne(VE.StrategyId).ToModel();
         VM.Id       = VE.Id;
         VM.User     = repoUtil.GetOne(VE.UserId).MapTo <UserModel>();
         VM.Vote     = VE.Vote;
         VM.Active   = VE.Active;
         return(VM);
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 12
0
        public ClientContext()
        {
            DefaultAccount      = new Account();
            PortfolioManager    = new PortfolioManager();
            GeneticEnvironment  = new GeneticEnvironment();
            MarketWatch         = new MarketWatch();
            MarketMeter         = new MarketMeter();
            PerformanceLogic    = new PerformanceLogic();
            PositionLogic       = new PositionLogic();
            StrategyRepository  = new StrategyRepository();
            IndicatorRepository = new IndicatorRepository();
            PersistenceLogic    = new PersistenceLogic();

            PersistenceLogic.Register(this);

            //we need marketWatch.Instruments in strategyRep before connecting to server when loading report
            StrategyRepository.Register(MarketWatch, null);

            //we need this when loading performance
            PerformanceLogic.Register(this);
        }
        public async Task Get_Added_Strategy_Name()
        {
            var      strategyRepository = new StrategyRepository(connection);
            Strategy strategy           = new Strategy()
            {
                Name  = "CooperateTest",
                Moves = new List <Move>()
                {
                    new Move()
                    {
                        MoveType = Core.Enums.MoveType.Cooperate
                    }
                }
            };

            string id = await strategyRepository.AddAsync(strategy);

            Strategy strategyFromDb = await strategyRepository.GetAsync(id);

            Assert.AreEqual(strategy.Name, strategyFromDb.Name);
        }