Beispiel #1
0
        private void Test(CoinExchange exchange, int[] coins, int money)
        {
            int num          = exchange.Exchange1(coins, money);
            int numWithOpt   = exchange.ExchangeWithOpt1(coins, money);
            int numWithRecur = exchange.ExchangeWithRecur(coins, money);

            Console.WriteLine($"coins of ({string.Join(",", coins)}), money of {money}, the num is {num}, {numWithOpt}(Opt) and {numWithRecur}(Recur)");
        }
Beispiel #2
0
        public void Run()
        {
            CoinExchange exchange = new CoinExchange();

            int[] coins;
            coins = new int[] { 1, 3, 4 };
            Test(exchange, coins, 6);

            coins = new int[] { 9, 3, 8, 6, 5 };
            Test(exchange, coins, 10);

            Test(exchange, new int[] { 2 }, 3);

            Test(exchange, new int[] { 3, 2 }, 3);

            for (int i = 0; i < 10; i++)
            {
                Random random = new Random(i);
                coins = GetNums(random, 5);
                int money = 10;
                Test(exchange, coins, money);
            }
        }