登录慕测平台从慕测开发者测试练习的Triangle和NextDay程序中分别生成满足100%语句覆盖、函数覆盖

登录慕测平台从慕测开发者测试练习的Triangle和NextDay程序中分别生成满足100%语句覆盖、函数覆盖,第1张

生成JUnit测试用例集
1.对Triangle进行JUnit测试并设计测试用例使其满足100%函数覆盖
2.对Triangle进行JUnit测试并设计测试用例使其满足100%语句覆盖
3.对Triangle进行JUnit测试并设计测试用例使其满足100%判定覆盖
4.对NextDay进行JUnit测试并设计测试用例使其满足100%函数覆盖
5.对NextDay进行JUnit测试并设计测试用例使其满足100%语句覆盖
6.对NextDay进行JUnit测试并设计测试用例使其满足100%判定覆盖


#Triangle
package net.mooctest;
 import static org.junit.Assert.*;
 import org.junit.Test;
 public class TriangleTest {
  
  Triangle T1 = new Triangle(1, 4, 3);
  Triangle T2 = new Triangle(3, 4, 5);
  Triangle T3 = new Triangle(3, 3, 3);
  Triangle T4 = new Triangle(0, 3, 3);
  Triangle T5 = new Triangle(3, 3, 4);
  
  @Test
  public void testIsTriangle() {
   assertEquals(false, T1.isTriangle(T1));
  }
 @Test
  public void testIsTriangle2() {
   assertEquals(true, T2.isTriangle(T2));
    }
  @Test
  public void testgetType() {
   assertEquals("Scalene", T2.getType(T2));
  }
  @Test
  public void testgetType1() {
   assertEquals("Regular", T3.getType-(T3));
  }
  @Test
  public void testgetType2() {
   assertEquals("Illegal", T4.getType(T4));
  }
  @Test
  public void testgetType3() {
   assertEquals("Isosceles", T5.getTyp-e(T5));
     }
  @Test
  public void testgetBorders() {
   assertEquals(3, T2.getBorders().len-gth);
  }
 }
 #nextday
  package net.mooctest;
 import static org.junit.Assert.*;
 import org.junit.Test;
 public class NextdayTest {
  @Test
  public void testValid() {
   //normal day++
   Date currentday=new Date(12,30,1987);
   Date nextday=Nextday.nextDay(c-urrentday);
   Date expectday=new Date(12,31,1987);
   assertEquals(expectday,nextday);
   //normal day->next month
   currentday=new Date(11,30,1987);  nextday=Nextday.nextDay(current-day);
   expectday=new Date(12,1,1987);
   assertEquals(expectday,nextday);
   //normal month->next year
   currentday=new Date(12,31,1987);
   nextday=Nextday.nextDay(current-day);
   expectday=new Date(1,1,1988);
   assertEquals(expectday,nextday);
   //normal leap year 2016, Feb 28
   currentday=new Date(2,28,2016);
   nextday=Nextday.nextDay(current-day);
   expectday=new Date(2,29,2016);
   assertEquals(expectday,nextday);
   //special leap year 2000, Feb 28
   currentday=new Date(2,28,2000);
   nextday=Nextday.nextDay(current-day);
   expectday=new Date(2,29,2000);
   assertEquals(expectday,nextday);
   currentday=new Date(2,27,2000);
   nextday=Nextday.nextDay(current-day);
   expectday=new Date(2,28,2000);
   assertEquals(expectday,nextday);
   //special leap year -2017, Feb 28
   currentday=new Date(2,28,-2017);
   nextday=Nextday.nextDay(current-day);
   expectday=new Date(2,29,-2017);
   assertEquals(expectday,nextday);
   //special leap year -2001, Feb 28
    currentday=new Date(2,28,-2001);
   nextday=Nextday.nextDay(current-day);
   expectday=new Date(2,29,-2001);
   assertEquals(expectday,nextday);
   //special leap year -2018, Feb 28
   currentday=new Date(2,28,-2018);
   nextday=Nextday.nextDay(current-day);
   expectday=new Date(3,1,-2018);
   assertEquals(expectday,nextday);
   //special leap year -1, Dec 31
   currentday=new Date(12,31,-1);
   nextday=Nextday.nextDay(current-day);
   expectday=new Date(1,1,1);
   assertEquals(expectday,nextday); //method coverage
   currentday.printDate();
   currentday.toString();
   
   //function equals() coverage for Date, Day, Month, and Year
   assertEquals(31,currentday.getDay().getDay());
   assertEquals(12,currentday.getMont-h().getMonth());
   assertEquals(-1,currentday.getYear().getYear());
   Year y1=new Year(1111);
   Month m1=new Month(11,y1);
   Day d1=new Day(20,m1);
   assertEquals(false,currentday.getDa-y().equals(d1));
   assertEquals(false,currentday.getM-onth().equals(m1));
   assertEquals(false,currentday.getYe-ar().equals(y1));
   
   assertEquals(false,currentday.getYe-ar().equals(m1));
   assertEquals(false,currentday.getM-onth().equals(y1));
   assertEquals(false,currentday.getDa-y().equals(m1));
   assertEquals(false,currentday.equals-(y1));
   y1=new Year(-1);
   m1=new Month(12,y1);
   d1=new Day(31,m1);
   assertEquals(true,currentday.getDa-y().equals(d1));
   assertEquals(true,currentday.getMo-nth().equals(m1));
   assertEquals(true,currentday.getYea-r().equals(y1));  currentday=new Date(1,1,1987);
   nextday=new Date(1,1,1987);
   assertEquals(true,currentday.equals(nextday));
   nextday=new Date(1,2,1987);
   assertEquals(false,currentday.equals-(nextday));
  }
  @Test(expected=IllegalArgumentExcepti-on.class)
      public void testInvalidDay() {
      //day>31 exception
   Year y=new Year(1987);
   Month m=new Month(11,y);
   Day d=new Day(32,m);
  }
  @Test(expected=IllegalArgumentExcepti-on.class)
      public void testInvalidDay1() {
   Day d=new Day(2,null); }
  @Test(expected=IllegalArgumentExcepti-on.class)
      public void testInvalidMonth1() {
   //Month>12 exception
   Year y=new Year(1987);
   Month m=new Month(13,y);  
  }
  @Test(expected=IllegalArgumentExcepti-on.class)
      public void testInvalidMonth2() {
   //Month>13 exception
   Year y=null;
   Month m=new Month(1,y);  
  }
  @Test(expected=IllegalArgumentExcepti-on.class)
      public void testInvalidYear() {
      //year=0 
      exception  Year y=new Year(0);   }}
 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/915658.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-16
下一篇 2022-05-16

发表评论

登录后才能评论

评论列表(0条)

保存