Exercism v3 launches on Sept 1st 2021. Learn more! ๐Ÿš€๐Ÿš€๐Ÿš€
Avatar of ssinha

ssinha's solution

to Leap in the CFML Track

Published at Apr 24 2019 · 0 comments
Test suite

Given a year, report if it is a leap year.

The tricky thing here is that a leap year in the Gregorian calendar occurs:

on every year that is evenly divisible by 4
  except every year that is evenly divisible by 100
    unless the year is also evenly divisible by 400

For example, 1997 is not a leap year, but 1996 is. 1900 is not a leap year, but 2000 is.

If your language provides a method in the standard library that does this look-up, pretend it doesn't exist and implement it yourself.


Though our exercise adopts some very simple rules, there is more to learn!

For a delightful, four minute explanation of the whole leap year phenomenon, go watch this youtube video.

To run the code in this exercise, you will only need to have CommandBox CLI installed. This binary runs CFML code from the command line.

To run the tests, cd into the exercise folder and run the following:

box task run TestRunner
# Or start up a test watcher that will rerun when files change
box task run TestRunner --:watcher

The tests leverage a library called TestBox which supports xUnit and BDD style of testing. All test suites will be written in the BDD style which uses closures to define test specs. You won't need to worry about installing TestBox. The CLI test runner will take care of that for you. You just need to be connected to the internet the first time you run it. You can read more about it here:



JavaRanch Cattle Drive, exercise 3 http://www.javaranch.com/leap.jsp

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


component extends="testbox.system.BaseSpec" {

	function beforeAll(){
	  SUT = createObject( 'Leap' );

	function run(){
		describe( "My Leap class", function(){			

			it( 'year not divisible by 4: common year', function(){
				expect( SUT.leapYear( year='2015' ) ).toBeFalse();

			it( 'year divisible by 4, not divisible by 100: leap year', function(){
				expect( SUT.leapYear( year='1996' ) ).toBeTrue();

			it( 'year divisible by 100, not divisible by 400: common year', function(){
				expect( SUT.leapYear( year='2100' ) ).toBeFalse();

			it( 'year divisible by 400: leap year', function(){
				expect( SUT.leapYear( year='2000' ) ).toBeTrue();



component extends="LeapTest" {

	function beforeAll(){
	  SUT = createObject( 'Solution' );

* Your implmentation of the Leap exercise
component {
	* @year The input year to consider
	* @returns A boolean for whether the inputted year is true or false
	 function leapYear( year ) {
		// Implement me here
		var flag = false;
			if(year % 4 eq 0 and (year % 100 neq 0 or year % 400 EQ 0)){
				flag = true; 
			flag = false;
		return flag;

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other peopleโ€™s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?