예제 #1
0
        public void CalculateLeapYearTest()
        {
            var request = new LeapYearRequest();

            request.StartYear = 1991;
            request.EndYear   = 1998;

            LeapYearCalculator response = new LeapYearCalculator();
            var output = response.FindLeapYear(request);
            var actual = output.LeapYearlist;

            int[] expected = { 1992, 1996 };

            Assert.AreEqual(actual, expected);
        }
예제 #2
0
        public ActionResult LeapYearInput(LeapYearCalculatorModel request)
        {
            if (ModelState.IsValid)
            {
                var leapCalc = new LeapYearCalculator();
                var leapData = new LeapYearRequest();
                leapData.StartYear = request.StartYear.Value;
                leapData.EndYear   = request.EndYear.Value;

                var result = leapCalc.FindLeapYear(leapData);
                return(View("LeapYearOutput", result));
            }
            else
            {
                return(View(request));
            }
        }
        public LeapYearResponse FindLeapYear(LeapYearRequest request)
        {
            LeapYearResponse response = new LeapYearResponse();

            response.StartYear = request.StartYear;//set user formatted input to now equal our stored output value ("response")
            response.EndYear   = request.EndYear;


            for (int i = response.StartYear; i < response.EndYear; i++)
            {
                if ((i % 4 == 0 && i % 100 != 0) || (i % 4 == 0 && i % 100 == 0 && i % 400 == 0))
                {
                    response.LeapYearlist.Add(i);
                }
            }

            return(response);
        }