Пример #1
0
 public void TestInitialBatteryPercentage()
 {
     var testBattery = new LaptopBattery();
     var expected = 50;
     var actual = testBattery.Percentage;
     Assert.AreEqual(expected, actual);
 }
Пример #2
0
        public void ChargeWithNegativePowerExpect25()
        {
            LaptopBattery battery = new LaptopBattery();
            battery.Charge(-25);

            Assert.AreEqual(25, battery.CurrentBatteryPower());
        }
Пример #3
0
        public void ChargeWithSuperpositivePowerExpectHundred()
        {
            LaptopBattery battery = new LaptopBattery();
            battery.Charge(200);

            Assert.AreEqual(100, battery.CurrentBatteryPower());
        }
Пример #4
0
        public void ChargeWithPositivePowerExpect75()
        {
            LaptopBattery battery = new LaptopBattery();
            battery.Charge(25);

            Assert.AreEqual(75, battery.CurrentBatteryPower());
        }
Пример #5
0
        public void ChargeWithSupernegativePowerExpectZero()
        {
            LaptopBattery battery = new LaptopBattery();
            battery.Charge(-200);

            Assert.AreEqual(0, battery.CurrentBatteryPower());
        }
Пример #6
0
 public void TestOverchargedBattery()
 {
     var testBattery = new LaptopBattery();
     var expected = 100;
     testBattery.Charge(51);
     var actual = testBattery.Percentage;
     Assert.AreEqual(expected, actual);
 }
Пример #7
0
 public void TestEmptyBattery()
 {
     var testBattery = new LaptopBattery();
     var expected = 0;
     testBattery.Charge(-51);
     var actual = testBattery.Percentage;
     Assert.AreEqual(expected, actual);
 }
Пример #8
0
 public void TestChargeMethodWithPositiveNumber()
 {
     var testBattery = new LaptopBattery();
     var expected = 51;
     testBattery.Charge(1);
     var actual = testBattery.Percentage;
     Assert.AreEqual(expected, actual);
 }
Пример #9
0
 public override Laptop CreateLaptop()
 {
     var ram = new RAM(4);
     var cpu = new Cpu64Bit(2);
     HardDrive[] hardDrive = new[] { new HardDrive(500, false, 0) };
     var laptopBattery = new LaptopBattery();
     var laptop = new Laptop(cpu, ram, hardDrive, laptopBattery);
     return laptop;
 }
        public void OverChargeBatteryTest()
        {
            RAM laptopRAM = new RAM(4);
            var laptopVideoCard = new VideoCard(false);
            var laptopHardDrives = new[] { new HardDrive(500, false, 0) };
            var laptopBattery = new LaptopBattery();
            var laptopCPU = new CPU(2, CPUTypes._64bit, laptopRAM, laptopVideoCard);

            Computer laptop = new Computer(ComputerType.LAPTOP, laptopCPU, laptopRAM, laptopHardDrives, laptopVideoCard, laptopBattery);
            laptop.ChargeBattery(300);
        }
Пример #11
0
        public Computer(ComputerType type, CPU cpu, RAM ram, IEnumerable<HardDrive> hardDrives, VideoCard videoCard, LaptopBattery battery)
        {
            this.CPU = cpu;
            this.RAM = ram;
            this.HardDrives = hardDrives;
            this.VideoCard = videoCard;
            if (type != ComputerType.LAPTOP && type != ComputerType.PC)
            {
                this.VideoCard.IsMonochrome = true;
            }

            this.battery = battery;
        }
Пример #12
0
        public void CheckIfDefaultPowerIs50()
        {
            LaptopBattery battery = new LaptopBattery();

            Assert.AreEqual(50, battery.CurrentBatteryPower());
        }
Пример #13
0
 public LaptopComputer(IMotherboard motherboard, Cpu cpu, Ram ram, IEnumerable<HardDrive> hardDrives, IVideoCard videoCard, LaptopBattery battery)
     : base(ComputerType.LAPTOP, motherboard, cpu, ram, hardDrives, videoCard)
 {
     this.battery = battery;
 }
