示例#1
0
        public void MapWithLockedDoorWithMultipleDependencyOnObjectivesIsSolvable()
        {
            var map         = BuildStandardTestMap();
            var startVertex = 1;

            var mapModel    = new MapModel(map, startVertex);
            var doorManager = mapModel.DoorAndClueManager;

            doorManager.PlaceDoor(new DoorRequirements(new Connection(10, 11), "lock0", 2));
            doorManager.PlaceObjective(new ObjectiveRequirements(4, "obj0", 1, new List <string> {
                "lock0"
            }));
            doorManager.PlaceObjective(new ObjectiveRequirements(5, "obj1", 1, new List <string> {
                "lock0"
            }));
            doorManager.AddCluesToExistingObjective("obj0", new List <int> {
                1
            });
            doorManager.AddCluesToExistingObjective("obj1", new List <int> {
                1
            });

            GraphSolver solver = new GraphSolver(mapModel);

            Assert.IsTrue(solver.MapCanBeSolved());
        }
        public bool DoLockClueStressTest(int numberOfNodes, double branchingRatio, int numberOfDoors, int numberOfCluesPerDoor, bool visualise)
        {
            var graphGenerator = new GraphGenerator(random);

            var randomMap = graphGenerator.GenerateConnectivityMapNoCycles(numberOfNodes, branchingRatio);

            var doorAndClueTester = new DoorAndClueGenerator(random);

            var mapModel = new MapModel(randomMap, 0);

            if (visualise)
            {
                VisualiseConnectivityGraph(mapModel);
            }

            doorAndClueTester.AddDoorsAndClues(mapModel, numberOfDoors, numberOfCluesPerDoor);

            if (visualise)
            {
                VisualiseConnectivityGraphWithDoors(mapModel);
            }

            var mapTester = new GraphSolver(mapModel);

            return(mapTester.MapCanBeSolved());
        }
示例#3
0
        public async Task GetTotalTransactionAsync()
        {
            //Arrange
            IEnumerable <Transactions> transactions = MockTransactions.GetTransactions();
            var mockTransactionsRepository          = new Mock <IRepository <Transactions> >();

            mockTransactionsRepository.Setup(p => p.GetAsync()).Returns(Task.FromResult(transactions));

            IEnumerable <Rates> rates = MockRates.GetRates();
            var mockRatesRepository   = new Mock <IRepository <Rates> >();

            mockRatesRepository.Setup(p => p.GetAsync()).Returns(Task.FromResult(rates));

            GraphSolver   graphSolver   = new GraphSolver();
            AmountService amountService = new AmountService();
            TransactionBusinessService transactionBusinessService = new TransactionBusinessService(graphSolver, amountService, null);
            TransactionFilterService   transactionFilterService   = new TransactionFilterService(null);

            ConfigurationBuilder configBuilder = new ConfigurationBuilder();

            configBuilder.AddInMemoryCollection(new Dictionary <string, string> {
                { "Currency", "EUR" }
            });
            IConfiguration config = configBuilder.Build();

            TransactionsService transactionsService = new TransactionsService(mockTransactionsRepository.Object, mockRatesRepository.Object, transactionFilterService, transactionBusinessService, null, config);

            //Act
            var totalTransactionDTO = await transactionsService.GetTotalTransactionAsync("A0000").ConfigureAwait(false);

            //Assert
            Assert.NotNull(null);
        }
        public void GetWeightsToNodeOnBreadthFirstSearch()
        {
            //Arrange
            IEnumerable <Rates> rates = MockRates.GetRates();
            Graph       ratesGraph    = rates.ToGraph();
            GraphSolver graphSolver   = new GraphSolver();

            //Act
            var ratesDict = graphSolver.GetWeightsToNodeOnBreadthFirstSearch(ratesGraph, "EUR");

            //Assert
            Assert.Empty(ratesDict["EUR"]);

            Assert.Single(ratesDict["USD"]);
            Assert.Equal(expected: (decimal)0.53, actual: ratesDict["USD"].ElementAt(0));

            Assert.Equal(expected: 2, actual: ratesDict["AUD"].Count());
            Assert.Equal(expected: (decimal)0.81, actual: ratesDict["AUD"].ElementAt(0));
            Assert.Equal(expected: (decimal)0.53, actual: ratesDict["AUD"].ElementAt(1));

            Assert.Equal(expected: 3, actual: ratesDict["CAD"].Count());
            Assert.Equal(expected: (decimal)1.41, actual: ratesDict["CAD"].ElementAt(0));
            Assert.Equal(expected: (decimal)0.81, actual: ratesDict["CAD"].ElementAt(1));
            Assert.Equal(expected: (decimal)0.53, actual: ratesDict["CAD"].ElementAt(2));
        }
