maven Junit test to determine whether it is a leap year

(100)
prepared DateUtil a class, a method which has isLeapYear (int year), and determines whether the input is a leap year. If it is a leap year, it returns true, else return false. Leap year need to meet the following three conditions:
the year must be greater than 0 and less than or equal to 10000.
100 years not divisible, and divisible by 4.
The year is divisible by 100, and can be divisible by 400.
Please write JUnit test class DateUtilTest, the following use cases, to test the correctness of the program using assertEquals. -100 1000, 20000, 2020, 2019, 2000, 1900.

DateUtil class

package it.qijian.cn;

public class DateUtil{
	
	public  boolean isLeapYear(int year) {
		
	if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0){ //平闰年判断算法
		return true;
	 }
	 else{
		return false;
	 }
	}
	
}

Test categories:

package it.qijian.cn;

import static org.junit.Assert.assertEquals; 

import org.junit.Test;

public class DateUtilTest {
	@Test
	public void test() {
		assertEquals(false, new DateUtil().isLeapYear(1900));	
		assertEquals(false, new DateUtil().isLeapYear(-100)); 
		assertEquals(false, new DateUtil().isLeapYear(1000)); 
		assertEquals(true, new DateUtil().isLeapYear(20000)); 
		assertEquals(true, new DateUtil().isLeapYear(2020)); 
		assertEquals(false, new DateUtil().isLeapYear(2019)); 
		assertEquals(true, new DateUtil().isLeapYear(2000)); 
	}
}

pom.xml file:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>test</groupId>
  <artifactId>test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  <dependencies>
	<!-- https://mvnrepository.com/artifact/junit/junit -->
		<dependency>
		    <groupId>junit</groupId>
		    <artifactId>junit</artifactId>
		    <version>4.12</version>
		    <scope>test</scope>
		</dependency>
		
  </dependencies>
</project>

operation result:
Here Insert Picture Description

Published 32 original articles · won praise 24 · views 5896

Guess you like

Origin blog.csdn.net/qq_43663493/article/details/104723591