Exemplo n.º 1
0
        public string GetBerlinClock(BerlinClockInputModel input)
        {
            BerlinClockInputModelValidator clockValidator = new BerlinClockInputModelValidator();

            clockValidator.ValidateAndThrow(input);

            // Hours
            var hourDictionary = GetLampState(input.hour);
            int firstRowQuant  = hourDictionary["first"];
            int secondRowQuant = hourDictionary["second"];

            // Minutes
            var minDictionary  = GetLampState(input.minute);
            int thirdRowQuant  = minDictionary["first"];
            int fourthRowQuant = minDictionary["second"];

            // Lamps symbols
            string second    = GetSecLampState(input.second).ToString();
            string firstRow  = RowConverter(firstRowQuant, 4, LampEnum.Red);
            string secondRow = RowConverter(secondRowQuant, 4, LampEnum.Red);
            string thirdRow  = RowConverter(thirdRowQuant, 11, LampEnum.Yellow, LampEnum.Red);
            string fourthRow = RowConverter(fourthRowQuant, 4, LampEnum.Yellow);

            BerlinClockModel berlinClock = new BerlinClockModel
            {
                second    = second,
                firstRow  = firstRow,
                secondRow = secondRow,
                thirdRow  = thirdRow,
                fourthRow = fourthRow
            };

            return(ConcatClockCode(berlinClock));
        }
Exemplo n.º 2
0
        public string MakeView_GetCorrectViewCases(BerlinClockModel model)
        {
            // Act
            string result = this._berlinClockCharViewFormat.MakeView(model);

            // Assert
            return(result);
        }
Exemplo n.º 3
0
        public void Should_CreateAllNeededBulbs()
        {
            var clockModel = new BerlinClockModel();

            Assert.IsNotNull(clockModel.SecondsBulb);
            Assert.AreEqual(4, clockModel.BigHoursBulbs.Count());
            Assert.AreEqual(4, clockModel.HoursBulbs.Count());
            Assert.AreEqual(11, clockModel.BigMinutesBulbs.Count());
            Assert.AreEqual(4, clockModel.MinutesBulbs.Count());
        }
        public string convertTime(string aTime)
        {
            var berlinClock = new BerlinClockModel(aTime);

            if (berlinClock.Init())
            {
                return
                    (_berlinClockPrinterFactory
                     .GetPrinter <string>()
                     .Print(berlinClock));
            }
            return(string.Empty);
        }
Exemplo n.º 5
0
        private string ConcatClockCode(BerlinClockModel berlinClock)
        {
            var second    = berlinClock.second;
            var firstRow  = berlinClock.firstRow;
            var secondRow = berlinClock.secondRow;
            var thirdRow  = berlinClock.thirdRow;
            var fourthRow = berlinClock.fourthRow;

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(second);
            stringBuilder.AppendLine(firstRow);
            stringBuilder.AppendLine(secondRow);
            stringBuilder.AppendLine(thirdRow);
            stringBuilder.Append(fourthRow);

            return(stringBuilder.ToString());
        }
        /// <summary>
        /// Creates view of <see cref="BerlinClockModel"/> as characters. See remarks for examples
        /// </summary>
        /// <param name="model">Berlin clock model</param>
        /// <returns><see cref="BerlinClockModel"/> as characters</returns>
        /// <remarks>
        /// Some examples:
        /// 1. For "23:59:59"
        /// O
        /// RRRR
        /// RRRO
        /// YYRYYRYYRYY
        /// YYYY
        ///
        /// 2. For "00:00:00"
        /// Y
        /// OOOO
        /// OOOO
        /// OOOOOOOOOOO
        /// OOOO
        /// </remarks>
        public string MakeView(BerlinClockModel model)
        {
            char secondsSymbol = model.EvenSeconds
                                ? c_secondSymbol
                                : c_offSymbol;
            string secondsRow = secondsSymbol.ToString();

            string filling5HoursRow = StringHelper.GetFilledStringByCharacters(
                BerlinClockModel.c_limit5HoursChars, model.CountOf5Hours, c_hourSymbol, c_offSymbol);

            string fillingModHoursRow = StringHelper.GetFilledStringByCharacters(
                BerlinClockModel.c_limitModHoursChars, model.CountOfModHours, c_hourSymbol, c_offSymbol);

            string filling5MinutesRow = StringHelper.GetFilledStringByCharactersWithSeparators(
                BerlinClockModel.c_limit5MinutesChars, model.CountOf5Minutes, c_minuteSymbol, c_quaterSeparateNumber, c_quarterSymbol, c_offSymbol);

            string fillingModMinutesRow = StringHelper.GetFilledStringByCharacters(
                BerlinClockModel.c_limitModMinutesChars, model.CountOfModMinutes, c_minuteSymbol, c_offSymbol);

            string resultView = $"{secondsRow}\r\n{filling5HoursRow}\r\n{fillingModHoursRow}\r\n{filling5MinutesRow}\r\n{fillingModMinutesRow}";

            return(resultView);
        }