示例#5
0
 static void Main(string[] args)
 {
     if (!Map.InitMap("subway_map.json"))
     {
         return;
     }
     GraphSolver.BuildGraph();
     if (args.Length == 3 && args[0] == "/b")
     {
         if (!Map.StationId.ContainsKey(args[1]) ||
             !Map.StationId.ContainsKey(args[2]))
         {
             Console.WriteLine("站名有误或数据文件未收录此站!");
             return;
         }
         int id1 = Map.StationId[args[1]], id2 = Map.StationId[args[2]];
         var res = GraphSolver.CalcPath(id1, id2);
         Console.WriteLine(res.ToString());
         return;
     }
     if (args.Length == 2 && args[0] == "/a")
     {
         if (!Map.StationId.ContainsKey(args[1]))
         {
             Console.WriteLine("站名有误或数据文件未收录此站!");
             return;
         }
         int id  = Map.StationId[args[1]];
         var res = GraphSolver.TravelAroundPath(id);
         Console.WriteLine(res.ToPathString(false));
         return;
     }
     if (args.Length == 2 && args[0] == "/z")
     {
         LineQuery.TestAnswer(args[1]);
         return;
     }
     if (args.Length == 1 && args[0] == "/g")
     {
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         Application.Run(new GUIForm());
         return;
     }
     if (args.Length == 0)
     {
         Console.WriteLine("当前以无参数方式启动.");
         LineQuery.LineStations();
         return;
     }
     Console.WriteLine("参数有误, 请仔细检查.");
     Console.WriteLine(" - 路径查询: subway.exe /b 起始站 终到站");;
     Console.WriteLine(" - 线路查询: subway.exe");
     Console.WriteLine(" - 环游路径: subway.exe /a 起始站");
     Console.WriteLine(" - 检测答案: subway.exe /z 答案txt路径");
     Console.WriteLine(" - 启动GUI: subway.exe /g");
 }
示例#6
0
        public void MapWithNoDoorsIsSolvable()
        {
            var map         = BuildStandardTestMap();
            var startVertex = 1;

            var mapModel = new MapModel(map, startVertex);

            GraphSolver solver = new GraphSolver(mapModel);

            Assert.IsTrue(solver.MapCanBeSolved());
        }
示例#7
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (!Map.StationId.ContainsKey(DepatureText.Text) || !Map.StationId.ContainsKey(TerminalText.Text))
            {
                MessageBox.Show("站名有误或未收录该站点!");
                return;
            }
            timer1.Enabled  = false;
            timer1.Interval = 300;
            int id1 = Map.StationId[DepatureText.Text], id2 = Map.StationId[TerminalText.Text];

            path = GraphSolver.CalcPath(id1, id2);
            ShowPath();
        }
示例#8
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!Map.StationId.ContainsKey(textBox1.Text))
            {
                MessageBox.Show("站名有误或未收录该站点!");
                return;
            }
            timer1.Enabled  = false;
            timer1.Interval = 100;
            int id = Map.StationId[textBox1.Text];

            path = GraphSolver.TravelAroundPath(id);
            ShowPath();
        }
