Exemple #1
0
        public override AccessResult SetBrightness(int brightness)
        {
            if (brightness is < 0 or > 100)
            {
                throw new ArgumentOutOfRangeException(nameof(brightness), brightness, "The brightness must be within 0 to 100.");
            }

            if (_isInternal)
            {
                if (PowerManagement.SetActiveSchemeBrightness(brightness))
                {
                    this.Brightness = brightness;
                    return(AccessResult.Succeeded);
                }
            }
            else
            {
                brightness = ArraySearch.GetNearest(_brightnessLevels, (byte)brightness);

                if (MSMonitor.SetBrightness(DeviceInstanceId, brightness))
                {
                    this.Brightness = brightness;
                    return(AccessResult.Succeeded);
                }
            }
            return(AccessResult.Failed);
        }
        public override bool SetBrightness(int brightness)
        {
            if (brightness is < 0 or > 100)
            {
                throw new ArgumentOutOfRangeException(nameof(brightness), brightness, "The brightness must be within 0 to 100.");
            }

            if (_isRemovable)
            {
                brightness = ArraySearch.GetNearest(_brightnessLevels, (byte)brightness);

                if (MSMonitor.SetBrightness(DeviceInstanceId, brightness))
                {
                    this.Brightness = brightness;
                    return(true);
                }
            }
            else
            {
                if (PowerManagement.SetActiveSchemeBrightness(brightness))
                {
                    this.Brightness = brightness;
                    return(true);
                }
            }
            return(false);
        }
        //[Fact]
        public void TestArraySearch()
        {
            ArraySearch s = new ArraySearch(new int[] { 3, 6, 14, 4, 12, 9, 10, 1, 5 });

            Assert.Equal(0, s.IndexOf(3));
            Assert.Equal(8, s.IndexOf(5));
            Assert.Equal(4, s.IndexOf(12));
            Assert.Equal(-1, s.IndexOf(7));
        }
Exemple #4
0
        public void LinearSearchTest()
        {
            // Arrange
            var data            = ArrayHelpers.CreateUnsortedArray();
            var searchAlgorithm = new ArraySearch();

            // Act
            var result = searchAlgorithm.LinearSearch(data, 9);

            // Assert
            result.Should().BeTrue();
        }
Exemple #5
0
        public void BinarySearchTest()
        {
            // Arrange
            var data            = ArrayHelpers.CreateUnsortedArray();
            var sortAlgorithm   = new QuickSort <int>();
            var searchAlgorithm = new ArraySearch();

            data = sortAlgorithm.Sort(data);

            // Act
            var result = searchAlgorithm.BinarySearch(data, 9);

            // Assert
            result.Should().BeTrue();
        }
Exemple #6
0
        public void TestArraySearchLongComplexity()
        {
            byte[] bytes = new byte[] {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            };

            Console.WriteLine($"Total bytes: {bytes.Length}");

            var delimiter = Encoding.ASCII.GetBytes("942gh2hg249");

            Array.Copy(delimiter, 0, bytes, 640, delimiter.Length);

            int index = 0;

            this.Measure(() => {
                index = ArraySearch.IndexOf(delimiter, delimiter.Length, bytes, bytes.Length);
            }, "ArraySearchLong");

            Console.WriteLine($"Location index: {index}");

            Assert.AreEqual(640, index);
        }
Exemple #7
0
        public static bool userMainMenu()
        {
            Console.Title = "Fun with C#!";
            Console.Clear();
            Console.WriteLine("Welcome to my fun with console window app!");
            Console.WriteLine("1)  Check the DNS address of any website!");
            Console.WriteLine("2)  Lets play some music!");
            Console.WriteLine("3)  Have your computer speak for you!");
            Console.WriteLine("4)  Find your exact age and your lucky numbers!");
            Console.WriteLine("5)  Guess what number I am thinking of!");
            Console.WriteLine("6)  Play Roulette for fun!");
            Console.WriteLine("7)  Play Craps for fun!");
            Console.WriteLine("8)  Two sum! The array game of fun!");
            Console.WriteLine("9)  Need some dice? Here you go!");
            Console.WriteLine("10) Different types of sorts, find out their sort times!");
            Console.WriteLine("11) Lets play FizzBuzz!");
            Console.WriteLine("12) Sieve of Eratosthenes as a list.");
            Console.WriteLine("13) Nothing here! 13 is Unlucky!!");
            Console.WriteLine("14) Sieve of Eratosthenes as a hash!");
            Console.WriteLine("15) Calculator! That is cool!");
            Console.WriteLine("16) How does the swap method rearrange values?");
            Console.WriteLine("17) ++Variable, or Variable++, what is the difference?");
            Console.WriteLine("18) Lets talk about collections!");
            Console.WriteLine("19) Lets talk about synchronous vs asynchronous!");
            Console.WriteLine("20) MD5 Hash password crack!");
            Console.WriteLine("21) How does temp swap work?");
            Console.WriteLine("Or hit any other key for end program prompt.");
            Console.Write("Choose here: ");
            string result = Console.ReadLine();

            if (result == "1")
            {
                Address.check();
                return(true);
            }
            else if (result == "2")
            {
                Music.playMusic();
                return(true);
            }
            else if (result == "3")
            {
                Speak.talking();
                return(true);
            }
            else if (result == "4")
            {
                Age.agePlay();
                return(true);
            }
            else if (result == "5")
            {
                Guessing.guessingPlay();
                return(true);
            }
            else if (result == "6")
            {
                Roulette.roulettePlay();
                return(true);
            }
            else if (result == "7")
            {
                Crapps.crappsPlay();
                return(true);
            }
            else if (result == "8")
            {
                TwoSum.doesitadd();
                return(true);
            }
            else if (result == "9")
            {
                Dice.rollem();
                return(true);
            }
            else if (result == "10")
            {
                ArraySearch.searchtime();
                return(true);
            }
            else if (result == "11")
            {
                Fizz.buzz();
                return(true);
            }
            else if (result == "12")
            {
                SieveOfEratosthenesList.PrimesList();
                return(true);
            }
            else if (result == "14")
            {
                Sieve_of_EratosthenesHash.primehash();
                return(true);
            }
            else if (result == "15")
            {
                calculator.numbers();
                return(true);
            }
            else if (result == "16")
            {
                int a = 20;
                int b = 30;
                Swap.SwapNum(ref a, ref b);
                Console.ReadLine();
                return(true);
            }
            else if (result == "17")
            {
                AssignmentThenOperation.Execute();
                return(true);
            }
            else if (result == "18")
            {
                Collections.Execute();
                return(true);
            }
            else if (result == "19")
            {
                SyncVsASync.Execute();
                return(true);
            }
            else if (result == "20")
            {
                MD5HashCrack.Execute();
                return(true);
            }
            else if (result == "21")
            {
                TempSwap.Execute();
                return(true);
            }
            else
            {
                Null.Object();
                return(false);
            }
        }