上机实验

源程序代码:

package junit01;

public class triangle {
 public String s(int a,int b,int c){
  if(a + b <= c||b + c <= a||a + c <= b||a*b*c <= 0) return("不是三角形");
  else if(a==b && b==c) return("等边三角形");
  else if((a==b && b!=c)||(b==c && c!=a)||(a==c && c!=b)) return("等腰三角形");
  else return("一般三角形");
 }
}

Test代码:

package junit01;

import static org.junit.Assert.*;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class triangleTest2 {
 private triangle t;
 @Before
 public void setUp() throws Exception {
  t = new triangle();
 }

 @Test
 public void testS() {
  Assert.assertEquals("不能判断是否为三角形","不是三角形",t.s(5,5,11));
  Assert.assertEquals("不能判断是否为等边三角形","等边三角形",t.s(6,6,6));
  Assert.assertEquals("不能判断是否为等腰三角形","等腰三角形",t.s(2,2,3));
  Assert.assertEquals("不能判断是否为一般三角形","一般三角形",t.s(3,4,5));
 }
}

原文地址:https://www.cnblogs.com/aisingiorohanani/p/5295602.html