示例#9
0
        public void MapWithLockedDoorAndInaccessibleClueIsNotSolvable()
        {
            var map         = BuildStandardTestMap();
            var startVertex = 1;

            var mapModel    = new MapModel(map, startVertex);
            var doorManager = mapModel.DoorAndClueManager;

            doorManager.PlaceDoorAndCluesNoChecks(new DoorRequirements(new Connection(10, 11), "lock0"),
                                                  new List <int>(new int[] { 12 }));

            GraphSolver solver = new GraphSolver(mapModel);

            Assert.IsFalse(solver.MapCanBeSolved());
        }
        public void GetTotalAmount()
        {
            //Arrange
            GraphSolver   graphSolver   = new GraphSolver();
            AmountService amountService = new AmountService();
            TransactionBusinessService transactionBusinessService = new TransactionBusinessService(graphSolver, amountService, null);

            IEnumerable <Transactions> transactions = MockTransactions.GetTransactions();

            //Act
            var totalAmount = transactionBusinessService.GetTotalAmount(transactions);

            //Assert
            Assert.Equal(expected: (decimal)47.00, actual: totalAmount);
        }
示例#11
0
        public void MapWithLockedDoorAndRecursivelyLockedTwoCluesIsSolvable()
        {
            var map         = BuildStandardTestMap();
            var startVertex = 1;

            var mapModel    = new MapModel(map, startVertex);
            var doorManager = mapModel.DoorAndClueManager;

            doorManager.PlaceDoorAndClues(new DoorRequirements(new Connection(10, 11), "lock0"),
                                          new List <int>(new int[] { 6 }));

            doorManager.PlaceDoorAndClues(new DoorRequirements(new Connection(5, 6), "lock1"),
                                          new List <int>(new int[] { 4 }));

            GraphSolver solver = new GraphSolver(mapModel);

            Assert.IsTrue(solver.MapCanBeSolved());
        }
示例#12
0
        public void MapWithLockedDoorWithDependencyOnUnsolveableObjectiveIsNotSolvable()
        {
            var map         = BuildStandardTestMap();
            var startVertex = 1;

            var mapModel    = new MapModel(map, startVertex);
            var doorManager = mapModel.DoorAndClueManager;

            doorManager.PlaceDoor(new DoorRequirements(new Connection(10, 11), "lock0", 1));
            doorManager.PlaceObjective(new ObjectiveRequirements(4, "obj0", 1, new List <string> {
                "lock0"
            }));
            //missing clue for objective

            GraphSolver solver = new GraphSolver(mapModel);

            Assert.IsFalse(solver.MapCanBeSolved());
        }
        public void ExchangeToCurrency()
        {
            //Arrange
            GraphSolver   graphSolver   = new GraphSolver();
            AmountService amountService = new AmountService();
            TransactionBusinessService transactionBusinessService = new TransactionBusinessService(graphSolver, amountService, null);

            IEnumerable <Transactions> transactions = MockTransactions.GetTransactions();
            IEnumerable <Rates>        rates        = MockRates.GetRates();

            //Act
            var transactionsToCurrency = transactionBusinessService.ExchangeToCurrency(transactions, rates, "EUR");

            //Assert
            Assert.Equal(expected: (decimal)8.02, actual: transactionsToCurrency.ElementAt(0).Amount);
            Assert.Equal(expected: (decimal)5.26, actual: transactionsToCurrency.ElementAt(1).Amount);
            Assert.Equal(expected: (decimal)5.96, actual: transactionsToCurrency.ElementAt(2).Amount);
            Assert.Equal(expected: (decimal)10.25, actual: transactionsToCurrency.ElementAt(3).Amount);
        }
示例#14
0
        public void MapWithLockedDoorDependingOnAnObjectiveWithNotEnoughCluesIsNotSolvable()
        {
            var map         = BuildStandardTestMap();
            var startVertex = 1;

            var mapModel    = new MapModel(map, startVertex);
            var doorManager = mapModel.DoorAndClueManager;

            doorManager.PlaceDoor(new DoorRequirements(new Connection(10, 11), "lock0", 2));
            doorManager.PlaceObjective(new ObjectiveRequirements(2, "obj0", 1, new List <string> {
                "lock0"
            }));
            //red herring
            doorManager.PlaceObjective(new ObjectiveRequirements(3, "obj1", 1));
            //One clue before and one after the door (not enough to unlock it)
            var clues = doorManager.AddCluesToExistingObjective("obj0", new List <int> {
                2
            });

            GraphSolver solver = new GraphSolver(mapModel);

            Assert.IsFalse(solver.MapCanBeSolved());
        }