Beispiel #1
0
        /// <summary>
        /// Unit tests the methods in this class.
        /// </summary>
        /// <param name="args">the command-line arguments</param>
        private static void Test(string[] args)
        {
            int n = int.Parse(args[0]);

            if (args.Length == 2)
            {
                Seed = long.Parse(args[1]);
            }
            double[] probabilities = { 0.5, 0.3, 0.1, 0.1 };
            int[]    frequencies   = { 5, 3, 1, 1 };
            string[] a             = "A B C D E F G".Split(' ');

            StdOut.Println($"seed = {Seed}");
            for (int i = 0; i < n; i++)
            {
                StdOut.Printf("{0, 2}", Uniform(100));
                StdOut.Printf("{0,10:f5}", Uniform(10.0, 99.0));
                StdOut.Printf("{0, 7}", Bernoulli(0.5));
                StdOut.Printf("{0, 9:f5}", Gaussian(9.0, 0.2));
                StdOut.Printf("{0, 3}", Discrete(probabilities));
                StdOut.Printf("{0, 3}", Discrete(frequencies));
                StdOut.Printf("{0, 13}", Uniform(100000000000L));
                StdOut.Print("  ");
                Shuffle(a);
                foreach (string s in a)
                {
                    StdOut.Print(s);
                }
                StdOut.Println();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Interactive test of basic functionality.
        /// </summary>
        /// <param name="args">the command-line arguments</param>
        private static void Test(string[] args)
        {
            StdOut.Print("Type a string: ");
            string s = ReadString();

            StdOut.Println("Your string was: " + s);
            StdOut.Println();

            StdOut.Print("Type an int: ");
            int a = ReadInt();

            StdOut.Println("Your int was: " + a);
            StdOut.Println();

            StdOut.Print("Type a boolean: ");
            bool b = ReadBool();

            StdOut.Println("Your boolean was: " + b);
            StdOut.Println();

            StdOut.Print("Type a double: ");
            double c = ReadDouble();

            StdOut.Println("Your double was: " + c);
            StdOut.Println();
        }