Пример #14
0
 public Laptop(Cpu cpu, RAM ram, IEnumerable<HardDrive> hardDrives, LaptopBattery battery)
     : base(cpu, ram, hardDrives)
 {
     this.Battery = battery;
     this.VideoCard.IsMonochrome = false;
 }
        public static void Main()
        {
            var manufacturer = Console.ReadLine();
            if (manufacturer == "HP")
            {
                var personalComputerRAM = new RAM(2);
                var personalComputerVideoCard = new VideoCard(false);
                var personalComputerHardDrives = new[] { new HardDrive(500, false, 0) };
                var personalComputerCPU = new CPU(2, CPUTypes._32bit, personalComputerRAM, personalComputerVideoCard);

                personalComputer = new Computer(ComputerType.PC, personalComputerCPU, personalComputerRAM, personalComputerHardDrives, personalComputerVideoCard, null);

                var serverRAM = new RAM(32);
                var serverVideoCard = new VideoCard();
                var serverHardDrives = new List<HardDrive> { new HardDrive(0, true, 2, new List<HardDrive> { new HardDrive(1000, false, 0), new HardDrive(1000, false, 0) }) };
                var serverCPU = new CPU(4, CPUTypes._32bit, serverRAM, serverVideoCard);

                server = new Computer(ComputerType.SERVER, serverCPU, serverRAM, serverHardDrives, serverVideoCard, null);

                var laptopRAM = new RAM(4);
                var laptopVideoCard = new VideoCard(false);
                var laptopHardDrives = new[] { new HardDrive(500, false, 0) };
                var laptopBattery = new LaptopBattery();
                var laptopCPU = new CPU(2, CPUTypes._64bit, laptopRAM, laptopVideoCard);

                laptop = new Computer(ComputerType.LAPTOP, laptopCPU, laptopRAM, laptopHardDrives, laptopVideoCard, laptopBattery);
            }
            else if (manufacturer == "Dell")
            {
                var personalComputerRAM = new RAM(8);
                var personalComputerVideoCard = new VideoCard(false);
                var personalComputerHardDrives = new[] { new HardDrive(1000, false, 0) };
                var personalComputerCPU = new CPU(4, CPUTypes._64bit, personalComputerRAM, personalComputerVideoCard);

                personalComputer = new Computer(ComputerType.PC, personalComputerCPU, personalComputerRAM, personalComputerHardDrives, personalComputerVideoCard, null);

                var serverRAM = new RAM(64);
                var serverVideoCard = new VideoCard();
                var serverHardDrives = new List<HardDrive> { new HardDrive(0, true, 2, new List<HardDrive> { new HardDrive(2000, false, 0), new HardDrive(2000, false, 0) }) };
                var serverCPU = new CPU(8, CPUTypes._64bit, serverRAM, serverVideoCard);

                server = new Computer(ComputerType.SERVER, serverCPU, serverRAM, serverHardDrives, serverVideoCard, null);

                var laptopRAM = new RAM(8);
                var laptopVideoCard = new VideoCard(false);
                var laptopHardDrives = new[] { new HardDrive(1000, false, 0) };
                var laptopBattery = new LaptopBattery();
                var laptopCPU = new CPU(4, CPUTypes._32bit, laptopRAM, laptopVideoCard);

                laptop = new Computer(ComputerType.LAPTOP, laptopCPU, laptopRAM, laptopHardDrives, laptopVideoCard, laptopBattery);
            }
            else if (manufacturer == "Lenovo")
            {
                var personalComputerRAM = new RAM(4);
                var personalComputerVideoCard = new VideoCard(true);
                var personalComputerHardDrives = new[] { new HardDrive(2000, false, 0) };
                var personalComputerCPU = new CPU(2, CPUTypes._64bit, personalComputerRAM, personalComputerVideoCard);

                personalComputer = new Computer(ComputerType.PC, personalComputerCPU, personalComputerRAM, personalComputerHardDrives, personalComputerVideoCard, null);

                var serverRAM = new RAM(8);
                var serverVideoCard = new VideoCard();
                var serverHardDrives = new List<HardDrive> { new HardDrive(0, true, 2, new List<HardDrive> { new HardDrive(500, false, 0), new HardDrive(500, false, 0) }) };
                var serverCPU = new CPU(2, CPUTypes._128bit, serverRAM, serverVideoCard);

                server = new Computer(ComputerType.SERVER, serverCPU, serverRAM, serverHardDrives, serverVideoCard, null);

                var laptopRAM = new RAM(16);
                var laptopVideoCard = new VideoCard(false);
                var laptopHardDrives = new[] { new HardDrive(1000, false, 0) };
                var laptopBattery = new LaptopBattery();
                var laptopCPU = new CPU(2, CPUTypes._64bit, laptopRAM, laptopVideoCard);

                laptop = new Computer(ComputerType.LAPTOP, laptopCPU, laptopRAM, laptopHardDrives, laptopVideoCard, laptopBattery);
            }
            else
            {
                throw new InvalidArgumentException("Invalid manufacturer!");
            }

            var command = Console.ReadLine();

            while (command != null && command != "Exit")
            {
                var commandArguments = command.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (commandArguments.Length != 2)
                {
                    throw new ArgumentException("Invalid command!");
                }

                var commandName = commandArguments[0];
                var commandParameter = int.Parse(commandArguments[1]);
                if (commandName == "Charge")
                {
                    laptop.ChargeBattery(commandParameter);
                }
                else if (commandName == "Process")
                {
                    server.Process(commandParameter);
                }
                else if (commandName == "Play")
                {
                    personalComputer.Play(commandParameter);
                }

                command = Console.ReadLine();
            }
        }